NEWDolby Interactivity APIs are now the Dolby.io Communications APIs Learn More >
X

CommandService JavaScript Web Example

Sample implementation for JavaScript (Web) of the CommandService for multiple participants to move avatars across the screen.

Overview

Users can use arrow keys to move their avatar around the screen. Position of avatar is communicated to other users in real time utilizing Dolby.io Communications API's CommandService.

Features Tech Stack
  • JavaScript

Key concepts

To send a command to all participants in a session, call the send() method of the Command object.

VoxeetSDK.command
  .send({payload: 'hello world'})
  .catch((err) => {
    console.error(err);
  });

To receive commands send in a session, add an event listener for the 'received' event dispatched by the Command object.

VoxeetSDK.command.on('received', (participant, message) => {
  const dataParsed = JSON.parse(message);
  console.log("Command received, message:", dataParsed.payload)
}

Did this page help you?