Skip to main content

You are viewing Agora Docs forBetaproducts and features. Switch to Docs

Android
iOS
macOS
Web
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 scenarios 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 RtmChannelType.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


    _15
    // Send string message
    _15
    PublishOptions options = new PublishOptions();
    _15
    options.setChannelType(RtmChannelType.USER);
    _15
    options.setCustomType("PlainText");
    _15
    rtmClient.publish("Tony", "Hello world", options, new ResultCallback<Void>() {
    _15
    @Override
    _15
    public void onSuccess(Void responseInfo) {
    _15
    log(CALLBACK, "Send message success");
    _15
    }
    _15
    _15
    @Override
    _15
    public void onFailure(ErrorInfo errorInfo) {
    _15
    log(ERROR, errorInfo.toString());
    _15
    }
    _15
    });

  • Binary message


    _16
    // Send binary message
    _16
    byte[] message = new byte[] {1, 2, 3, 4};
    _16
    PublishOptions options = new PublishOptions();
    _16
    options.setChannelType(RtmChannelType.USER);
    _16
    options.setCustomType("ByteArray");
    _16
    rtmClient.publish("Tony", message, options, new ResultCallback<Void>() {
    _16
    @Override
    _16
    public void onSuccess(Void responseInfo) {
    _16
    log(CALLBACK, "Send message success");
    _16
    }
    _16
    _16
    @Override
    _16
    public void onFailure(ErrorInfo errorInfo) {
    _16
    log(ERROR, errorInfo.toString());
    _16
    }
    _16
    });

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.

Message packet size

Signaling SDK imposes 32KB size limits on message payload packets sent in user channels. The message payload packet size includes the message payload itself plus the size of the customType field. If the message payload package size exceeds the limit, you receive the following error message.


_6
// ErrorInfo
_6
ErrorInfo {
_6
errorCode = -11010;
_6
reason = "Publish too long message.";
_6
operation = "publishTopicMessage"; // or "publish"
_6
}

To avoid sending failure due to excess message payload packet size, check the packet size before sending.

API reference

Signaling