OpenTok JavaScript Library Reference

The OpenTok API reference details the OpenTok JavaScript library and the OpenTok server-side libraries.

Note: Flash app developers should consult the OpenTok ActionScript API reference.

OpenTok JavaScript library

The OpenTok JavaScript library consists of the following classes.

Class Description
Archive Used to record and playback sessions and streams.
ArchiveEvent Dispatched by the Session object when an archive is created, closed, or loaded; when an archive recording starts or stops; or when an archive starts or stops playing back.
Camera Specifies a camera on the client machine.
Capabilities Defines the capabilities property of the Session class.
ChangeFailedEvent Dispatched by an Archive object when a call to the set() method fails.
Connection Represents a connection to an OpenTok session.
ConnectionEvent Dispatched by the Session object when another user connects or disconnects from a session.
DeviceEvent Dispatched by the DevicePanel object when the user selects a camera or microphone in the device panel.
DeviceManager Lets you select the camera and microphone to use for a publisher stream.
DevicePanel Dispatched by the DevicePanel object when the user selects a device in the device panel.
DeviceStatusEvent Dispatched by the DeviceManager object in a response to calling the detectDevices() method.
ExceptionEvent Dispatched by the TB object when the OpenTok API encounters an exception.
Event Defines the basic OpenTok event object that is passed to event listeners.
Microphone Specifies a microphone on the client machine.
Player Lets you individually play back stand-alone archives.
Publisher Provides the mechanism through which control of the published stream is accomplished.
Recorder Lets you record stand-alone archives.
RecorderManager Manages recording and playing back of stand-alone archives.
ResizeEvent Dispatched by a Publisher object when a publisher div must resize to display the Flash Player Settings dialog box.
Session Represents an OpenTok session and provides access to much of the OpenTok functionality.
SessionConnectEvent Dispatched by the Session object on the connecting page when the session has successfully connected.
SessionDisconnectEvent Dispatched by the Session object when a session has disconnected.
SignalEvent Dispatched by the Session object when any subscribed session sends a signal.
StateChangedEvent Dispatched by an Archive object when a call to the set() method succeeds.
StateManager Lets you work with the state of a session or archive. You can add event listeners for changes to state data. For sessions, you can also set state data.
Stream Provides information about an audio-video stream.
StreamEvent The Session object dispatches StreamEvent events when a session has a stream created or destroyed.
StreamPropertyChangedEvent The Session object dispatches StreamPropertyChangedEvent events when a publisher starts or stops publishing audio or video.
Subscriber Provides the mechanism through which control of a subscribed stream is accomplished.
TB Lets you initialize the OpenTok API, set up error logging, and set up exception event handling.
VolumeEvent Reports the microphone level for a stream the client has subscribed to.

 

OpenTok version numbers

You include the OpenTok in your web page using a <script> tag.

When you are developing your app, load the script from the OpenTok staging server:

<script src="http://staging.tokbox.com/v0.91/js/TB.min.js"></script>

When you are ready to deliver a production version of your app, load the script from the following location:

<script src="http://static.opentok.com/v0.91/js/TB.min.js"></script>

If your page loads via HTTPS, be sure to load the OpenTok JavaScript library via HTTPS (otherwise the browser will display a warning to the user):

  • In staging:
    <script src="https://staging.tokbox.com/v0.91/js/TB.min.js" ></script>
  • In production:
    <script src="https://swww.tokbox.com/v0.91/js/TB.min.js" ></script>

Note: You can load a specific version of the OpenTok API by modifying the version number (such as "v0.90.1") in the src attribute.

OpenTok version numbers consist of three parts: the major version number, the minor version number, and the revision number. For example, v0.91.17 is major version 0, minor version 91 (of major version 0), and revision 17 (of v0.91). As revision versions are released, changes are included in the root minor revision. For example, when v0.91.17 was released, its changes were included in v0.91. To reference a specific revision, you can include the complete version number in the src attribute. However, we recommend that you specify only the major and minor version numbers. Specify a revision number only if you need to use a specific older revision.

Important: Always use the libraries we provide unmodified. This ensures that you use the latest up-to-date, tested code. TokBox does not support the use of modified libraries.

For more information on specific versions of the API, see the OpenTok API release notes. To learn when new versions of the OpenTok API become available, join the the TokBox Announcements forum.

OpenTok server-side libraries

The OpenTok server-side libraries include code for your web server. Use these libraries to obtain OpenTok session IDs and to obtain validation tokens for individual users.

IRC Live Chat

Have a quick question? Chat with other developers.  Join chat

TokBox staff may not be online right now. To reach them during off-hours, visit the forums.