Search code examples
webrtcpeerjsice-protocol

WebRTC "ICE Failed" , error


So, i'm trying to build a webrtc video chat web app using peer.js. So far so good, everything seems to work right. The problem starts when i run my app on my private server.

Everytime i try to answer or make a call the video starts playing for a few seconds, but with black screen, and then i get the ICE Failed error and it disconnects.

This wont happen if the two users share the same ip address. If the users share the same ip the video chat works fine and there is no problem at all.

What could be the problem here?

UPDATE

i added stun and turn server on peer but i get the same error again

peer = new Peer({ key: peerApiKey, debug: 3, config: {'iceServers': [
            { url: 'stun:stun.l.google.com:19302' },
            { url: 'stun:stun1.l.google.com:19302' },
            { url: 'turn:numb.viagenie.ca:3478', credential: 'muazkh', username:'webrtc@live.com' },
            { url: 'turn:numb.viagenie.ca', credential: 'muazkh', username:'webrtc@live.com' },
            { url: 'turn:192.158.29.39:3478?transport=udp', credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=', username:'28224511:1379330808' },
            { url: 'turn:192.158.29.39:3478?transport=tcp', credential: 'JZEOEt2V3Qb0y27GRntt2u2PAYA=', username:'28224511:1379330808' }
        ]}});

Solution

    • You need to set a valid STUN server (maybe the peer.js defaults are not working). This will solve the problem in around 80% of the cases.
    • In some situations a TURN service is also required to complete the calls.
    • And in some situations even TURN is not enough (for example if UDP is blocked for both end) and in these circumstances you need a server to route the media (via TCP/TURN).