NAT Issues in WebRTC (Point-to-Point)

382 views
Skip to first unread message

Venkat Sarvesh

unread,
Jul 25, 2016, 6:49:34 AM7/25/16
to discuss-webrtc
Hello,

I followed the below link and able to implement point-to-point video calling. But, it is working in the same network environment and not working between two different networks. Please suggest a solution to solve this issue.


Please find the below code snippet:

navigator.mediaDevices.getUserMedia(constraints)
.then(gotStream)
.catch(function (e) {
alert('getUserMedia() error: ' + e);
});

gotStream: function (stream) {
console.log('Adding local stream.' + isInitiator);
localVideoConnected.src = window.URL.createObjectURL(stream);
localStream = stream;
sendMessage('got user media');
if (isInitiator) {
maybeStart();
}
},

maybeStart: function () {
isChannelReady);
if (!isStarted && typeof localStream !== 'undefined' && isChannelReady) {
console.log('>>>>>> creating peer connection');
createPeerConnection();
pc.addStream(localStream);
isStarted = true;
console.log('isInitiator', isInitiator);
if (isInitiator) {
doCall();
}
}
}

doCall: function () {
console.log('Sending offer to peer');
pc.createOffer(setLocalAndSendMessage, handleCreateOfferError, sdpConstraints);
},
pc.createOffer(setLocalAndSendMessage, handleCreateOfferError, sdpConstraints);

setLocalAndSendMessage: function (sessionDescription) {
console.log('---------------SET LOCAL SDP AND SEND----------');
pc.setLocalDescription(sessionDescription);
console.log('setLocalAndSendMessage sending message', sessionDescription);
sendMessage(sessionDescription);
},

handleCreateOfferError: function (event) {
console.log('createOffer() error: ', event);
}

Console log:

creating peer connection webrtc.controller.js:102:21
Created RTCPeerConnnection webrtc.controller.js:120:21
isInitiator true webrtc.controller.js:106:21
Sending offer to peer webrtc.controller.js:147:17
setLocalAndSendMessage sending message RTCSessionDescription { type: "offer", sdp: "v=0 o=mozilla...THIS_IS_SDPARTA-47.…" } webrtc.controller.js:163:17
Client sending message:  RTCSessionDescription { type: "offer", sdp: "v=0 o=mozilla...THIS_IS_SDPARTA-47.…" } webrtc.controller.js:77:17
icecandidate event:  icecandidate { target: RTCPeerConnection, isTrusted: true, candidate: RTCIceCandidate, currentTarget: RTCPeerConnection, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1469439589615000, originalTarget: RTCPeerConnection, explicitOriginalTarget: RTCPeerConnection } webrtc.controller.js:129:17
Client sending message:  Object { type: "candidate", label: 0, id: "sdparta_0", candidate: "candidate:0 1 UDP 2122187007 192.16…" } webrtc.controller.js:77:17
icecandidate event:  icecandidate { target: RTCPeerConnection, isTrusted: true, candidate: RTCIceCandidate, currentTarget: RTCPeerConnection, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1469439589619000, originalTarget: RTCPeerConnection, explicitOriginalTarget: RTCPeerConnection } webrtc.controller.js:129:17
Client sending message:  Object { type: "candidate", label: 0, id: "sdparta_0", candidate: "candidate:1 1 UDP 2122252543 192.16…" } webrtc.controller.js:77:17
icecandidate event:  icecandidate { target: RTCPeerConnection, isTrusted: true, candidate: RTCIceCandidate, currentTarget: RTCPeerConnection, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1469439589624000, originalTarget: RTCPeerConnection, explicitOriginalTarget: RTCPeerConnection } webrtc.controller.js:129:17
Client sending message:  Object { type: "candidate", label: 0, id: "sdparta_0", candidate: "candidate:0 2 UDP 2122187006 192.16…" } webrtc.controller.js:77:17
icecandidate event:  icecandidate { target: RTCPeerConnection, isTrusted: true, candidate: RTCIceCandidate, currentTarget: RTCPeerConnection, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1469439589627000, originalTarget: RTCPeerConnection, explicitOriginalTarget: RTCPeerConnection } webrtc.controller.js:129:17
Client sending message:  Object { type: "candidate", label: 0, id: "sdparta_0", candidate: "candidate:1 2 UDP 2122252542 192.16…" } webrtc.controller.js:77:17
icecandidate event:  icecandidate { target: RTCPeerConnection, isTrusted: true, candidate: RTCIceCandidate, currentTarget: RTCPeerConnection, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1469439589630000, originalTarget: RTCPeerConnection, explicitOriginalTarget: RTCPeerConnection } webrtc.controller.js:129:17
Client sending message:  Object { type: "candidate", label: 1, id: "sdparta_1", candidate: "candidate:0 1 UDP 2122187007 192.16…" } webrtc.controller.js:77:17
icecandidate event:  icecandidate { target: RTCPeerConnection, isTrusted: true, candidate: RTCIceCandidate, currentTarget: RTCPeerConnection, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1469439589632000, originalTarget: RTCPeerConnection, explicitOriginalTarget: RTCPeerConnection } webrtc.controller.js:129:17
Client sending message:  Object { type: "candidate", label: 1, id: "sdparta_1", candidate: "candidate:1 1 UDP 2122252543 192.16…" } webrtc.controller.js:77:17
icecandidate event:  icecandidate { target: RTCPeerConnection, isTrusted: true, candidate: RTCIceCandidate, currentTarget: RTCPeerConnection, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1469439589635000, originalTarget: RTCPeerConnection, explicitOriginalTarget: RTCPeerConnection } webrtc.controller.js:129:17
Client sending message:  Object { type: "candidate", label: 1, id: "sdparta_1", candidate: "candidate:0 2 UDP 2122187006 192.16…" } webrtc.controller.js:77:17
icecandidate event:  icecandidate { target: RTCPeerConnection, isTrusted: true, candidate: RTCIceCandidate, currentTarget: RTCPeerConnection, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1469439589637000, originalTarget: RTCPeerConnection, explicitOriginalTarget: RTCPeerConnection } webrtc.controller.js:129:17
Client sending message:  Object { type: "candidate", label: 1, id: "sdparta_1", candidate: "candidate:1 2 UDP 2122252542 192.16…" } webrtc.controller.js:77:17
icecandidate event:  icecandidate { target: RTCPeerConnection, isTrusted: true, currentTarget: RTCPeerConnection, eventPhase: 2, bubbles: false, cancelable: false, defaultPrevented: false, timeStamp: 1469439589640000, originalTarget: RTCPeerConnection, explicitOriginalTarget: RTCPeerConnection, NONE: 0 } webrtc.controller.js:129:17
End of candidates. webrtc.controller.js:138:21
Client received message: Object { type: "answer", sdp: "v=0 o=mozilla...THIS_IS_SDPARTA-47.…" } -- true webrtc.controller.js:461:13
Remote stream added. webrtc.controller.js:202:17
HTTP "Content-Type" of "text/html" is not supported. Load of media resource https://192.168.1.59:5000/ failed. /
Client received message: Object { type: "candidate", label: 0, id: "sdparta_0", candidate: "candidate:0 1 UDP 2122252543 192.16…" } -- true webrtc.controller.js:461:13
ICE failed, see about:webrtc for more details (unknown)

