OpenTok JavaScript client library 2.2 preview

At the WebRTC Expo on November 18, we announced some new features. Since then, a number of developers have asked about how to take advantage of them. In response, we are providing a preview version of the OpenTok JavaScript client library: version 2.2. This includes an advanced look at these new features:

  • Archiving—You can record audio-video streams in a session and download the recording as an MP4 file (with H.264 video and AAC audio).
  • Dynamic frame rate control—This feature lets you reduce bandwidth usage of a Subscriber’s video stream. This reduces CPU usage and the network bandwidth consumed, and it lets you subscribe to more streams simultaneously.

These are just a couple of the new features to be included in version 2.2.

If you are a developer, here are some guidelines on testing these new features. Remember, this is a preview version, and the API is subject to change. Also, be sure to read the section on Loading version 2.2 of the JavaScript client library for important information on changes in version 2.2 of the OpenTok JavaScript library.

Archiving

Sign up here to participate in the archiving beta program.

Dynamic frame rate control

To restrict the bandwidth a Subscriber consumes, call the restrictFrameRate() method of the subscriber, passing in true:

mySubscriber.restrictFrameRate(true);

Pass in false and the frame rate of the video stream is not restricted:

mySubscriber.restrictFrameRate(false);

Restricting the bandwidth has the following benefits:

  • It reduces CPU usage
  • It reduces the network bandwidth consumed by the app
  • It lets you subscribe to more streams simultaneously.

When the frame rate is restricted, the Subscriber video frame will update once or less per second.

This feature is only available in sessions that use the OpenTok media server, not in peer-to-peer sessions. In peer-to-peer sessions, calling this method has no effect.

For more information about dynamic frame rate control, see this blog post.

Loading version 2.2 of the JavaScript client library

To use the new features available in version 2.2, set the src attribute of the script tag to load the new library:

<script src="http://static.opentok.com/webrtc/v2.2/js/TB.min.js"></script>

For HTTPS, use the following URL for the src attribute value:

<script src="https://swww.tokbox.com/webrtc/v2.2/js/TB.min.js"></script>

Important: The OpenTok 2.2 JavaScript library includes changes that are not backward compatible with OpenTok 2.0:

  • The sessionConnected event dispatched by the Session object — The streams and connections properties are deprecated (and these are now empty arrays). For streams and connections in the session when you connect, the Session object dispatches individual streamCreated and connectionCreated events (for each stream and connection). However, the Session object does not dispatch a connectionCreated event for the client’s own connection. For the client’s own connection, the Session object dispatches a sessionConnected event only.
  • The streamCreated event dispatched by the Session object — The Session object dispatches the streamCreated event for streams published by other clients only. The event includes a new property: stream (a Stream object corresponding to the new stream). The streams property is deprecated.
  • The streamCreated event dispatched by the Publisher object — The Publisher dispatches the streamCreated event for the stream published by the Publisher object. The stream property of the event is a reference to the Stream object.
  • The connectionCreated event dispatched by the Session object — The ConnectionCreatedEvent class now has a connection property, and the connections property is deprecated. The Session object now dispatches the connectionCreated event for each connection added to the session, including other clients’ connections that exist when you first connect.
  • The connectionDestroyed event dispatched by the Session object — The ConnectionDestroyedEvent class now has a connection property, and the connections property is deprecated. The Session object now dispatches the connectionDestroyed event for each connection that leaves the session while your client is connected.
  • The streamDestroyed event dispatched by the Session object — The Session object dispatches the streamDestroyed event for destroyed streams from other clients only. The event includes a new property: stream (a Stream object corresponding to the destroyed stream). The streams property is deprecated.
  • The streamDestroyed event dispatched by the Publisher object — The Publisher dispatches the streamDestroyed event when the stream published by the Publisher object is destroyed. The stream property is a reference to the Stream object. The default behavior of this event is to remove the Publisher from the HTML DOM. You can cancel the default behavior by calling the preventDefault() method of the event object.
  • The sessionDisconnected event dispatched by the Session object — Calling the preventDefault() method no longer causes a Publisher to be preserved. The Publisher is destroyed by default when the Publisher dispatches the streamDestroyed event. (You can preserve the Publisher by calling the preventDefault() method of the streamDestroyed event dispatched by the Publisher object.)
  • In the Session.signal() method, the optional to property of the signal parameter takes a single Connection object (defining the connection to which the signal will be sent). The to property does not take an array of Connection objects, like it did in version 2.0 of the JavaScript library.
  • Jake Tomson

    Any near plans to port WebRTC to iOS phonegap?