Suggestions

close search

Session Creation Overview

When you connect to an OpenTok session on an app, you specify the session you want to connect to using an OpenTok session ID. Each session ID identifies a unique OpenTok session. You can think of a session as a room in which participants meet and chat.

The number of sessions you create and how clients connect to them depend upon the requirements of your app. If your app connects users with one another for a one-time , create a unique session for that meeting. However, if your app connects users over various days in the same "room," then you can create one session and reuse it. If one group of users meet with each other, while other groups meet independently, create unique sessions for each group.

OpenTok sessions do not expire. However, authentication tokens do expire. Also note that sessions cannot explicitly be destroyed.

The OpenTok Media Router and media modes

When you create a session, you specify how clients in the session will send audio-video streams, known as the media mode. There are two options:

Note: In version 2.2 of the OpenTok server SDKs, the default media mode is relayed. (In earlier versions, the default was to use the OpenTok Media Router.)

Best practices when creating sessions

Session ID reuse

When possible, do not reuse session IDs between different video chat conversations. Instead, generate new session IDs for each distinct video chat on your application.

This is important, especially when using OpenTok Inspector. In Inspector, session quality scores and data are indexed by session ID. A session ID that is reused for multiple conversations is more difficult to debug using Inspector, and sessions with re-used session IDs tend to report lower aggregate quality scores than the actual experienced call quality.

Choosing Relayed vs. Routed session type

Use a relayed instead of a routed session, if you have only two participants (or maybe even three) and you are not using archiving. Using relayed sessions reduces the latency between participants, reduces the points of failure and you can get better quality video and audio in most cases.

Routed sessions are required if you want to archive your session. They are recommended if you have more than two or three participants in the session.

For more information, see The OpenTok Media Router and media modes.

Creating sessions

While working on a test version of your app, you can obtain a test session ID using a Project Page of of your TokBox Account.

You can also use one of the the OpenTok server-side libraries or the OpenTok REST API to generate a session:

You can also use the OpenTok REST API to create a session.

If you need to dynamically generate multiple session IDs, use one of the OpenTok server-side libraries or the OpenTok REST API — not the Project Page.