Chat

Chat is is designed to support in-session text communication. Zoom truncates messages exceeding a binary size of 10,000 bytes. As a best practice, we recommend a limit of 1000 characters per message.

While in a session, users can send chat messages to other users in the session.

The following two main components within the SDK will help you implement in-session message features:

  • The onChatNewMessageNotify callback is triggered when a new message is sent or received. This callback confirms the delivery of the message.
  • An instance of ZoomVideoSDKChatHelper provides methods that can be used to send and receive messages in a session running on your app.

Note: Common chat implementations in Android utilize RecyclerViews to display messages. This documentation will only cover how to obtain information from the ZoomVideoSDK Chat API. If you would like to use this API with RecyclerViews, see RecyclerViews in Android.

Send chat messages

There are two different forms of chat in a session: public and private. A private message is sent to a specific user in the session and a public message is sent to all users present in the session.

Before sending a private message to a specific user, you must verify that private chat is enabled in your session and obtain the user you would like to send the message to.

  1. Obtain an instance of the ZoomVideoSDKChatHelper object.

    val chatHelper = ZoomVideoSDK.getInstance().chatHelper
    
    ZoomVideoSDKChatHelper chatHelper = ZoomVideoSDK.getInstance().getChatHelper();
    
  2. Check if chat is disabled prior to setting up chat-related components.

    chatHelper.isChatDisabled
    
    chatHelper.isChatDisabled();
    
  3. Send a private chat message

    if (chatHelper.isPrivateChatDisabled) {
        // You cannot send user-specific messages
    } else {
        chatHelper.sendChatToUser(user, "This is a private message")
    }
    
    if (chatHelper.isPrivateChatDisabled()) {
        // You cannot send user-specific messages
    } else {
        chatHelper.sendChatToUser(user, "This is a private message");
    }
    
  4. Send a public chat message

    chatHelper.sendChatToAll("This is a public message")
    
    chatHelper.sendChatToAll("This is a public message");
    

Receive chat messages

Whenever a chat message is received, the most important pieces of data to make note of are the sender and the content of the message.

You can use this information to display the sender information such as the user name and content of the message to the message recipient(s) in your UI.

  1. Get notified when a chat message is received

    override fun onChatNewMessageNotify(chatHelper: ZoomVideoSDKChatHelper?, messageItem: ZoomVideoSDKChatMessage) {
        val content = messageItem.content
        val sender = messageItem.senderUser
        val senderName = sender.userName
    }
    
    @Override
    public void onChatNewMessageNotify(ZoomVideoSDKChatHelper chatHelper, ZoomVideoSDKChatMessage messageItem) {
        String content = messageItem.getContent();
        ZoomVideoSDKUser sender = messageItem.getSenderUser();
        String senderName = sender.getUserName();
    }
    

For more information on how to use the ZoomVideoSDKUserInfo object, see Sessions.

More details

You can find out more details about chats using ZoomVideoSDKChatMessage:

messageItem.isChatToAll // Returns false for private messages
messageItem.isSelfSend // Returns true if current user sent the message
messageItem.timeStamp // The time at which the message was sent
messageItem.receiverUser // The recipient for a private message
messageItem.isChatToAll(); // Returns false for private messages
messageItem.isSelfSend(); // Returns true if current user sent the message
messageItem.getTimeStamp(); // The time at which the message was sent
messageItem.getReceiverUser(); // The recipient for a private message

Callbacks

The following is an example of a chat callback.

Get notified when a message is posted

override fun onChatNewMessageNotify(chatHelper: ZoomVideoSDKChatHelper?, messageItem: ZoomVideoSDKChatMessage) {
    val content = messageItem.content
    val sender = messageItem.senderUser
}
@Override
public void onChatNewMessageNotify(ZoomVideoSDKChatHelper chatHelper, ZoomVideoSDKChatMessage messageItem) {
    String content = messageItem.getContent();
    ZoomVideoSDKUser sender = messageItem.getSenderUser();
}

Send files in chat

Users can transfer files in chat during the session.

Zoom deletes files sent via in-session chat when the session ends.

Enable send files via in-session chat in your Video SDK account portal settings and configure the following settings.

  • Only allow specified file types - Select to allow only specific file types and enter the file extensions in the text box, separated by commas.
  • Maximum file size - Select to limit the file size to 2048 MB.

Check if the file transfer feature is enabled.

if (ZoomVideoSDK.getInstance().session.isFileTransferEnable) {
    // File Transfer is enabled.
}

Get the list of allowed file types that you can transfer.

ZoomVideoSDK.getInstance().session.transferFileTypeWhiteList

Get the maximum file size to transfer.

ZoomVideoSDK.getInstance().session.maxTransferFileSize

Send files to all users in the current session.

val error = ZoomVideoSDK.getInstance().session.transferFile("filePath")
if (error == 0) {
    // Transfer successfully
} else {
    // Failed to transfer
}

Send files to a certain user in the session.

// Get the user you want to send file to
val userToReceiveFile: ZoomVideoSDKUser
val error = userToReceiveFile.transferFile("filePath")
if (error == 0) {
    // Transfer successfully
} else {
    // Failed to transfer
}

Cancel sending files.

// onSendFileStatus under ZoomVideoSDKDelegate
if (file != null && status != null && status == ZoomVideoSDKFileTransferStatus.FileTransferState_TransferDone) {
    val error = file.cancelSend()
}

Start receiving files.

// onReceiveFileStatus under ZoomVideoSDKDelegate
override fun onReceiveFileStatus(
    file: ZoomVideoSDKReceiveFile?,
    status: ZoomVideoSDKFileTransferStatus?
) {
    if (file != null && status != null) {
        val error = file.startReceive("filePath")
    }
}

Cancel receiving files.

// onReceiveFileStatus under ZoomVideoSDKDelegate
override fun onReceiveFileStatus(
    file: ZoomVideoSDKReceiveFile?,
    status: ZoomVideoSDKFileTransferStatus?
) {
    if (file != null && status != null) {
        val error = file.cancelReceive()
    }
}

File transfer callbacks

Be sure that you listen for callback events to receive file transfer callbacks.

Get notified when you transfer a file.

override fun onSendFileStatus(
    file: ZoomVideoSDKSendFile?,
    status: ZoomVideoSDKFileTransferStatus?
) {
}

Get notified when you receive a file from other users.

 override fun onReceiveFileStatus(
    file: ZoomVideoSDKReceiveFile?,
    status: ZoomVideoSDKFileTransferStatus?
) {
}