Session Chat


This guide describes how to use the Chat feature.

Quickstart

After joining a session, chat interfaces are available through the client.getChatClient method:

const chat = client.getChatClient();
chat.sendToAll('hello everyone'); // send message to everyone
chat.send('hello', userId) // send message to someone
client.on('chat-on-message', (payload) => {
  const {
    message,
    sender: {
      name: senderName,
      userId,
    },
    receiver: {
      name: receiverName,
      userId,
    },
    timestamp
  } = payload;
  console.log(`Message: ${message}, from ${senderName} to ${receiverName}`)
})

Send a message

Use the chat.send method to send a chat message to a specific user:

chat.send('hello', userId).then(payload => {
  const {
    message,
    receiver: {
      name,
      userId,
    }
  } = payload;
  console.log(`Message: ${message}, from me to ${name}`)
})

Use chat.sendToAll to send a message to everyone:

chat.sendToAll('hello everyone');

Use the chat-on-message event to receive messages. You will also receive any messages sent by yourself from this event:

client.on('chat-on-message', (payload) => {
  const {
    message,
    sender: {
      name: senderName,
      userId,
    },
    receiver: {
      name: receiverName,
      userId,
    },
    timestamp
  } = payload;
  console.log(`Message: ${message}, from ${senderName} to ${receiverName}`)
})

Chat privileges

During a session, specific privileges are available to restrict chat functions. The following table details privilege values:

Value Description
ChatPrivilege.All Attendee can chat with all users.
ChatPrivilege.NoOne Attendees cannot chat with anyone.
ChatPrivilege.EveryonePublicly Attendees can chat with all users, but not individual users.

Changing privileges

Hosts or managers of the session can change chat privileges of participants using chat.setPrivilege:

import {
  ChatPrivilege
} from '@zoom/videosdk'
chat.setPrivilege(ChatPrivilege.All);

A user can get their current privilege by invoking the method chat.getPrivilege:

const privilege = chat.getPrivilege();
console.log(privilege);

They can also listen to the chat-privilege-change event to get a real-time update of their privilege status:

client.on('chat-privilege-change', payload => {
  console.log(`new privilege: ${payload.chatPrivilege}`);
})