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 each other.

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

  • An instance of ZMVideoSDKChatHelper provides methods that can be used to send and receive messages in a session running on your app.
  • The onChatNewMessageNotify callback from your ZMVideoSDKDelegate confirms the delivery of a message.

Send chat messages

Users can send a message privately to a single user or publicly to the entire session.

Send a private chat message

// Get the ZMVideoSDKChatHelper to perform chat actions.
if let chatHelper = ZMVideoSDK.shared()?.getChatHelper() {
    // Check if chat is enabled in this session.
    if chatHelper.isChatDisabled() == false, chatHelper.isPrivateChatDisabled() == false {
        // Send message to User.
        chatHelper.sendChat(to: user, content: message)
    }
}
// Get the ZMVideoSDKChatHelper to perform chat actions.
ZMVideoSDKChatHelper *chatHelper = [[ZMVideoSDK sharedZMVideoSDK] getChatHelper];
// Check if chat is enabled in this session.
if ([chatHelper IsChatDisabled] == NO && [chatHelper IsPrivateChatDisabled] == NO) {
    // Send message to User.
    [chatHelper SendChatToUser:user Content:message];
}

Send a public chat message to all users in a session

// Get the ZMVideoSDKChatHelper to perform chat actions.
if let chatHelper = ZMVideoSDK.shared()?.getChatHelper() {
    // Check if chat is enabled in this session.
    if chatHelper.isChatDisabled() == false{
        // Send message to all users in this session.
        chatHelper.sendChat(toAll: message)
    }
}
// Get the ZMVideoSDKChatHelper to perform chat actions.
ZMVideoSDKChatHelper *chatHelper = [[ZMVideoSDK sharedZMVideoSDK] getChatHelper];
// Check if chat is enabled in this session.
if ([chatHelper IsChatDisabled] == NO) {
    // Send message to all users in this session.
    [chatHelper SendChatToAll:message];
}

Receive chat messages

To be notified when a message is received use onChatNewMessageNotify within ZMVideoSDKDelegate. The parameter chatMessage contains information about the message including an ZMVideoSDKUser info object for both the sender and recipient (if applicable).

func onChatNewMessageNotify(_ helper: ZMVideoSDKChatHelper!, message chatMessage: ZMVideoSDKChatMessage!) {
    // Use helper to perform chat actions.
    // Message contains the info about a chat message.
    if let content = chatMessage.content, let senderName = chatMessage.sendUser.getName() {
        print("\(senderName) sent a message: \(content)")
    }
}
- (void)onChatNewMessageNotify:(ZMVideoSDKChatHelper *)helper message:(ZMVideoSDKChatMessage *)chatMessage {
    // Use helper to perform chat actions.
    // Message contains the info about a chat message.
    NSString *content = chatMessage.content;
    VideoSDKUser *sender = chatMessage.sendUser;
    NSLog(@"%@ sent a message: %@", [sender getName], content);
}

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

Chat message details

Here are some additional considerations to make note of while using ZMVideoSDKChatMessage:

let isChatToAll = chatMessage.isChatToAll // Returns false for private messages.
let currentUserIsSender = chatMessage.isSelfSend // Returns true if the current user sent the message.
let timeMessageWasSent = chatMessage.timeStamp // The time at which the message was sent.
let recipient = chatMessage.receiverUser // The recipient of a private message.
chatMessage.isChatToAll; // Returns false for private messages.
chatMessage.isSelfSend; // Returns true if the current user sent the message.
chatMessage.timeStamp; // The time at which the message was sent.
chatMessage.receiverUser; // The recipient of a private message.

Callbacks

The following is an example of a chat callback.

Get notified when a message is delivered

func onChatNewMessageNotify(_ chatHelper: ZMVideoSDKChatHelper!, chatMessage: ZMVideoSDKChatMessage!) {
    // Use helper to perform chat actions.
    // Message contains the info about a chat message.
    if let content = chatMessage.content, let senderName = chatMessage.sendUser.getName() {
        print("\(senderName) sent a message: \(content)")
    }
}
- (void)onChatNewMessageNotify:(ZMVideoSDKChatHelper*)chatHelper chatMessage:(ZMVideoSDKChatMessage*)chatMessage {
    // Use helper to perform chat actions.
    // Message contains the info about a chat message.
    NSString *content = chatMessage.content;
    ZMVideoSDKUser *sender = [chatMessage getSendUser];
    NSLog(@"%@ sent a message: %@", sender.getUserName, content);
}

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.

