imperiumsage
imperiumsage

Reputation: 71

Can network traversal service tokens be shared among the peers in a multi user WebRTC session

I have been going back and forth on this with a twilio support engineer, and I'm not sure if they understand my question completely. I'm hoping an evangelist/someone who has used the network traversal service in a production WebRTC application can help.

I have a lambda microservice that requests a twilio network traversal token (twilio resource: tokens) using the twilio-node client library. I want to minimize the number of tokens in the wild, and am planning to have an initiator, at the start of the webrtc session, request the token via the lambda service, then send the token out of band to the other clients who will be participating in the webrtc session.

On the next call, the initiator will check if the token is still active, and if so will use the same token, else will request a new token.

Is this something I can do? Or will every client participating in the same webrtc session require its own set of tokens?

Upvotes: 1

Views: 307

Answers (2)

Megan Speir
Megan Speir

Reputation: 3811

As zembla points out, there is nothing to prevent you from having multiple users from sharing NTS tokens. But I think while our support team has also advised while you "can" do this you probably "shouldn't".

If the concern is the number of tokens, consider setting a lower ttl (“time to live”: the duration where that token is valid) on the tokens: https://www.twilio.com/docs/api/rest/token#instance-properties

This example in Node keeps a token for only 1 hour:

client.tokens.create({
    "ttl": 3600
}, function(err, token) {
    process.stdout.write(token.username);
});

You can adjust the time as you see fit. It seems as though this would solve your concerns for minimizing the number of tokens. Please let me know if this helps.

Upvotes: 1

zembla
zembla

Reputation: 21

Twilio NTS tokens are tied to the account, not a user; there's nothing to prevent multiple users from sharing an NTS token as long as the token is still valid when the user consumes it.

Upvotes: 2

Related Questions