When you connect to a TokBox session on an app, you specify the session you want to connect to using a TokBox session ID.
OpenTok sessions do not expire. However, authentication tokens do expire. (See Connection Token Creation.) Also note that sessions cannot explicitly be destroyed.
While working on a test version of your app, you can obtain a test session ID using the Dashboard page.
You can include the following advanced settings:
Click the Generate Session button. The form displays a new session ID.
You can also use the OpenTok server-side libraries to create session IDs while testing. See the next section.
You can create an OpenTok session using one of the OpenTok server-side libraries, which are available for Java, PHP, Python, and Ruby. Each server-side library includes an OpenTokSDK object. While each of these libraries may slightly differ, the basic concept remains the same. Alternatively, the developer can POST a request directly to the specified OpenTok API URL, as described at the end of this section.
In order to create a session, an OpenTokSDK object is created by passing in the
API key and the partner secret. You can invoke the API to create a session by
create_session() method of the OpenTokSDK object.
This returns an OpenTokSession object of the format described below.
Here is a simple example in PHP:
<?php require_once 'API_Config.php'; require_once 'OpenTokSDK.php'; $apiObj = new OpenTokSDK(API_Config::API_KEY, API_Config::API_SECRET); $session = $apiObj->create_session(); echo $session->getSessionId(); ?>
This creates a new session, situating it in TokBox's global network near the IP as specified by
create_session method that generates a Session object. This
object includes a
session_id property, which is the session ID for the
method of the Session object (to connect a user to an OpenTok session).
Although this example is written in PHP, the other OpenTok server-side libraries
(for Java, Python, and Ruby) work in the same way. They each define an OpenTokSDK
object, which includes a
create_session() method. This method has two
location(String) An IP address that TokBox will use to situate the session in its global network. Ideally, this IP address should be representative of the geographical locations of the participants in the session. If you have access to the IP address of the first participant in the session, use that address.
properties(Object) Optional. An object used to enable peer-to-peer streaming in sessions. For details, see Peer-to-Peer Streaming and OpenTok server-side libraries documentation.
Next workflow step: Connection Token Creation.