let ret = ZMVideoSDK.shared().getSessionInfo().isFileTransferEnabled()
BOOL ret =  [[[ZMVideoSDK sharedVideoSDK] getSessionInfo] isFileTransferEnabled];

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

let ret = ZMVideoSDK.shared().getSessionInfo().getTransferFileTypeWhiteList()
NSString *ret =  [[[ZMVideoSDK sharedVideoSDK] getSessionInfo] getTransferFileTypeWhiteList];

Get the maximum file size to transfer.

let ret = ZMVideoSDK.shared().getSessionInfo().getMaxTransferFileSize()
unsigned long long  ret =  [[[ZMVideoSDK sharedVideoSDK] getSessionInfo] getMaxTransferFileSize];

Send files to all users in the current session.

let ret = ZMVideoSDK.shared().getSessionInfo().transferFile(filePath: String)
ZMVideoSDKErrors ret =  [[[ZMVideoSDK sharedVideoSDK] getSessionInfo] transferFile:self.filePathTextF.stringValue];

Send files to a certain user in the session.

// Locate the user that you will like to send the file to
let receiver: ZMVideoSDKUser
// Send file directly
let ret = receiver.transferFile(filePath: String)
ZMVideoSDKErrors ret =  [_receiverUser transferFile:self.filePathTextF.stringValue];

Cancel sending files.

// getCurrentSendFileObj is a user-defined method, to retrieve the sending file.
let sendFile: ZMVideoSDKSendFile = getCurrentSendFileObj()
let ret = sendFile.cancelSend()
ZMVideoSDKSendFile *send = [self getCurrentSendFileObj]; // getCurrentSendFileObj is a user-defined method, to retrieve the sending file.
ZMVideoSDKErrors ret =  [send cancelSend];

Start receiving files.

// getCurrentReceiveFileObj is a user-defined method, to retrieve the receiving file.
let receiveFile: ZMVideoSDKReceiveFile = getCurrentReceiveFileObj()
let fileDomain = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).map(\.path).last
let filePath = "<File path to receive>"
let downloadFilePath = "\(fileDomain)/\(filePath.count > 0 ? filePath : receiveFile.fileName)"
if (receiveFile) {
  let ret = receiveFile.startReceive(downloadFilePath)
  }
ZMVideoSDKReceiveFile *receive = [self getCurrentReceiveFileObj]; //getCurrentReceiveFileObj is a user-defined method, to retrieve the receiving  file.
NSString *fileDomain = [NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES).lastObject copy];
NSString *filePath = @"<File path to receive>";
NSString *downloadFilePath = [NSString stringWithFormat:@"%@/%@",fileDomain,filePath.length>0?filePath:receive.fileName];
if (receive) {
  ZMVideoSDKErrors ret =  [receive startReceive:downloadFilePath];
  } else {
    NSLog(@"receive is null");
  }

Cancel receiving files.

// getCurrentReceiveFileObj is a user-defined method, to retrieve the receiving file.
let receiveFile: ZMVideoSDKReceiveFile = getCurrentReceiveFileObj()
let downloadPath = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).map(\.path).last
if (receiveFile) {
  let ret = receiveFile.cancelReceive()
  }
ZMVideoSDKReceiveFile *receive = [self getCurrentReceiveFileObj]; // getCurrentReceiveFileObj is a user-defined method, to retrieve the receiving  file.
  if (receive) {
    ZMVideoSDKErrors ret =  [receive cancelReceive];
  } else {
    NSLog(@"receive is null");
  }

File transfer callbacks

Be sure that you have set up a delegate for callback events to receive file transfer callbacks.

Get notified when you transfer a file.

func onSendFile(_ sendFile: ZMVideoSDKSendFile!, status: ZMVideoSDKFileTransferStatus) {
  // Get the transfer status of the file and the file content here.
  }
- (void)onSendFile:(ZMVideoSDKSendFile *)sendFile status:(ZMVideoSDKFileTransferStatus)status
{
  // Get the transfer status of the file and the file content here.
}

Get notified when you receive a file from other users.

func onReceiveFile(_ receiveFile: ZMVideoSDKReceiveFile!, status: ZMVideoSDKFileTransferStatus) {
  // Get the transfer status of the file and the file content here.
  }
-(void)onReceiveFile:(ZMVideoSDKReceiveFile *)receiveFile status:(ZMVideoSDKFileTransferStatus)status
{
  // Get the transfer status of the file and the file content here.
}