当我尝试使用 track.attach 附加远程参与者轨道并使用 track.detach() 删除轨道时,我遇到了这个问题,但它给出了错误,例如 e.attach is 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);
}
}
}