Skip to main content
Android
iOS
macOS
Web
Windows
Flutter
Linux C++
Unity

User channels

Signaling enables you to send direct, point-to-point messages to individual users through user channels. This feature is useful in one-on-one communication use-cases such as private chats and customer support interactions.

Understand the tech

To implement point-to-point communication between individual users in your app:

  1. Set up the Signaling SDK: Integrate the Signaling SDK in your app and initialize an instance of the Signaling client.
  2. Authenticate the user: Log in to Signaling using a unique user ID.
  3. Send direct messages: Call the publish method with the User channel type and specify the recipient's user ID as the channel name to send direct messages.
  4. Handle incoming messages: Listen for message events to receive messages sent directly to the local user.

Prerequisites

Ensure that you have:

  • Integrated the Signaling SDK in your project, and implemented the framework functionality from the SDK quickstart.

Implement user messages

This section shows you how to use the Signaling SDK to send messages directly to a specified user.

To send message to a user channel, call the publish method with the channelType parameter set to RTM_CHANNEL_TYPE_USER and the channelName parameter set to the target user's userId. This method enables you to send a message to one user at a time. To send messages to multiple users, call this method for each user. While Signaling does not limit the number of users you can send messages to or receive messages from, it does limit the frequency at which you can send messages to users.

Refer to the following sample code for sending messages:

  • String message

    // Send string message
    std::string message = "Hello Agora!";
    PublishOptions options;
    options.messageType = RTM_MESSAGE_TYPE_STRING;
    options.customType = "PlainText";
    options.channelType = RTM_CHANNEL_TYPE_USER;

    uint64_t requestId;
    rtmClient->publish("Tony", message.c_str(), message.size(), options, requestId);
    Copy
  • Binary message

    // Send binary message
    PublishOptions options;
    options.messageType = RTM_MESSAGE_TYPE_BINARY;
    options.customType = "ByteArray";
    options.channelType = RTM_CHANNEL_TYPE_USER;
    char message[5] = {0x00, 0x01, 0x02, 0x03, 0x04};

    uint64_t requestId;
    rtmClient->publish("Tony", message, 5, options, requestId);
    Copy

When you call this method, the SDK triggers the onPublishResult callback and returns the API call result.

// Asynchronous callback
class RtmEventHandler : public IRtmEventHandler {
void onPublishResult(const uint64_t requestId, RTM_ERROR_CODE errorCode) override {
if (errorCode != RTM_ERROR_OK) {
// publish message failed
} else {
// publish message success
}
}
};
Copy
info

Signaling currently supports only string and binary message formats. To send other types of data such as a JSON objects, or data from third-party data construction tools such as protobuf, serialize the data before sending the message. For information on how to effectively construct the payload data structure and recommended serialization methods, refer to Message payload structuring.

Reference

This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.

Signaling