我正在使用twilio的JavaScript SDK制作具有Django后端的视频聊天应用
当我使用Video.connect()连接到会议室时,新参与者的视频将添加到现有参与者屏幕中,但是新参与者看不到现有参与者 如何向新参与者展示旧参与者视频?
这是我的剧本
console.log('conectes')
const Video = Twilio.Video;
Video.connect(context.person_token, {
name: context.room_name,
audio: false,
video: { width: 640 }
}).then(room => {
alert(`Successfully joined a Room: ${room}`);
room.participants.forEach(participant=>{
participant.tracks.forEach(publication => {
if (publication.isSubscribed) {
const track = publication.track;
document.getElementById('remote-media-div').appendChild(track.attach());
}
});
});
room.on('participantConnected', participant => {
alert(`A remote Participant connected: ${participant}`);
alert('scripty')
alert(`Participant "${participant.identity}" connected`);
participant.tracks.forEach(publication => {
if (publication.isSubscribed) {
const track = publication.track;
document.getElementById('remote-media-div').appendChild(track.attach());
}
});
participant.on('trackSubscribed', track => {
document.getElementById('remote-media-div').appendChild(track.attach());
});
});
}, error => {
alert(`Unable to connect to Room: ${error.message}`);
});
function toggleLocalVideo(){
const local_video = document.getElementById('local_video');
const localMediaContainer = document.getElementById('local-media');
if (local_video.checked == true){
Video.createLocalVideoTrack().then(track => {
localMediaContainer.appendChild(track.attach());
});
} else {
while(localMediaContainer.hasChildNodes){
localMediaContainer.removeChild(localMediaContainer.firstChild);
}
}
}
试图找到可以在文档中随处使用的功能