Need help regarding setting up turn server with mediasoup server

Hi Team,

First of all, thank you for the Mediasoup, It’s amazing.
I just need some help related to turn setup. I read IBC’s comment is one of the turn/stun setup post.

As per IBC :

mediasoup (server) does not need any knowledge/configuration related to TURN. You must setup your TURN server so it has proper direct networking to the mediasoup server. That’s all.

In the client side you pass STUN/TURN servers when creating a send/recv transport:

I’m very new to this turn/stun. But as per the above comment, we put ice servers info in our client config and I saw we received packets in Coturn logs and the connection is also stated as a relay. I Just don’t know how we make a direct connection to our mediasoup server from the turn server?

Can anyone help me or share his approach to setting up the turn server to the mediasoup?

Do you have STUN and TURN server URLs? if so, you just need to add the info to in the client side.

recvTransport = mediasoupDevice.createRecvTransport({ iceServers: [ ] )}

and you need to add IceServer to createSendTransport as well.
You can find an example of how to the array format looks like

for security you may want to use proxy to save your TURN server credential

Always add stun and turn so in case stun does not work, you can rely your media over turn.

Configuring a STUN server in a mediasoup-client is completely useless. mediasoup server is ICE Lite so it’s not gonna check client’s ICE candidates (which cannot even be signaled to mediasoup BTW). So this is incorrect.

Of course, you can configure a TURN server, but zero reasons to use a STUN server.

1 Like

@ibc Thank you for the info. I am coming from native Webrtc. good to know that stun is not needed. does that mean mediasoup-client will always try to avoid using TURN unless it was required? my concerned that TURN server will be used for ice candidates where TURN is not required.

I am wondering why the docs has “In the client side you pass STUN/TURN servers when creating a send/recv transport:” if mediasoup-client does not need it

Thanks, IBC for the info, but we need the Turn as we are inside a very strict firewall where we can’t expose too many open ports. So as a workaround, we need the Stun/Turn to listen on 443 and communicate with the Mediasoup server internally.

I just don’t understand or find anything related to configuring my Turn to have a direct connection with the Mediasoup server. I checked turnserver.conf file there I don’t find any field with the help of that we can achieve a direct connection. As you mentioned in your comment.

You must setup your TURN server so it has proper direct networking to the mediasoup server.

Do you mean we have to put the Turn and the Mediasoup on the same server?

The client will send packets through the TURN server with the announced address of the mediasoup server as destination, mediasoup will see some address of the TURN server as the origin address. So you should make sure that there is a direct link between mediasoup’s external address and the address allocated by the TURN server for the client.

You know there is WebRtcServer class in mediasoup which listen into a single port, right?

1 Like

Right. Thanks for the comment, I’m actually forgetting about this thing. But now everything is clear.

Thanks again :blush: