Twilioビデオアプリケーションで作業していて、マップ経由で配信されるリモート参加者のビデオ/オーディオトラックにアクセスする際に問題が発生しています。開発ツールを使って遊んでみると、私が必要とする値は、私が使っている方法でアクセスできるはずだが、うまくいかないようだ。
設定アップ室用コード:
Javascriptマップで値にアクセスする際に問題が発生する可能性があります。
function connectVid(){
Twilio.Video.connect(localStorage.vidToken, {
audio: true,
video: {width: 520}
}).then(function(room){
window.room = room;
console.log('Connected to Room: ', room.name);
Twilio.Video.createLocalTracks().then(function(localTracks) {
console.log('Creating tracks in Room: ');
console.log(room);
console.log('Got default audio and video tracks: ', localTracks);
var localParticipant = room.localParticipant;
trackArray = localTracks;
console.log(trackArray);
console.log('Connected to the Room as localParticipant "%s"', localParticipant.identity);
var localMediaContainer = document.getElementById('lstream');
localTracks.forEach(function(track) {
localMediaContainer.appendChild(track.attach());
});
})
}).then(function(room){
attachRemoteParticipant();
}).catch(function(err){
console.log(err.message);
if(err.code === 20104) {
getVidToken();
};
})
};
attachRemoteParticipant()。コード:として私が最初に(関数(...){...})の終わりに、connectVid()コード内attachRemoteParticipant機能-抽象UN含む試し
function attachRemoteParticipant() {
room.participants.forEach(function(participant) {
console.log('Participant "%s" is connected to the Room', participant.identity);
var remoteContainer = document.getElementById('rstream');
var remoteTracks = Array.from(participant.tracks.values());
console.log("Remote Tracks COMING:");
console.log(remoteTracks);
remoteTracks.forEach(function(track){
console.log('In Remote 4 each');
console.log(track);
remoteContainer.appendChild(track.attach());
});
});
};
そのように、その後発生したconnectVid外コール:
$('#new-twilio-video').click(function(){
if(localStorage.vidToken == undefined) {
getVidToken();
// attachRemoteParticipant();
} else {
connectVid();
// attachRemoteParticipant();
}
addVidModal();
});
もちろんのコメントを外し。 console.log('Participant "%s" is connected to the Room', participant.identity);
で記録されるものは正しいですが、console.log(remoteTracks);
は空の配列を生成します。ただし、Dev Toolsを使用して実行する場合は、room.participants.forEach(function(participant) {console.log(Array.from(participant.tracks.values());})
私は欲しいものを正確に受け取っています。
私は、値が抽出される準備が整う前に発生しているArray.from(...)
コールと関係があると考えています。したがって、早期実行を防止しようとしていますが、間違っている可能性があります。任意の提案をいただければ幸いです。
編集:devツールは、私が望む配列を提供しますが、undefined
を2番目の結果として提供します。それは問題を引き起こすでしょうか?