0

当我尝试使用 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);
        }
    }
}
4

1 回答 1

0

this指的是全局上下文(假设所有代码都是上面编码的),由于箭头函数的性质,它们继承了最接近的上下文。

使用funtion(){}this并将参考该出版物

于 2020-11-13T19:29:51.550 回答