Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API to force Janus to use TURN #2774

Merged
merged 2 commits into from
Sep 27, 2021
Merged

Add API to force Janus to use TURN #2774

merged 2 commits into from
Sep 27, 2021

Conversation

lminiero
Copy link
Member

@lminiero lminiero commented Sep 21, 2021

In case you configured Janus to use a TURN server (which you almost always will NOT want to do!), you may also sometimes want to actually force Janus to use TURN: this is what this patch allows you to do, and can be considered the Janus equivalent of the iceTransportPolicy:"relay" you can use in browsers, to force them to use TURN instead. Enabling it is very easy, since all you need to do is add a force_relay:true attribute to the JSEP object you send to Janus, whether it's an offer or answer.

Notice this only works for libnice >= 0.1.14, as that's the version the property we use was added to. Besides, notice that this WILL cause PeerConnections to fail if: a. you didn't set any TURN server in Janus, b. Janus couldn't get a relay candidate from that server, or c. that candidate can't talk to the peer for any reason.

VERY IMPORTANT: Notice that you should NOT use this if you want USERS connected to Janus to use TURN. For USERS, you use iceTransportPolicy:"relay" on the client side: Janus will automatically talk to the TURN server, and does NOT need to be configured with TURN support itself. Janus ONLY needs TURN support in very specific cases, like when Janus itself is deployed behind a restrictive firewall (e.g., Janus acting as an endpoint in your home), and that's the ONLY time you'll need to actually be aware ths new feature exists.

I wrote this in all caps multiple times as it is a VERY common thing people get wrong all the time (main reason why we have a FAQ item for that), so I pretty much felt I had to repeat it all over again 😜

@danjenkins
Copy link
Contributor

I can confirm this works...

Pass in force_relay within the jsep object in either an offer or an answer and you'll end up selecting a candidate pair with a relay candidate

"selected-pair":"129.203.8.63:55346 [relay,udp] <-> 129.203.104.33:3337 [prflx,udp]"

@lminiero
Copy link
Member Author

Just added a config property to allow/prevent this new functionality to be used in the Janus API: the default is false, meaning that trying to pass force_relay will be ignored and a warning be showed in the logs. If you want to use this feature, allow it globally in janus.jcfg first. A warning is also now printed in the logs at startup when the functionality is allowed, as it may not be something they want.

@danjenkins
Copy link
Contributor

All good with these new changes

Upped my logging to verbose

[547189652986416] Forcing Janus to use a TURN server

"selected-pair":"129.203.11.77:62013 [relay,udp] <-> 129.203.170.33:1139 [prflx,udp]"

@lminiero
Copy link
Member Author

Thanks for the feedback! I'll merge then 👍

@lminiero lminiero merged commit 7587975 into master Sep 27, 2021
@lminiero lminiero deleted the force-relay branch September 27, 2021 08:52
@B-R-Bender
Copy link
Contributor

@lminiero @danjenkins hi guys, can anyone please tell me how to configure janus js in such case?
I want to try to deploy janus itself behind a firewall
and I'm confused a bit
what should I put into server option as server obviously has no public ip or domain name
const janus = new Janus({server: "...?"});
thank you

@lminiero
Copy link
Member Author

lminiero commented Jan 5, 2022

It's explained in the first post.

@B-R-Bender
Copy link
Contributor

I'm sorry Lorenzo, but I can't get it.
I've got my local network, with janus deployed. I've also got coturn installed on a computer with public ip
I've configure janus to use TURN as described here
but I'm really can't understand what to set as a janus server @lminiero

@oej
Copy link
Contributor

oej commented Jan 5, 2022

If you need further support please use the mailing list where many users can help you. Lorenzo is trying to be on holiday...

@B-R-Bender
Copy link
Contributor

yeah, got it
thanks guys anyway and happy new year!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants