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.

Can't fetch relay candidates even though my STUN/TURN servers are working

See original GitHub issue

Once I set local description on the peer connection object, the ice pc.onicecandidate event is fetching all candidates except the relay one, with my server’s IP address.

Here’s the screenshot of the console log for each new candidate I’m receiving: https://imgur.com/a/3eRMjB0

I’ve checked both STUN and TURN servers on Trickle ICE, and I’m getting all candidates, including the relay candidates with the IP address of my public server (it’s hosted on DigitalOcean). I’m also using Coturn, with the default configuration.

0.166 | 1 | relay | 3 | udp | {my public server's IP address} | 63254 | 5 \| 32542 \| 255

Am I doing something wrong?

        mediaDevices.enumerateDevices().then(sourceInfos => {
            console.log(sourceInfos);
            let videoSourceId;
            for (let i = 0; i < sourceInfos.length; i++) {
                const sourceInfo = sourceInfos[i];
                if (sourceInfo.kind === "videoinput" && sourceInfo.facing === (isFront ? "front" : "environment")) {
                    videoSourceId = sourceInfo.deviceId;
                }
            }
            mediaDevices.getUserMedia({
                audio: true,
                video: {
                    mandatory: {
                        minFrameRate: 30
                    },
                    facingMode: (isFront ? "user" : "environment"),
                    optional: (videoSourceId ? [{ sourceId: videoSourceId }] : [])
                }
            })
                .then(async (stream) => {
                    this.setState({ localStream: stream });
                    const configuration = {
                        "iceServers": [{
                            "urls": "turn:*********:3478",
                            credential: "**********",
                            username: "**************"
                        }, {
                            "urls": "stun:**********:3478",
                        }]
                    };

                    const pc = new RTCPeerConnection(configuration);
                    const socket = this.socket;
                    const meetingID = this.meetingID;
                    pc.onnegotiationneeded = (event) => {
                        console.log(event);

                        pc.createOffer().then(desc => {
                            pc.setLocalDescription(desc).then(() => {
                                // Send pc.localDescription to peer
                                socket.emit("send-offer", {
                                    meetingID: meetingID,
                                    offer: pc.localDescription
                                });
                            });
                        });
                    }

                    this.socket.on("remote-description", async (description) => {
                        const remoteDesc = new RTCSessionDescription(description);

                        await pc.setRemoteDescription(remoteDesc);
                    });

                    pc.onicecandidateerror = function (event) {
                        console.warn(event);
                    }

                    pc.onicecandidate = function (event) {
                        console.log(event.candidate);
                        if (event.candidate) {
                            socket.emit("to-host-new-ice-candidate", { meetingID: meetingID, iceCandidate: event.candidate });
                        }
                    };

                    this.socket.on("new-ice-candidate", async data => {
                        if (data.iceCandidate) {
                            try {
                                await pc.addIceCandidate(data.iceCandidate);
                            } catch (e) {
                                console.log("ICE error: ", e);
                                this.props.navigation.goBack();
                            }
                        }
                    });

                    const ref = this;

                    pc.oniceconnectionstatechange = function (event) {
                        console.log("Change: ", event);
                    }

                    pc.addStream(stream);
                    pc.onaddstream = function (event) {
                        console.log(event.stream);
                        ref.setState({ remoteStream: event.stream });
                    }
                    pc.onconnectionstatechange = function (event) {
                        if (pc.connectionState === "connected") {
                            // connected
                        } else {
                            ref.setState({ remoteStream: stream });
                        }

                    }
                })
                .catch(error => {
                    console.log(error);
                    Alert.alert("Error", "Media stream error.")
                });
        });

Platform information

  • React Native version: 0.63.2
  • Plugin version: 1.84.0
  • OS: Android
  • OS version: Android 7.1.1 on both emulator and the physical device

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:14

github_iconTop GitHub Comments

1reaction
Marwollocommented, Sep 7, 2020

Just tried Xirsys. Nope, same results.

1reaction
danjenkinscommented, Sep 7, 2020

Xirsys you dont need to buy - they offer you a free developer account

Google’s STUN server wont give you TURN /relay results because its a stun server, not a turn server.

onicecandidate of null means it finished gathering

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to test/troubleshoot simple coturn setup for webrtc?
I'm trying to get a TURN server using coturn working to relay for me with this config. var config = { 'iceServers': [...
Read more >
Troubleshooting WebRTC Connection Issues - Deconstruct
Relay : These are generated the same way as a Server Reflexive candidate. The query message is sent to the TURN server creating...
Read more >
Coturn server - Relay is not working - Stack Overflow
For some of the networks the STUN candidates are constantly failing, so I need to get a TURN server to relay the stream....
Read more >
WebRTC TURN Servers: When you NEED it • BlogGeek.me
The NAT traversal servers in WebRTC are in charge of making sure the media gets properly connected. These servers are STUN and TURN....
Read more >
Troubleshooting TURN - Giacomo Vacca
'host', 'server reflexive' and 'relay' candidates are left to compete with ... If the STUN Binding Request is received by the TURN server, ......
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