How to dynamic create WebRTC offer with promise method?

时间:2018-08-22 13:50:12

标签: javascript firebase promise

I'm new in WebRTC and javascript. I want to connect with more than two people. So I need to create offer to each player. But when I'm in the promise method, I can't read value of variable.

var pc = {};
for(i=0;i<=otherplayers.length-1;i++){
  pc[otherplayers[i]]= new RTCPeerConnection(servers);
  pc[otherplayers[i]].createOffer()
    .then(offer => pc[otherplayers[i]].setLocalDescription(offer) )
    .then(() => sendMessage("offer",myid, JSON.stringify({'sdp':pc[otherplayers[i]].localDescription})) );
}

Each "otherplayers[i]" after "then." can't be use .

Is there anything i miss?

0 个答案:

没有答案