Have you explored the newest version of the OpenTok platform? Check out OpenTok 2.0, built on top of WebRTC. Learn more

Connection class

The Connection object represents a connection to a TokBox session. The Session object has a connection property that is a Connection object. It represents the local user's connection. The Stream object has a connection property that is a Connection object. It represents the stream publisher's connection.

To initialize a session, call the TB.initSession() method, which returns the Session object. Then call the connect() method of the Session object to connect to a session. The Session object dispatches a sessionConnected event when the connection is made. For a code example, see SessionConnectEvent.

Connection properties

The Connection object has the following properties:

connectionId (String) — The ID of this connection.

creationTime (Number) — The timestamp for the creation of the connection. This value is calculated in milliseconds. You can convert this value to a Date object by calling new Date(creationTime), where creationTime is the creationTime property of the Connection object.

data (String) — A string containing metadata describing the connection. When you generate a user token string pass the connection data string to the generate_token() method of the OpenTok server-side libraries. You can also generate a token and define connection data on the Dashboard page.

quality — Includes information about the downstream bandwidth, the upstream bandwidth, and the latency of the connection at the time the connection is established. This information can help you to handle different network conditions (such as connections from mobile devices and on other low-bandwidth connections).

The quality object includes the following properties:

  • downBandwidth (Number) — The downstream bandwidth, in kilobits per second. This is the number of kilobits that can received from the OpenTok server each second. Each subscribed audio-video stream requires from 150 to 200 kbps.
  • latency (Number) — The latency of the connection to the OpenTok server, in milliseconds.
  • upBandwidth (Number) — The upstream bandwidth, in kilobits per second. This is the number of kilobits that can be sent to the OpenTok server each second. Each published audio-video stream requires from 150 to 200 kbps.

The quality property is set only if you set the detectConnectionQuality property to 1 in the object you pass as the properties parameter of the connect() method of the Session object.

IRC Live Chat

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