5

I am trying to establish a p2p audio/video connection b/w two peers. Following: Getting started with WebRTC.

It works fine at my home in LAN Environment between 2 PCs, but throws an error message when running at my company's LAN Environment, there is part the javascript

function processSignalingMessage(message) {
        var msg = JSON.parse(message);

        if (msg.type === 'offer') {
            // Callee creates PeerConnection
            if (!initiator && !started)
                maybeStart();

            // We only know JSEP version after createPeerConnection().
            if (isRTCPeerConnection)
                pc.setRemoteDescription(new RTCSessionDescription(msg));
            else
                pc.setRemoteDescription(pc.SDP_OFFER,
                        new SessionDescription(msg.sdp));

            doAnswer();
        } else if (msg.type === 'answer' && started) {
            pc.setRemoteDescription(new RTCSessionDescription(msg));
        } else if (msg.type === 'candidate' && started) {
            var candidate = new RTCIceCandidate({
                sdpMLineIndex : msg.label,
                candidate : msg.candidate
            });
            pc.addIceCandidate(candidate);
        } else if (msg.type === 'bye' && started) {
            onRemoteHangup();
        }
    }

when the first user recieved message "type":"candidate",get wrong

and part of the console log:

  • Creating PeerConnection
  • Created webkitRTCPeerConnnection with config "{"iceServers":[{"url":"stun:stun.l.google.com:19302"}]}"
  • Adding local stream
  • Sending answer to peer
  • recieved message : {"type":"candidate","label":0,"id":"audio","candidate":"a=candidate:1613033416 1 udp 2113937151 192.168.1.233 56946 typ host generation 0\r\n"}
  • Uncaught SyntaxError: Failed to execute 'addIceCandidate' on 'RTCPeerConnection': The ICE candidate could not be added
  • recieved message : {"type":"candidat".......}
  • Uncaught SyntaxError: Failed to execute 'addIceCandidate' on 'RTCPeerConnection': The ICE candidate could not be added
  • recieved message : {"type":"candidat".......}
  • Uncaught SyntaxError: Failed to execute 'addIceCandidate' on 'RTCPeerConnection': The ICE candidate could not be added

1 Answer 1

0

I think you can create the ICE candidate message by using just the msg.candidate,

var candidate = new RTCIceCandidate(msg.candidate);

And pass that into the addIceCandidate function

3
  • 10
    I have solved the problem.Errors when ICE Candidates are received before answer is sent 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.
    – yang Joe
    Commented Aug 22, 2014 at 2:08
  • 2
    Could you add the answer? Commented Mar 8, 2016 at 6:11
  • @yangJoe please remember to write an answer if you solved your own problem, so you can mark that as the accepted solution to this problem. Commented Oct 31, 2023 at 22:16

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