The app: I'm developing app that allows peers to connect to each other, I use mediasoup and WebRTC (SFU).
The problem: Everything works locally but when deployed to VPS (I use Vultr) peers can not connect. On VPS firewall ports are open for the range declared in mediasoup (tcp and udp).
I went through several questions here on stackoverflow but unfortunatelly none of it helps:
- set up TURN server: WebRTC connection does not establish after successful signaling How do I configure WebRTC to connect to my TURN server?
I use metered.ca, and I pass configuration on the client side:
producerTransportRef.current = deviceRef.current.createSendTransport({
...params,
iceServers: [
{
urls: 'stun:stun.relay.metered.ca:80',
},
{
urls: 'turn:a.relay.metered.ca:80',
username: 'XXX',
credential: 'YYY',
},
{
urls: 'turn:a.relay.metered.ca:80?transport=tcp',
username: 'XXX',
credential: 'YYY',
},
{
urls: 'turn:a.relay.metered.ca:443',
username: 'XXX',
credential: 'YYY',
},
{
urls: 'turn:a.relay.metered.ca:443?transport=tcp',
username: 'XXX',
credential: 'YYY',
},
],
});
params come from the server from defining mediasoup transport and are passed to the frontend where are merged with TURN server configs:
let transport = await router.createWebRtcTransport(webRtcTransport_options);
callback({
// https://mediasoup.org/documentation/v3/mediasoup-client/api/#TransportOptions
params: {
id: transport.id,
iceParameters: transport.iceParameters,
iceCandidates: transport.iceCandidates,
dtlsParameters: transport.dtlsParameters,
},
});
When I print the iceCandidate I get from the server there's my server ip address

When I run webrtc-internals in chrome I get:

I followed the error code:
701 error code - If no host candidate can reach the server, errorCode will be set to the value 701 which is outside the STUN error code range.
I noticed that the host candidate is in my local network (not sure if that's the problem)
I'd highly appreciate even suggestions on what to check next
Error code 701 here is due to Metered not responding to your binding_request (error code 701 indicates a binding_request timeout, the purpose of the binding_request is to check your public IP, essentially to create a srflx candidate). This is because you are using the "turn:" scheme instead of "stun:".
For Chrome, when you perform the trickle ice candidate check here, you can use Wireshark to capture the sent packets. You will see the binding_request being sent out, but there won't be a response from Metered. Instead, Metered will only respond to your allocate_request (basically to create a relay candidate). So, in my opinion, this error code is not the main issue here. I think you need to provide additional information to understand why you cannot establish a WebRTC connection.