Instantiating Audio Service

AloAudio Instantiation Properties

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

AloAudio Class

Once you have defined the properties you instantiate as shown:

const aloAudio = new AloAudio(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 AloAudio you can add event listeners for the events mentioned above.

Sample Instantiation with Event Listeners:

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

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

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

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

    }));
}

Last updated

Logo

© Copyright 2024 ALO.ai, Inc. • All Rights Reserved