This topic provides the basics on what OpenTok is and how it works.
The OpenTok platform includes client libraries available for the web, iOS, and Android, giving developers a full-featured platform to include live, face-to-face video in apps. OpenTok uses WebRTC for audio-video communications. (See our WebRTC FAQ.)
The OpenTok platform is composed of two parts:
The OpenTok API platform is built on three key concepts: streams, connections, and sessions.
Each client usually opens a single connection to a given Session. Through that connection, the client may choose to publish an audio-video stream to the session. Using that same connection, the browser may also subscribe to one, some, or all of the other published audio-video streams available in the session.
The vast majority of functionality is delivered through the OpenTok client-side library. This is executed on the client's browser, iOS app, or Android app. However, for security reasons, the developer's web server needs to get involved when creating new sessions or new tokens.
You can think of an OpenTok session like a virtual video chat room. Connecting to a particular session is like entering a specific room. You need to identify which room you want to enter before you actually enter it. Similarly, you need to specify the session you want to connect to using an OpenTok session ID in order to connect to it.
OpenTok sessions do not expire. However, authentication tokens do (we'll cover Token Creation in the next section).
You can create two different types of sessions — relayed (peer-to-peer) and routed (routed using the OpenTok Media Router). Routed sessions uses the OpenTok Media Router, which provides the following benefits:
For more on session creation and the OpenTok Media Router, see the Session Creation developer guide. This guide includes details on creating sessions using the OpenTok server-side libraries or the OpenTok REST API.
If OpenTok session are analogous to a virtual video chat room, you can think of a token as a key to that room. In the same way that only a valid key can open a specific room, a client connecting to an OpenTok session must provide a corresponding valid token. For security, you generate tokens using one of the OpenTok server SDKs and then pass the token on to the client application.
When a client connects to a session, it must authenticate itself by token. Tokens have expiration dates and they can be assigned roles (such as publisher, subscriber, and moderator) which give them different priviledges within a session.
For details, see the Token creation developer guide.
Use the OpenTok client SDK to connect to (join) an OpenTok session (using the session ID and token provided to the client, using one of the OpenTok server SDKs). When a client connects to the session, the OpenTok client SDK dispatches an event. It also dispatches events when other clients connect to the session.
OpenTok client SDK also includes methods for disconnecting from (leaving) the OpenTok session.
For more details, see the developer guide for Joining a session.
Once the client has connected to the OpenTok session, it can publish a stream that uses the
client's camera and microphone. For example, OpenTok.js includes a
method, which publishes a stream to the session. The client SDKs also include events that
are dispatched when the Publisher starts streaming to the session. These events are dispatched
on each client connected to the session.
When a client publishes a
stream, events are dispatched on all clients connected to the connected to a session.
Upon receiving the event, a client can decide to subscribe to (and display) the stream.
For example, OpenTok.js includes a
Session.subscribe() method, which subscribes
to a stream and displays it in the client's web page.
OpenTok client SDK also includes methods for unpublishing streams and unsubscribing to streams.
The workflows discussed in the previous sections cover the basic set of APIs provided by OpenTok. Aside from these, there are a number of rich features such as Archiving, Signaling, Restrict Frame Rate, and more. Some high level details are below:
To see the complete set of features offered, see the remaining OpenTok developer guides.