Twilio-video track.attach() / track.detach() 在 React js Web 应用程序中不起作用
Twilio-video track.attach() / track.detach() is not function in react js web application
当我尝试使用 track.attach 附加远程参与者轨道并使用 track.detach() 删除轨道时,我遇到了这个问题,但它给出了类似 e.attach 的错误not function 如何解决这个错误。在 attachtrack 功能中,我在尝试附加轨道时遇到了这个问题。我的 twilio-video 版本是 2.4.0
提前致谢。
room.on('participantConnected', participant => {
console.log(`Participant connected: ${participant.identity}`);
// this.setTimer();
room.participants.forEach(participant => {
console.log(`Participant "${participant.identity}" is connected to the Room`);
this.participantConnected(participant, room, true);
console.log("publish--->>>", participant);
});
});
participantConnected =(participant, room, flag) =>{
participant.tracks.forEach(publication => {
this.trackPublished(publication, participant, flag);
});
// Handle theTrackPublications that will be published by the Participant later.
participant.on('trackPublished', publication => {
this.trackPublished(publication, participant, flag);
});
}
trackPublished=(publication, participant, flag)=> {
// If the TrackPublication is already subscribed to, then attach the Track to the DOM.
if (publication.track) {
this.attachTrack(publication.track, participant, flag);
}
// Once the TrackPublication is subscribed to, attach the Track to the DOM.
publication.on('subscribed', track => {
this.attachTrack(track, participant, flag);
});
// Once the TrackPublication is unsubscribed from, detach the Track from the DOM.
publication.on('unsubscribed', track => {
this.detachTrack(track, participant, flag);
});
}
attachTrack=(track, participant, flag)=>{
var mediaContainer = document.getElementById('local-media');
if (flag == true) {
if (track.kind === 'video') {
const participantdiv = document.createElement('div');
participantdiv.id = participant.sid;
remoteparticipantsid = participant.sid
console.log("add remote--->>>", participant.sid);
participantdiv.appendChild(track.attach())
mediaContainer.appendChild(participantdiv);
}
}
}
this
指的是全局上下文(假设所有代码都是上面编码的),由于箭头函数的性质,它们继承最接近的上下文。
使用funtion(){}
,this
将引用出版物
当我尝试使用 track.attach 附加远程参与者轨道并使用 track.detach() 删除轨道时,我遇到了这个问题,但它给出了类似 e.attach 的错误not function 如何解决这个错误。在 attachtrack 功能中,我在尝试附加轨道时遇到了这个问题。我的 twilio-video 版本是 2.4.0 提前致谢。
room.on('participantConnected', participant => {
console.log(`Participant connected: ${participant.identity}`);
// this.setTimer();
room.participants.forEach(participant => {
console.log(`Participant "${participant.identity}" is connected to the Room`);
this.participantConnected(participant, room, true);
console.log("publish--->>>", participant);
});
});
participantConnected =(participant, room, flag) =>{
participant.tracks.forEach(publication => {
this.trackPublished(publication, participant, flag);
});
// Handle theTrackPublications that will be published by the Participant later.
participant.on('trackPublished', publication => {
this.trackPublished(publication, participant, flag);
});
}
trackPublished=(publication, participant, flag)=> {
// If the TrackPublication is already subscribed to, then attach the Track to the DOM.
if (publication.track) {
this.attachTrack(publication.track, participant, flag);
}
// Once the TrackPublication is subscribed to, attach the Track to the DOM.
publication.on('subscribed', track => {
this.attachTrack(track, participant, flag);
});
// Once the TrackPublication is unsubscribed from, detach the Track from the DOM.
publication.on('unsubscribed', track => {
this.detachTrack(track, participant, flag);
});
}
attachTrack=(track, participant, flag)=>{
var mediaContainer = document.getElementById('local-media');
if (flag == true) {
if (track.kind === 'video') {
const participantdiv = document.createElement('div');
participantdiv.id = participant.sid;
remoteparticipantsid = participant.sid
console.log("add remote--->>>", participant.sid);
participantdiv.appendChild(track.attach())
mediaContainer.appendChild(participantdiv);
}
}
}
this
指的是全局上下文(假设所有代码都是上面编码的),由于箭头函数的性质,它们继承最接近的上下文。
使用funtion(){}
,this
将引用出版物