Please do the needful.

Thanks in advance,
Venkat.



Philipp Hancke

unread,
Jul 25, 2016, 7:12:34 AM7/25/16
to discuss...@googlegroups.com
Use a TURN servers, see http://www.html5rocks.com/en/tutorials/webrtc/infrastructure/

Standard disclaimer: there are no 'free TURN servers'

--

---
You received this message because you are subscribed to the Google Groups "discuss-webrtc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to discuss-webrt...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/discuss-webrtc/c201d213-9e97-47d0-bb46-e14e884deca8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Venkat Sarvesh

unread,
Jul 26, 2016, 3:58:51 AM7/26/16
to discuss-webrtc
Hi Philipp,

Thanks for quick reply. 

I added TURN server in 
var pcConfig = {
    'iceServers': [{
        'url': 'stun:stun.l.google.com:19302'
    },
{
url: 'turn:numb.viagenie.ca',
credential: 'muazkh',
username: 'web...@live.com'
}]
};

And the code that is referring these servers is as below:

function requestTurn(turnURL) {
    var turnExists = false;
    for (var i in pcConfig.iceServers) {
        if (pcConfig.iceServers[i].url.substr(0, 5) === 'turn:') {
            turnExists = true;
            turnReady = true;
            break;
        }
    }
    if (!turnExists) {
        console.log('Getting TURN server from ', turnURL);
        // No TURN server. Get one from computeengineondemand.appspot.com:
        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4 && xhr.status === 200) {
                var turnServer = JSON.parse(xhr.responseText);
                console.log('Got TURN server: ', turnServer);
                pcConfig.iceServers.push({
                    'url': 'turn:' + turnServer.username + '@' + turnServer.turn,
                    'credential': turnServer.password
                });
                turnReady = true;
            }
        };
        xhr.open('GET', turnURL, true);
        xhr.send();
    }
}

