OpenTok: What is the difference between a session and a token?

I am trying to make a video chat for 2 people using the OpenTok API , but I have no clue on how to create sessionIdor tokenwhat the difference is between them.

I reviewed the examples above, but they do not show how to create them. Therefore, I would appreciate if anyone could provide an example with explanations.

+3
source share
2 answers

SessionIDs determine the video chat you want to connect to. Many people can connect and publish video streams in one session. You see and hear other people in the session, based on which video streams your browser subscribes to in this session. Since your application controls who can publish and who subscribes to whom, you can create a large number of video chat topologies in your session (for example, 1: 1, video conferencing, talk shows, security cameras, etc.).

Tokens are a security / authentication mechanism. When you initiate a connection to this session, you must provide the token that was generated using the same credentials that created the session. Tokens do not allow other sites to “knock down a batch” of the session that you created if they manage to access your session.

, , , OpenTok, . , , , .

+7

session ID token:

<?php
    require_once 'SDK/API_Config.php';
    require_once 'SDK/OpenTokSDK.php';

    $apiObj = new OpenTokSDK(API_Config::API_KEY, API_Config::API_SECRET);

    $session = $apiObj->create_session($_SERVER["REMOTE_ADDR"]);

    $sessionId = $session->getSessionId();
    $token = $apiObj->generate_token($sessionId, "moderator");
?>

JS :

<script type="text/javascript">
    var apiKey = <?php echo API_Config::API_KEY; ?> ;
    var sessionId = "<?php echo $sessionId; ?>";
    var token = "<?php echo $token; ?>";

    var session;
    var publisher;
    var subscribers = {};

    session = TB.initSession(sessionId);

    //Video chat event listeners
    session.addEventListener('sessionConnected', sessionConnectedHandler);
    session.addEventListener('streamCreated', streamCreatedHandler);

    session.connect(apiKey, token);
</script>
+2

All Articles