Errors when ICE Candidates are received before answer is sent

后端 未结 2 629
深忆病人
深忆病人 2020-12-10 16:01

I\'m establishing WebRTC connection on Chrome 23. To attach local stream you need to allow browser to use the camera and microphone. On the caller side I\'m checking if loca

相关标签:
2条回答
  • 2020-12-10 16:33

    The solution from Episodex helped me.

    First setRemoteDescription, then create own stream, then create and send the answer.

      // On read message
      if (msg.sdp.type === 'offer') {
    
            this.peerConnection.setRemoteDescription(new RTCSessionDescription(msg.sdp))
              .then(() => navigator.mediaDevices.getUserMedia({audio: true, video: true}))
              .then(stream => this.peerConnection.addStream(stream));
              .then(() => this.peerConnection.createAnswer())
              .then(answer => this.peerConnection.setLocalDescription(answer))
              .then(() => this.sendMessage({sdp: this.peerConnection.localDescription}))
    
      } 
    
    0 讨论(0)
  • 2020-12-10 16:45

    After I wrote this question an answer came into my mind... There is no need for attaching local stream before receiving ICE candidates, but remoteDescription should be set (which should be done at the moment of receiving offer). In my code I waited with setting remoteDescription and sending answer until browser gets the local stream.

    0 讨论(0)
提交回复
热议问题