Still getting the same issue, let me know if there is something that I'm missing.

Thanks,
Venkat

Venkat Sarvesh

unread,
Jul 26, 2016, 3:58:52 AM7/26/16
to discuss-webrtc
Thanks for reply Philipp,

I added TURN server in pcConfig Jason along with STUN server and passed as parameter while creating new PeerConnection() instance. Please let me know if there is something i missed.

Thanks,
Venkat.


On Monday, July 25, 2016 at 4:42:34 PM UTC+5:30, Philipp Hancke wrote:

Philipp Hancke

unread,
Jul 26, 2016, 4:03:59 AM7/26/16
to discuss...@googlegroups.com
Are you Muaz Khan? If not why are you trying to use his credentials for the numb.viagenie.ca turn server? While he is a nice guy, he doesn't want to pay the bill for other people.
Consequently, he changed his credentials which means that you are using credentials which don't work. Which is the same as running without a TURN server.

http://numb.viagenie.ca/ allows you to create an account for free...

Venkat Sarvesh

unread,
Jul 27, 2016, 3:34:05 AM7/27/16
to discuss-webrtc
True, I'm not Muaz Khan. And I'm now using my own TURN server. Its working on FireFox, but not on Chrome, AND chrome is not even saying that "ICE Failed", any help on this.

Thanks & Regards,
Venkat

Venkat Sarvesh

unread,
Jul 27, 2016, 3:34:25 AM7/27/16
to discuss-webrtc
AND Philipp, do we need TLS/SSL enabled for TURN server as my app is HTTPS enabled?

Thanks,
Venkat

Philipp Hancke

unread,
Jul 27, 2016, 10:27:16 AM7/27/16
to discuss...@googlegroups.com
2016-07-26 11:17 GMT+02:00 Venkat Sarvesh <sarvesh...@gmail.com>:
True, I'm not Muaz Khan. And I'm now using my own TURN server.

\o/
 
Its working on FireFox, but not on Chrome, AND chrome is not even saying that "ICE Failed", any help on this.

add a listener for the iceconnectionstatechange event. See e.g. https://github.com/webrtc/samples/blob/gh-pages/src/content/peerconnection/states/js/main.js#L81
chrome://webrtc-internals may offer more insight on what candidates are generated and added.

TURN/TCP will work but you might want to add TURN/TLS as there are some cases where clients are on networks that block one but not the other.
 

Venkat Sarvesh

unread,
Jul 28, 2016, 5:08:38 AM7/28/16
to discuss-webrtc
Hi Philipp, I tried enabling TLS on TURN and even added listener for iceconnectionstatechange event. Got the event sequence on chrome://webrtc-internals, it is stating as ICEConnectionStateFailed. But not sure what is the issue. Any help is appreciated.

Thanks,
Venkat

Venkat Sarvesh

unread,
Jul 28, 2016, 6:39:51 AM7/28/16
to discuss-webrtc
Attaching the logs
webrtc_internals_dump (2).txt

Philipp Hancke

unread,
Jul 28, 2016, 6:43:57 AM7/28/16
to discuss...@googlegroups.com
you're not generating any candidates with 'typ relay' in the onIceCandidate event. Either your TURN server is not reachable or your credentials are wrong. Wireshark is the easiest way to check that.

Venkat Sarvesh

unread,
Jul 28, 2016, 9:40:36 AM7/28/16
to discuss-webrtc
Thanks Philipp. When I see FireFox icecandidate events, I'm able to see typ relay candidates with same TURN server. Is there some issue with enabling TLS on TURN?
I'm using self-signed certificate, does this cause the issue I'm facing?

Thanks,
Venkat
Message has been deleted

Peng

unread,
Aug 1, 2016, 11:38:36 PM8/1/16
to discuss-webrtc
Self-signed certificate will cause the issue.
And try this sample https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/ to find whether your STUN/TURN really work.

Venkat Sarvesh

unread,
Aug 2, 2016, 2:53:24 AM8/2/16
to discuss-webrtc
Philipp, does the bandwidth plays any role in ice failed issue in chrome/opera. Because, with same TURN server I'm able to connect video call for 10-40 seconds and then getting iceconnectionstatefailed in chrome/opera, but working very well in FF.

Thanks,
Venkat

Venkat Sarvesh

unread,
Aug 22, 2016, 2:22:25 PM8/22/16
to discuss-webrtc
Hi Philipp and Peng,

Thanks for the help. I found the issue. Its all in STUN/TURN server set up. Its working perfectly now. Thanks to both of you once again!!

Thanks,
Venkat
Reply all
Reply to author
Forward
0 new messages