Chat / Unreal
Current version: v3
Chat Unreal v3
Chat Unreal
Chat
Unreal
Home
/
Chat
/
Unreal
/
Messages

Receive messages through a channel event handler

Members can receive each other's messages through the MessageReceived() method of a channel event handler. A SBDBaseMessage object for each received message is one of the following three message types.

Message typeDescription

UserMessage

A text message sent by a user.

FileMessage

A binary file message sent by a user.

AdminMessage

A text message sent by an admin through the Chat API.

UNIQUE_HANDLER_ID is a unique identifier to register multiple concurrent handlers.

class MyChannelHandler : public SBDChannelHandler {
    void MessageReceived(SBDBaseChannel* channel, SBDBaseMessage* message) {
        // You can customize how to display the different types of messages with the result object in the message parameter.
        if (message->message_type == SBDMessageType::User) {
            // ...
        }
        else if (message->message_type == SBDMessageType::File) {
            // ...
        }
        else if (message->message_type == SBDMessageType::Admin) {
            // ...
        }
    }
});

SBDMain::AddChannelHandler(UNIQUE_HANDLER_ID, new MyChannelHandler());

If the UI isn't valid anymore, remove the channel event handler.

// You can remove a specific channel handler.
SBDMain::RemoveChannelHandler(UNIQUE_HANDLER_ID);

// You can remove all registered channel handlers. 
SBDMain::RemoveAllChannelHandlers();