Skip to main content
Version: 0.4.0

LiveSwitch Integration

This guide shows how to combine a LiveSwitch Voice Call with the atmoky WebSDK to spatialize the audio streams of the remote participants. Make sure you've read Basic Setup which explains the functions which will be called down below.

Integration

The following code adjusts the example implementation from the LiveSwitch Quickstart: JavaScript guide in order to retrieve the MediaStreamTrack from the remote participants media stream.

// ... //MediaStreamingLogic.prototype.openSfuDownstreamConnection = function (  remoteConnectionInfo) {  // Create remote media.  const remoteMedia = new fm.liveswitch.RemoteMedia();  const audioStream = new fm.liveswitch.AudioStream(remoteMedia);  const videoStream = new fm.liveswitch.VideoStream(remoteMedia);  // Add remote media to the layout.  this.layoutManager.addRemoteMedia(remoteMedia);  // Create a SFU downstream connection with remote audio and video.  const connection = this.channel.createSfuDownstreamConnection(    remoteConnectionInfo,    audioStream,    videoStream  );  // Store the downstream connection.  this.downstreamConnections[connection.getId()] = connection;  connection.addOnStateChange((conn) => {    fm.liveswitch.Log.debug(      `Downstream connection is ${new fm.liveswitch.ConnectionStateWrapper(        conn.getState()      ).toString()}.`    );    if (conn.getState() == liveswitch.ConnectionState.Connected) {      // set volume to zero as it would bypass the renderer      remoteMedia.setAudioVolume(0);      const userID = remoteConnectionInfo.getUserId();      let stream = remoteMedia._getInternal()._getAudioMediaStream();      addParticipantSource(user.uid, stream.getAudioTracks()[0]);    }    // Remove the remote media from the layout and destroy it if the remote is closed.    if (conn.getRemoteClosed()) {      delete this.downstreamConnections[connection.getId()];      this.layoutManager.removeRemoteMedia(remoteMedia);      remoteMedia.destroy();      const userID = remoteConnectionInfo.getUserId();      removeParticpantSource(userID);    }  });  connection.open();  return connection;};// ... //