Search code examples
javascriptphpapiopentoktokbox

OpenTok: What's the difference between the session and the token?


I'm trying to make a 2 persons video chat using OpenTok API, but I don't have a clue on how to generate a sessionId or a token and what's the difference between them.

I've looked into the provided examples, but they don't show how to generate them. So I would appreciate if someone could provide an example with explanations.


Solution

  • SessionIDs identify the video chat that you want to connect to. Many people can connect and publish video streams to the same session. You see and hear other people in a session based on which video streams your browser subscribes to in that session. Because your application controls who can publish and who subscribes to whom, you can create a wide variety of video chat topologies in your session (eg. 1:1, video conference, talk show, security cam, etc.).

    Tokens are a security/authentication mechanism. When you initiate a connection to a given session, you must provide a token that was generated using the same credentials that created the session. Tokens prevent other sites from "party crashing" a session that you have created, if they manage to get their hands on your sessionId.

    Furthermore, when you generate a token, you can imbue it with a role, which tells the OpenTok infrastructure what types of actions to allow. For instance, you can decide to give a particular connection moderation rights by initiating that connection with a token that has the moderator role.