question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Connection failed when I dial to my friend outside my network

See original GitHub issue

I am getting the connection failed when I try to connect to my friend via the internet outside my network but when I dial to a different network which is also outside my network everything works, so I set up my on TURN server and tested using https://webrtc.github.io/samples/src/content/peerconnection/trickle-ice/ turn server works well, but why I am getting a connection failed someone please help

Frontend code 

var Peer = require('simple-peer')
let socket = io();

socket.on('connect', function() {

    function InitPeer(init=false,stream=null) {
        let peer = new Peer({initiator: init,stream:stream,trickle: false,reconnectTimer: 100,
            iceTransportPolicy: 'relay',
            config: {

                iceServers: [
                    {
                        urls: "stun:xx.ml",
                        username: "shehin",
                        credential: "shehin"
                    },
                    {
                        urls: "turn:xx.ml",
                        username: "shehin",
                        credential: "shehin"
                    }
                ]
            }});
        return peer;
    }

    function CreateVideo(stream) {
        let video = document.querySelector('video');
        video.srcObject = stream;
        video.play();
        return stream;
    }
    function InitiateBroadcaster() {

        let peers={};

        navigator.getUserMedia({video: true, audio: true}, gotMedia, (err) => {
            console.log(err);
        });

        socket.emit('broadcaster_found',{socketId:socket.io.engine.id});

        function gotMedia(stream) {
            stream = CreateVideo(stream);

            //STEP - 3
            function FrontOfferRequest(_data)
            {
                try {
                    _data = JSON.parse(_data);
                    let peer = InitPeer(true, stream);
                    peer.on('signal', data => {
                        console.log(data);
                        let _socketId = _data.socketId;
                        peers[_socketId] = peer;
                        socket.emit('back_offer', JSON.stringify({'data': data, 'socketId': _data.socketId}));
                    });
                    peer.on('connect', () => {
                        console.log('CONNECTED')
                    });
                    peer.on('error', (err) => {
                        console.log(err);
                    });

                    peer.on('close', function () {
                        peer.destroy();
                    });
                }catch (e) {
                    console.log(e);
                }
            }
            //STEP - 7
            function FrontAnswer(_data){
                try {
                    _data = JSON.parse(_data);
                    peers[_data.socketId].signal(_data.data);
                }catch (e) {
                    console.log(e);
                }
            }
            socket.on('front_offer_request',FrontOfferRequest);
            socket.on('front_answer',FrontAnswer);

        }
    }

    function InitiateReceiever() {
        // STEP - 1
        socket.emit('back_offer_request');

        let peer = new Peer();
        peer.on('signal', data => {
            console.log(data);

            socket.emit('back_answer',JSON.stringify({'data':data}));
        });
        peer.on('close', function () {
            peer.destroy();
        });
        peer.on('error', (err) => {
            console.log(err);
        });
        peer.on('stream', stream => {
            CreateVideo(stream);

        });

        // STEP - 5
        function FrontOffer(_data)
        {
            try {

                _data = JSON.parse(_data);
                peer.signal(_data.data);
            }catch (e) {
                console.log(e);
            }
        }
        socket.on('front_offer',FrontOffer);

    }
    location.hash === '#Broadcast' ? InitiateBroadcaster() : InitiateReceiever();


});

Error: Connection failed. at makeError (bundle.js:5988) at Peer._onConnectionStateChange (bundle.js:6625) at RTCPeerConnection.Peer._pc.onconnectionstatechange (bundle.js:6090)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
AarumugamGcommented, May 21, 2020

I have same issue.

0reactions
ahaydercommented, Nov 3, 2020

same here. 😢

Read more comments on GitHub >

github_iconTop Results From Across the Web

7 Ways to fix call failure on your phone-Carlcare
This call failure issue can be caused from different factors like poor network reception, due to call barring settings or you mistakenly turned ......
Read more >
8 ways to fix a call failed message on your iPhone
One of the most common reasons a call fails is because of a glitch with your cellular connection. You can generally fix this...
Read more >
Fix Wi-Fi connection problems - Google Fi Help
Phone: Try connecting to the Wi-Fi network with another device, like a laptop computer or friend's phone. If other devices can use the...
Read more >
If you can't make or receive calls on your iPhone - Apple Support
Check your network settings · Reset your network settings. Go to Settings > General > Transfer or Reset iPhone > Reset > Reset...
Read more >
Troubleshoot wireless network connection problems in 10 steps
Wireless connection problems often frustrate end users and IT. Follow these troubleshooting steps to untangle wireless connection issues.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found