react-native-webrtc: Can't fetch relay candidates even though my STUN/TURN servers are working
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
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 15
Just tried Xirsys. Nope, same results.
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