Skip to main content

Receiving chat messages

To be able to receive chat messages you need to implement a method onChatUpdates() method from callback DyteChatEventsListener. You can subscribe to this events by calling meeting.addMeetingEventsListener(dyteChatEventsListener)

    extension MeetingViewModel: DyteChatEventsListener {
func onChatUpdates(messages: [DyteChatMessage]) {
// any update in chat messages
}

func onNewChatMessage(message: DyteChatMessage) {
// updates for new chat messages only
}
}

Here, the message is of type Message, as defined in introduction. messages is a list of all chat messages in the meeting, which is the same as meeting.chat.messages.

When a chat message is received, the meeting.chat.messages list is also updated.

DyteChatMessage has different implementations of it, thus you will need to cast and use appropriate type as follows:

   func onNewChatMessage(message: DyteChatMessage) {
if let msg = message {
switch msg.type {
case .text:
if let textMsg = msg as? DyteTextMessage {
//print("onNewChatMessage: Text : \(textMsg)")
}
case .file:
if let fileMsg = msg as? DyteFileMessage {
//print("onNewChatMessage: File : \(fileMsg.name)")
}
case .image:
if let imgMsg = msg as? DyteImageMessage {
//print("onNewChatMessage: Image : \(imgMsg.link)")
}

default:
print("Error! Message type unknown!")
}
}