OpenTok JavaScript Library Reference

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

Notes:

  • You can improve the quality and performance of sessions that have only two clients by using peer-to-peer streaming. Peer-to-peer streaming is limited to clients using the OpenTok JavaScript or ActionScript libraries. For more information, see Peer-to-peer streaming.
  • 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 Represents an OpenTok device panel, in which the client can select a microphone and camera.
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.
IssueReportedEvent Dispatched by the TB object when a call to TB.reportIssue() is successful.
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.
ValueEvent Reports the microphone gain or activity level of a publisher.
VolumeEvent Reports the microphone level for a stream the client has subscribed to.

 

OpenTok version numbers

You include the OpenTok JavaScript library in your web page using a <script> tag:

<script src="http://static.opentok.com/v1.1/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):

<script src="https://swww.tokbox.com/v1.1/js/TB.min.js" ></script>

OpenTok version numbers consist of three parts: the major version number, the minor version number, and the revision number. For example, v1.1.4 is major version 1, minor version 1 (of major version 1), and revision 4 (of v1.1). As revision versions are released, changes are included in the root minor revision. For example, when v1.1.4 was released, its changes were included in v1.1.

To reference a specific revision, you can include the complete version number (such as "v1.1.x") in the src attribute. However, we recommend that you specify only the major and minor version numbers. TokBox officially supports the current version (v1.1). If you are loading an older version, we ask that you upgrade to take advantage of the latest bug fixes and features in the OpenTok platform.

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 and REST API

The OpenTok server-side libraries include code for your web server. Use these libraries to create OpenTok session IDs and to create tokens.

The OpenTok REST API lets you create session IDs, create tokens, download archive manifests, download archive videos, and download stitched archive videos.

IRC Live Chat

Have a quick question? Chat with TokBox Support on IRC. Join chat