Instantiating Video Service

AloVideo Properties

In order to instantiate the AloVideo object you are required to provide a number of properties. See Class Instantiation Properties

AloVideo Class

Once you have defined the properties you instantiate as shown:

aloVideo = new AloVideo(props);

Connection Events

Once instantiated, and connected to a channel, the user will be connected to the AloAudio Service. There are a number of event fire that are related to this connection:

After you instantiate AloVideo you can add event listeners for the events mentioned above.

Sample Instantiation with Event Listeners

function connectToVideo() {    
    const user = new VideoUser (
      "12345",
      {        
        name: "James Jones",
        deviceId: "abcd-efsg-wqer-qewe"
      }
    );
    const props = {
      user: user,
      userAuthToken: "token generated from Authentication Service"
    };
    aloVideo = new AloVideo(props);
    initializeEventListeners();
}

function initializeEventListeners() {
    aloVideo.events.addEventListener('onDisconnect', e => {
      console.log("onDisconnect:", e.detail);
    })

    aloVideo.events.addEventListener('onConnectionChange', action(e => {
      console.log("onConnectionChange:", e.detail);

      switch (e.detail.state) {
        case aloVideo.CONNECTION_STATUS_CONNECTED:
          console.log("Ālo video connected");
          break;
        case aloVideo.CONNECTION_STATUS_DISCONNECTED:
          console.log("Ālo video disconnected");
          break;
        case aloVideo.CONNECTION_STATUS_ERROR:
          console.log("Ālo video connection error", e.detail);
          break;
        case aloVideo.CONNECTION_STATUS_CONNECTING:
          console.log("Ālo video connecting");
          break;
        case aloVideo.CONNECTION_STATUS_RECONNECT_PENDING:
          console.log(
            "Ālo video reconnect pending.  Retrying in ", 
            e.detail.pendingRestartSeconds
          );
          break;
      }

    }));
}

Sample onConnectionChange Payloads

{
 detail: {state: "ACQUIRING_ACCESS"}
}

{
 detail: {state: "CONNECTING"}
}

{
 detail: {
  state: "CONNECTED",
  user: {...}
 }
}

{
 detail: {
  state: "DISCONNECTED",
  user: {...}
 }
}

{
 detail: {
  state: "ERROR",
  message: "Lost connection to the server",
  user: {...}
 }
}

Last updated