Use in-meeting chat

View as Markdown

The Meeting SDK lets you use in-meeting chat  to communicate with other participants in the same meeting.

Handle chat functionality through the MobileRTCMeetingService interface.

guard let meetingService = MobileRTC.shared().getMeetingService() else { return }

Understand the chat callbacks

For chat related callbacks, conform to and add the delegate MobileRTCMeetingServiceDelegate. The callbacks are onChatMessageNotification, onChatMessageEditNotification and onChatMsgDeleteNotification.

Control chat settings

Before you use in-meeting chat, check if the current meeting or webinar supports chat, and then look at which participants or attendees can use chat.

Chat settings in a meeting

In a meeting, use getAttendeeChatPriviledge.

if !meetingService.isChatDisabled() {
    let chatPrivilege = meetingService.getAttendeeChatPriviledge()
}

The MobileRTCMeetingChatPriviledgeType uses one of these values.

  • MobileRTCMeetingChatPriviledge_No_One - No participants may use chat.
  • MobileRTCMeetingChatPriviledge_Host_Only - Only the host of the meeting may use chat.
  • MobileRTCMeetingChatPriviledge_Everyone_Publicly - All participants may use chat, but private messages are not allowed.
  • MobileRTCMeetingChatPriviledge_Everyone_Publicly_And_Privately - All participants may use chat to send both private and public messages.
  • MobileRTCMeetingChatPriviledge_Unknown - Meeting chat privilege is not applicable to the current meeting.

If the current user is the meeting's host, they can control chat settings by specifying a MobileRTCMeetingChatPriviledgeType.

meetingService.changeAttendeeChatPriviledge(.everyone_Publicly_And_Privately)
meetingService.changeAttendeeChatPriviledge(.no_One)

Chat settings in a webinar

In a webinar, use webinarAttendeeChatPrivilege.

let chatPrivilege = meetingService.getWebinarAttendeeChatPrivilege()

The MobileRTCChatAllowAttendeeChat uses one of these values.

  • MobileRTCChatAllowAttendeeChat_ChatWithNone - No attendees may use chat.
  • MobileRTCChatAllowAttendeeChat_ChatWithPanelist - Only panelists may use chat.
  • MobileRTCChatAllowAttendeeChat_ChatWithAll - All panelists and attendees may use chat.

Update a webinar's chat settings by setting a MobileRTCWebinarPanelistChatPrivilege.

meetingService.allowAttendeeChat(.chatWithAll)
meetingService.allowAttendeeChat(.chatWithPanelist)

Send messages

To send a public message in either a meeting or a webinar, instantiate a MobileRTCMeetingChatBuilder and set the content and message type.

guard let chatMessageToAll = MobileRTCMeetingChatBuilder().setContent("Hello World!")?.setMessageType(.to_All)?.build() else { return }
meetingService.sendChatMsg(chatMessageToAll)

For private messages, change the message type to MobileRTCChatMessageType_To_Individual and include a receiver ID to specify the message recipient.

guard let chatMessagePrivate = MobileRTCMeetingChatBuilder().setContent("Hello World!")?.setMessageType(.to_Individual)?.setReceiver(123456789)?.build() else { return }
meetingService.sendChatMsg(chatMessagePrivate)

To reply to an existing message in a thread, first get a threadId for the message being responded to. For more information on how to get the threadId, see Receive messages. Once you've retrieved the thread ID, pass it in and set the type based on whether the parent message is public or private.

guard let chatMessagePrivate = MobileRTCMeetingChatBuilder().setContent("Hello World!")?.setMessageType(.to_Individual)?.setReceiver(123456789)?.build() else { return }
meetingService.sendChatMsg(chatMessagePrivate)

// Reply
// 1. Identify the message (MobileRTCMeetingChat) you want to reply to and get its threadID
let chatInfo: MobileRTCMeetingChat? = nil
guard let chatInfo = chatInfo else { return }
let threadID = chatInfo.threadID

// 2. Build MobileRTCMeetingChatBuilder with threadID
guard let threadReplyMessage = MobileRTCMeetingChatBuilder().setContent("Reply to Hello World!")?.setMessageType(.to_All)?.setThreadId(threadID)?.build() else { return }

// 3. Send reply message
meetingService.sendChatMsg(chatMessagePrivate)

Messages sent from the SDK can also include quoted text. The quote position specifies the start and end characters in the quoted text string.

guard let quotedMessage = MobileRTCMeetingChatBuilder().setContent("This is a sample message stylized as a quote")?.setMessageType(.to_All)?.setQuotePosition(0, end: 42)?.build() else { return }
meetingService.sendChatMsg(quotedMessage)

Receive messages

To display content from chat messages, the SDK provides a callback to get notified of when a new message is sent to the meeting. You can also use this callback to confirm that a message sent by the current user has successfully been posted to the meeting chat.

Conform to the MobileRTCMeetingServiceDelegate protocol first, then use the chatInfo parameter within onChatMessageNotification to get information about the chat message. Some data, like receiverId, will only be available for specific types of messages.

guard let meetingService = MobileRTC.shared().getMeetingService() else { return }
meetingService.delegate = self

extension ViewController: MobileRTCMeetingServiceDelegate {
    func onChatMessageNotification(_ chatInfo: MobileRTCMeetingChat?) {
        guard let chatInfo = chatInfo else { return }
        chatInfo.chatId // A unique identifier assigned to this message.
        chatInfo.content // The content of the message that is visible to users in the meeting.
        chatInfo.date // The time at which the message was sent.
        chatInfo.senderId // The Zoom user ID of the user who sent the message.
        chatInfo.senderName // The display name of the user who sent the message.
        chatInfo.receiverId // The Zoom user ID of the user on the receiving end of a private message.
        chatInfo.receiverName // The display name of the user on the receiving end of a private message.
        chatInfo.isChatToWaitingroom // Whether the message was sent to the waiting room.
        chatInfo.chatMessageType // The message type, see "MobileRTCChatMessageType".
        chatInfo.isComment // Whether the chat message is a comment responding to a thread.
        chatInfo.isThread // Whether the chat message is a thread with comments.
        chatInfo.threadID // The unique identifier associated with a thread
        chatInfo.segmentDetails // Get the detailed attributes such as bold, italic, strikethrough and more.
    }
}

Delete messages

To delete a message sent by the current user, use the msgId. This will trigger the onChatMsgDeleteNotification callback under the same MobileRTCMeetingServiceDelegate

let msgID: String = ""
if meetingService.isChatMessageCanBeDeleted(msgID) {
    meetingService.deleteChatMessage(msgID)
}

Parse text format

The SDK supports receiving various styles of chat messages such as bold, italic, quote, font color and size, and many more. The styles are included as a list of MobileRTCSegmentDetails objects under each of the MobileRTCMeetingChat object.

if let chatInfoSegmentDetails = chatInfo.segmentDetails {
    for segment in chatInfoSegmentDetails {
        segment.content
        segment.boldAttrs
        segment.italicAttrs
        segment.underlineAttrs // and more
    }
}