peerjs icon indicating copy to clipboard operation
peerjs copied to clipboard

On Call (Only from webview) not working with message: webRTC: ICE failed, your turn server appear to be broken

Open guydoron opened this issue 5 years ago • 5 comments

Can someone help on this. This is only when 1 peer on the computer and 1 peer on app webview (android). This is both from peerjs default server and my own custom server based on peerjs github. It worked before 2 days no difference in code.

Reciever: ` var myvideo = document.getElementById("body");

//const peer = new Peer('a0f2831c-940b-45b7-b750-3c5824773875');
const peer = new Peer('a0f2831c-940b-45b7-b750-3c5824773875',{
        host: 'xxxx.xxxx',
        port: 9000,
        path: '/'
},{debug:3});

peer.on('open', function(id) {
    console.log('My peer ID is: ' + id);
    //alert(id);
});

function hasUserMedia() { 
    //check if the browser supports the WebRTC 
    return !!(navigator.mediaDevices.getUserMedia || navigator.webkitGetUserMedia || 
        navigator.mozGetUserMedia); 
} 

peer.on('connection', function(conn) {
    alert('peer connected');
    conn.on('data', function(data){
        // Will print 'hi!'
        console.log(data);
        //alert(data);
    });

    peer.on('call', function(call) {
        // Answer the call, providing our mediaStream
        if (hasUserMedia()) { 
            navigator.getUserMedia = navigator.mediaDevices.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;   
            //enabling audio channels 
            navigator.mediaDevices.getUserMedia({ video: false, audio: true }, function (stream) { 
                call.answer(stream);
                call.on('stream', function(remoteStream) {
                    // Show stream in some video/canvas element.
                    document.getElementById("myvideo").srcObject = remoteStream;
                    setTimeout(function(){ document.getElementById("myvideo").play(); }, 1000);
                });
            }, function (err) {alert(err);}); 
        } else { 
            alert("WebRTC is not supported"); 
        }
    });
});`

Caller: ` const peer = new Peer('a0f2831c-940b-45b7-b750-3c5824773877',{ host: 'xxxx.xxxxx', port: 9000, path: '/' },{debug:3});

    peer.on('open', function(id) {
        console.log('My peer ID is: ' + id);
        var conn = peer.connect("a0f2831c-940b-45b7-b750-3c5824773875");
        // on open will be launch when you successfully connect to PeerServer
        conn.on('open', function(){
            // here you have conn.id
            conn.send('imon'); // send im on so the ubuntu would konw i'm avaliable
        });

        conn.on('data', function(data){
            // Will print 'hi!'
            console.log(data);
        });

        if (hasUserMedia()) { 
            var getUserMedia = navigator.mediaDevices.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
            getUserMedia({video: false, audio: true}, function(stream) {
            var call = peer.call('a0f2831c-940b-45b7-b750-3c5824773875', stream);
            call.on('stream', function(remoteStream) {
                // Show stream in some video/canvas element.
                document.getElementById("myvideo").srcObject = remoteStream;
                setTimeout(function(){ document.getElementById("myvideo").play(); }, 1000);
            });
            }, function(err) {
                alert(err);
                console.log('Failed to get local stream' ,err);
            });
        } else { 
            alert("WebRTC is not supported"); 
        }
    });

    function hasUserMedia() { 
        //check if the browser supports the WebRTC 
        return !!(navigator.mediaDevices.getUserMedia || navigator.webkitGetUserMedia || 
            navigator.mozGetUserMedia); 
    } `

guydoron avatar Oct 29 '20 08:10 guydoron

UPDATE: Not only from webview. Also desktop browser. Also sometimes all works and I get in console webRTC: ICE failed, your turn server appears to be broken and sometimes it's working well.

guydoron avatar Nov 01 '20 07:11 guydoron

Well, on local WIFI all work all the time. IT only happens when working remotely i use ngrok to tunnel http to the internet. web page working of course. All is on https also peerjs - server (my own cloud).

guydoron avatar Nov 02 '20 08:11 guydoron

Error: Negotiation of connection to 28d84f60-bda9-4ce8-beeb-3813df268434 failed.

Doesn't work for me too when trying to connect using cellular networks. If I'm connected to WIFI, it works. Found out that the connection is initiated, but does not connect. Perhaps the cellular networks refuse a connection?

benhatsor avatar Dec 22 '20 07:12 benhatsor

@guydoron where do you see that message about your TURN server? i'm asking because we are also having a problem with peer connections that only happens on cellular network (in fact it only happens on AT&T).

johnkcox avatar Dec 22 '20 21:12 johnkcox

Well, i just moved to twillio stun/turn travelsal service and all issues where gone: https://www.twilio.com/stun-turn

On Tue, Dec 22, 2020, 23:29 John Cox [email protected] wrote:

@guydoron https://github.com/guydoron where do you see that message about your TURN server? i'm asking because we are also having a problem with peer connections that only happens on cellular network (in fact it only happens on AT&T).

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/peers/peerjs/issues/751#issuecomment-749784555, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA2WXYL3RJWG7S6ML4TE3XTSWEFUHANCNFSM4TDNJ5YA .

guydoron avatar Dec 23 '20 18:12 guydoron