webrtc:启动器如何创建对等连接?

时间:2018-07-31 16:04:48

标签: javascript html5 webrtc

我正在尝试为项目找到webrtc,但是我被困在这一部分,我无法了解启动器如何能够创建连接?

让我尝试用代码本身来解释我的疑问(直接来自docs步骤05)。 请阅读代码中的注释

navigator.mediaDevices.getUserMedia({
  audio: false,
  video: true
})
.then(gotStream)   // over here we get the stream and call then gotStream function
.catch(function(e) {
  alert('getUserMedia() error: ' + e.name);
});

function gotStream(stream) {
  console.log('Adding local stream.');
  localStream = stream;
  localVideo.srcObject = stream;
  sendMessage('got user media');   // eventually calling maybeStart(); but, WHAT IS THE USE OF CALLING THAT FUNCTION TWICE IF YOU ARE THE INITIATOR AND BOTH OF THE TIME ITS IT DOESN'T DO ANYTING BECUASE isChannelReady == FALSE .!   
  if (isInitiator) {  // TRUE is you're a initiator
    maybeStart();  // and here. 
  }
}

maybeStart()函数如下所示,

function maybeStart() {
  console.log('>>>>>>> maybeStart() ', isStarted, localStream, isChannelReady);  // isChannelReady is FALSE BOTH OF THE TIME!!
  if (!isStarted && typeof localStream !== 'undefined' && isChannelReady) {
    console.log('>>>>>> creating peer connection');
    createPeerConnection();
    pc.addStream(localStream);
    isStarted = true;
    console.log('isInitiator', isInitiator);
    if (isInitiator) { // how did we even reach here???
      doCall();
    }
  }
}

我要做的是将单个主机分配给多个客户端。而且我不希望客户端的流向主机(Initaitor)。

有什么猜想吗?

0 个答案:

没有答案