Command channel

The command channel is a ready-to-use, flexible real-time service through which you can send data to other users in the current session. Commands can be sent directly to specific users or to the session as a whole. It can be used to:

  • send real-time reactions to live content
  • conduct live surveys and polls during video sessions
  • share access to client-side settings of one participant to another participants's client

At a high level, this functions similarly to chat messages, you provide a receiver and the command you would like to send as a string. The receiver can be a specific user, signified by ZoomVideoSDKUser, or you can leave it empty to broadcast to everyone.

Using a distinct service for commands instead of sending them through chat allows for better separation of concerns in your implementation and reduces the likelihood of encountering bugs.

The maximum size is 512 characters and the rate limit is 2 commands per second per session. If you require a higher command frequency, contact Developer Support to request an increase.

Command channel is not designed for high frequency commands broadcasting, and high command frequencies may impact the session experience. To maintain optimal session performance, some commands may be dropped under heavy load. If your application requires high availability, high frequency, and N-to-N broadcast topology, we recommend deploying a dedicated signaling service for your app.

Get instance

To use the command channel, you will first need to get an instance of the ZoomVideoSDKCmdChannel object.

let commandChannel = ZoomVideoSDK.shareInstance()?.getCmdChannel()

Wait to become active

You must wait for the session's command channel to become active, indicated by the onCommandChannelConnectResult callback.

func onCmdChannelConnectResult(_ success: Bool) {
    if (success) {
        // Command channel is ready for use
    }
}

Send commands

Once the command channel has connected, you can send commands through the sendCommand method.

// Send command to a specific user
commandChannel?.sendCommand("raise_hand", receive: user)
// Send command to the whole session
commandChannel?.sendCommand("lower_all_hands", receive: nil)

Receive callback

After a command is sent, any SDK instance receiving the command should see the onCommandReceived callback.

func onCommandReceived(_ commandContent: String?, send sendUser: ZoomVideoSDKUser?) {
    // Respond to the command here
}