Suggestions

close search

SessionDisconnectEvent

Properties Methods 

The Session object dispatches SessionDisconnectEvent object when a session has disconnected. This event may be dispatched asynchronously in response to a successful call to the disconnect() method of the session object.

Example

The following code initializes a session and sets up an event listener for when a session is disconnected.

var apiKey = ""; // Replace with your API key. See https://tokbox.com/account
 var sessionID = ""; // Replace with your own session ID.
                     // See https://tokbox.com/developer/guides/create-session/
 var token = ""; // Replace with a generated token that has been assigned the moderator role.
                 // See https://tokbox.com/developer/guides/create-token/

 var session = OT.initSession(apiKey, sessionID);
 session.on("sessionDisconnected", function(event) {
     alert("The session disconnected. " + event.reason);
 });
 session.connect(token);

Properties

Name Type Description
reason String A description of why the session disconnected. This property can have the following values:

  • "clientDisconnected" — A client disconnected from the session by calling the disconnect() method of the Session object or by closing the browser. ( See Session.disconnect().)
  • "forceDisconnected" — A moderator has disconnected you from the session by calling the forceDisconnect() method of the Session object. (See Session.forceDisconnect().)
  • "networkDisconnected" — The network connection terminated abruptly (for example, the client lost its internet connection).

    Prior to dispatching a sessionDisconnected event for this reason, the Session object dispatches a reconnecting event, and the client attempts to reconnect to the OpenTok session. If the reconnection fails, the Session object dispatches a sessionDisconnected event with the reason property set to "networkDisconnected".

    Methods

    Name Description
    isDefaultPrevented() → {Boolean} Whether the default event behavior has been prevented via a call to preventDefault() (true) or not (false).
    preventDefault() Prevents the default behavior associated with the event from taking place.

    isDefaultPrevented() → {Boolean}

    Whether the default event behavior has been prevented via a call to preventDefault() (true) or not (false). See preventDefault().
    Returns:

    preventDefault()

    Prevents the default behavior associated with the event from taking place.

    For the sessionDisconnectEvent, the default behavior is that all Subscriber objects are unsubscribed and removed from the HTML DOM. Each Subscriber object dispatches a destroyed event when the element is removed from the HTML DOM. If you call the preventDefault() method in the event listener for the sessionDisconnect event, the default behavior is prevented, and you can, optionally, clean up Subscriber objects using your own code).

    To see whether an event has a default behavior, check the cancelable property of the event object.

    Call the preventDefault() method in the event listener function for the event.