Session Chat

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.

Sending messages

A message can be sent to a single user or to the entire session.

Send a private chat 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];
}

// 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)
    }
}

Send a chat message to all users in a session


// 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];
}

// 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)
    }
}

Receiving messages

Get notified when a chat message is posted

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).


- (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);
}

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)")
    }
}

For more information on how to use the ZMVideoSDKUser object, see the manage user information guide.

Additional considerations

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


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.

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.

Next Steps

Need help?

If you're looking for help, try Developer Support or our Developer Forum. Priority support is also available with Premier Developer Support plans.