10

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 local stream can be obtained and I'm not sending offer until this moment. Then offer is sent and the browser immediately starts to send ICE candidates.

Then if remote browser didn't obtained local media stream yet I get SYNTAX_ERR: DOM Exception 12 on peerConnection.addIceCandidate(candidate) for every ICE candidate received.

I checked documentation on addIceCandidate but there is no info about prerequisites.

I think I can delay sending ICE candidates from offerer by delaying it and waiting for signal that remote client added local stream, but this is additional communication needed and doesn't look right.

Can I somehow add remote ICE candidates to webkitRTCPeerConnection before answer is sent and local media stream is attached?

2
  • For 1st end-point, I check remote ICE candidates after creating offer (github.com/muaz-khan/WebRTC-Experiment/blob/master/ASP.NET-MVC/…) and for 2nd end-point, I check remote ICE candidates when 2nd-peer knows that 1st peer is about to send him offer in a few seconds! (github.com/muaz-khan/WebRTC-Experiment/blob/master/ASP.NET-MVC/…)
    – Muaz Khan
    Commented Nov 15, 2012 at 11:21
  • Thanks for your example :). My problem now is different though. After setting remoteDescription I can get ICE candidates fine. But when I delay allowing media access after all ICE candidates are received then no candidates are sent from receiver side. You handled this by forcing users to allow media access before entering room. It is not an option for me though.
    – Episodex
    Commented Nov 15, 2012 at 12:58

2 Answers 2

16

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.

2
  • Hello @Episodex, what did you do for waiting with setting remoteDescription? Thanks a lot! Commented Mar 3, 2015 at 9:03
  • 2
    @GuillaumeCisco As far as I remember I just set interval of 1 second and waited, but it was wrong! If you have same problem as me then just set remoteDescription before you even have access to camera. This way the browser will handle ICE candidates and establish connection. Then when the video stream is available the browser (or your code - I don't remember now) will send new local description to the peer and the video will go through. But it was over two years ago, a lot could have changed since then (hopefully for better).
    – Episodex
    Commented Mar 4, 2015 at 9:49
3

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.