在发送答案之前收到ICE候选人时的错误

时间:2012-11-15 10:56:40

标签: google-chrome webrtc

我正在Chrome 23上建立WebRTC连接。要附加本地流,您需要允许浏览器使用摄像头和麦克风。在呼叫者方面,我正在检查是否可以获得本地流,直到这一刻我才发送报价。然后发送报价,浏览器立即开始发送ICE候选人。

然后,如果远程浏览器没有获得本地媒体流,那么对于收到的每个ICE候选者,我在SYNTAX_ERR: DOM Exception 12上获得peerConnection.addIceCandidate(candidate)

我在addIceCandidate上检查了documentation,但没有关于先决条件的信息。

我认为我可以通过延迟发送ICE候选人并等待远程客户端添加本地流的信号来延迟发送ICE候选者,但这需要额外的通信,看起来不正确。

在发送应答并附加本地媒体流之前,我可以以某种方式将远程ICE候选添加到webkitRTCPeerConnection吗?

2 个答案:

答案 0 :(得分:7)

在我写完这个问题之后,我想到了一个答案......在收到ICE候选人之前不需要附加本地流,但是应该设置remoteDescription(这应该在收到报价时进行) )。在我的代码中,我等待设置remoteDescription并发送答案,直到浏览器获得本地流。

答案 1 :(得分:0)

Episodex的解决方案对我有所帮助。

首先设置setRemoteDescription,然后创建自己的流,然后创建并发送答案。

  // 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}))

  }