Skip to main content

You are viewing Agora Docs forBeta products and features. Switch to Docs

Signaling SDK API reference

The Signaling SDK API Reference lists the description, methods, basic usage, sample code, and return values. It is divided in to the following sections:

Setup

The API references for the Signaling SDK introduces the interface description, interface methods, basic usage example codes, and return values of Signaling APIs.

RtmConfig

Description

Use the RtmConfig to set additional properties for Signaling initialization. These configuration properties will take effect throughout the lifecycle of the Signaling client and affect the behavior of the Signaling client.

Method

You can create RtmConfig instances in the following way:


_7
RtmConfig rtmConfig = new RtmConfig.Builder("appid", "userId")
_7
.areaCode(EnumSet.of(RtmConstants.RtmAreaCode.AS, RtmConstants.RtmAreaCode.CN))
_7
.eventListener(eventListener)
_7
.proxyConfig(proxyConfig)
_7
.logConfig(logConfig)
_7
.encryptionConfig(encryptionConfig)
_7
.build();

PropertiesTypeRequiredDefaultDescription
appIdstringRequired-App ID obtained when creating a project in the Agora Console.
userIdstringRequired-User ID for identify a user or a device.
Information
To distinguish each user or device, you need to ensure that the userId parameter is globally unique and remains unchanged throughout the user or device's lifecycle.
areaCodeRtmAreaCodeOptionalGLOBService area code, you can choose according to the region where your business is deployed. See RtmAreaCode.
presenceTimeoutUInt32Optional300Presence timeout in seconds, and the value range is [10,300].
useStringUserIdBoolOptionaltrueWhether to use string-type user IDs:
  • true: Use string-type user IDs.
  • false: Use number-type user IDs. The SDK automatically converts string-type user IDs to number-type ones. In this case, the userId parameter must be a numeric string (for example, "123456"), otherwise initialization fails.
When using Agora RTC and Signaling products at the same time, it is necessary to ensure that the userId parameter is consistent.
logConfigRtmLogConfigOptional-Log configuration properties such as the log storage size, storage path, and level.
eventListenerRtmEventListenerRequired-Signaling event notification listener settings. See Event listeners.
proxyConfigRtmProxyConfigOptional-When using the Proxy feature of Signaling, you need to configure this parameter.
encryptionConfigRtmEncryptionConfigOptional-When using the client-side encryption feature of Signaling, you need to configure this parameter.

RtmLogConfig

Use the RtmLogConfig instance to configure and store local log files named agora.log. During the debugging phase, you can greatly improve efficiency by storing and tracking the running status of the app through logs. If you encounter complex problems and need Agora technical support to assist with the investigation, you need to provide the log information. RtmLogConfig contains the following properties:

PropertiesTypeRequiredDefaultDescription
filePathStringOptional-Log file storage paths.
fileSizeInKBintOptional1024Log file size in KB, with a value range of [128,1024].
  • If the value you enter is less than 128, the SDK sets the value to 128.
  • If the value you enter is greater than 1024, the SDK sets the value to 1024.
  • levelRtmLogLevelOptionalINFOOutput level of log information. See RtmLogLevel.

    RtmProxyConfig

    Use the RtmProxyConfig instance to set properties related to the client Proxy service. In some restricted network environments, you might need to use this feature.
    Caution
    You need to keep your Proxy username and password safe. The Signaling SDK does not parse, store, or forward your username and password in any way. In addition, if you modify the Proxy settings during the app running process, the settings will take effect only after restarting the Signaling client.

    RtmProxyConfig contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    proxyTypeRtmProxyTypeOptionalNONEProxy protocol type. See RtmProxyType.
    serverStringOptional-Proxy server domain name or IP address.
    portintOptional-Proxy listening port.
    accountStringOptional-Proxy login account.
    passwordStringOptional-Proxy login password.

    RtmEncryptionConfig

    Use the RtmEncryptionConfig instance to set the properties required for the client-side encryption. After successfully setting encryption modes, encryption keys, and other related properties, the SDK automatically encrypts and decrypts all messages sent or all statuses set by the user on the client side.
    Caution
    Once you set the encryption feature, all users must use the same encryption mode and key, otherwise users cannot communicate with each other.

    RtmEncryptionConfig contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    encryptionModeRtmEncryptionModeOptionalNONEEncryption mode. See RtmEncryptionMode.
    encryptionKeyStringOptional-User-defined encryption key, unlimited length. Agora recommends using a 32-byte key.
    encryptionKdfSaltbyte[]OptionalnullUser-defined encryption salt, length is 32 bytes. Agora recommends using OpenSSL to generate salt on the server side.

    Basic usage


    _27
    RtmProxyConfig proxyConfig = new RtmProxyConfig();
    _27
    proxyConfig.setProxyType(RtmProxyType.HTTP);
    _27
    proxyConfig.setServer("x.x.x.x"); // your proxy server ip
    _27
    proxyConfig.setPort(8080); // your server port
    _27
    proxyConfig.setAccount("user_name");
    _27
    proxyConfig.setPassword("pass_word");
    _27
    _27
    RtmLogConfig logConfig = new RtmLogConfig();
    _27
    logConfig.setFilePath(""); // your log path
    _27
    logConfig.setFileSize(10*1024); // log file size
    _27
    logConfig.setLevel(RtmLogLevel.INFO);
    _27
    _27
    byte[] salt = {1, 2, 3, 4, 5};
    _27
    RtmEncryptionConfig encryptionConfig = new RtmEncryptionConfig();
    _27
    encryptionConfig.setEncryptionMode(RtmEncryptionMode.AES_256_GCM);
    _27
    encryptionConfig.setEncryptionKey("your_encryption_key");
    _27
    encryptionConfig.setEncryptionSalt(salt);
    _27
    _27
    RtmConfig rtmConfig = new RtmConfig.Builder("yourAppId", "Tony")
    _27
    .areaCode(EnumSet.of(RtmAreaCode.GLOB))
    _27
    .eventListener(eventListener)
    _27
    .presenceTimeout(300)
    _27
    .useStringUserId(true)
    _27
    .proxyConfig(proxyConfig)
    _27
    .logConfig(logConfig)
    _27
    .encryptionConfig(encryptionConfig)
    _27
    .build();

    create

    Description

    Call the create method to create and initialize the Signaling Client instance.
    Information
    • You need to create and initialize a client instance before calling other Signaling APIs.
    • To distinguish each user or device, you need to ensure that the userId parameter is globally unique and remains unchanged throughout the user or device's lifecycle.

    Method

    You can create and initialize an instance in the following way:


    _1
    RtmClient create(RtmConfig config) throws Exception;

    ParametersTypeRequiredDefaultDescription
    configRtmConfigRequired-Initialize the configuration parameters of the Signaling Client. See RtmConfig.

    Basic usage


    _9
    RtmConfig rtmConfig = new RtmConfig.Builder("yourAppId", "Tony")
    _9
    .eventListener(eventListener)
    _9
    .build();
    _9
    _9
    try {
    _9
    rtmClient = RtmClient.create(rtmConfig);
    _9
    } catch (Exception e) {
    _9
    e.printStackTrace();
    _9
    }

    Return Value

    • If the method call succeeds, the SDK creates a Signaling client instance for subsequent calls to other Signaling APIs.
    • If the method call fails, the SDK returns Exception.

    Event Listeners

    Description

    Signaling has a total of 7 types of event notifications, as shown in the following table:

    Event TypeDescription
    onMessageEventReceive message event notifications in subscribed message channels and subscribed topics.
    onPresenceEventReceive presence event notifications in subscribed message channels and joined stream channels.
    onTopicEventReceive all topic event notifications in joined stream channels.
    onStorageEventReceive channel metadata event notifications in subscribed message channels and joined stream channels, and the user metadata event notification of the subscribed users.
    onLockEventReceive lock event notifications in subscribed message channels and joined stream channels.
    onConnectionStateChangedReceive event notifications when client connection status changes. For details, see SDK connection state and SDK connection state change reason.
    onTokenPrivilegeWillExpireReceive event notifications when the client tokens are about to expire.

    Add event listeners

    You can add an event listener object through the following ways:

    • Add only an event listener object during initialization.
    • Add one or more event listener objects at any point during the app's lifecycle by calling the addEventListener method.

    Adding During Initialization

    When initializing the Signaling client instance using the create method, you can refer to the following example code to add an event listener object:


    _38
    // add the message event listener
    _38
    // only need override the event which you want to receive
    _38
    rtmConfig.eventListener = new RtmEventListener {
    _38
    @Override
    _38
    public void onMessageEvent(MessageEvent event) {
    _38
    // Your Message Event handler
    _38
    }
    _38
    _38
    @Override
    _38
    public void onPresenceEvent(PresenceEvent event) {
    _38
    // Your Presence Event handler
    _38
    }
    _38
    _38
    @Override
    _38
    public void onTopicEvent(TopicEvent event) {
    _38
    // Your Topic Event handler
    _38
    }
    _38
    _38
    @Override
    _38
    public void onLockEvent(LockEvent event) {
    _38
    // Your Lock Event handler
    _38
    }
    _38
    _38
    @Override
    _38
    public void onStorageEvent(StorageEvent event) {
    _38
    // Your Storage Event handler
    _38
    }
    _38
    _38
    @Override
    _38
    public void onConnectionStateChange(String channelName, RtmConstants.RtmConnectionState state, RtmConstants.RtmConnectionChangeReason reason) {
    _38
    // Your Connection state change Event handler
    _38
    }
    _38
    _38
    @Override
    _38
    public void onTokenPrivilegeWillExpire(String channelName) {
    _38
    // Your Token Privilege Will Expire Event handler
    _38
    }
    _38
    }

    Adding at Any Time

    At any point during the app's lifecycle, if you need to add multiple event listener objects, you can call the addEventListener method multiple times.

    _15
    // create event listener
    _15
    // only need to override the event which you want to receive
    _15
    RtmEventListener listener = new RtmEventListener() {
    _15
    @Override
    _15
    public void onMessageEvent(MessageEvent event) {
    _15
    }
    _15
    _15
    @Override
    _15
    public void onConnectionStateChanged(String channelName, RtmConstants.RtmConnectionState state, RtmConstants.RtmConnectionChangeReason reason) {
    _15
    }
    _15
    };
    _15
    _15
    // add listener
    _15
    rtmClient.addEventListener(listener);
    _15
    // ...

    If you no longer need to listen to a specific event listener object, but still need to listen to other event listener objects, you can call the removeEventListener method to remove the specified event listener object.

    _1
    rtmClient.removeEventListener(listener);

    MessageEvent

    Message event.

    MessageEvent contains the following properties:

    PropertiesTypeDescription
    channelTypeRtmChannelTypeChannel types. See RtmChannelType.
    channelNameStringChannel name.
    topicNameStringTopic name.
    messageRtmMessageMessage.
    publisherStringUser ID of the message publisher.
    customTypeStringA user-defined field. Only supports string type.

    RtmMessage contains the following properties:

    PropertiesTypeDescription
    messageStringString type message.
    databyte[]Byte type message.
    messageTypeRtmMessageTypeMessage type. See RtmMessageType.

    PresenceEvent

    User presence event.

    PresenceEvent contains the following properties:

    PropertiesTypeDescription
    typeRtmPresenceEventTypePresence event type. See RtmPresenceEventType.
    channelTypeRtmChannelTypeChannel types. See RtmChannelType.
    channelNameStringChannel name.
    publisherStringUser ID of the message publisher.
    stateItemsArrayList<StateItem>Key-value pair that identifies the user's presence state.
    intervalIntervalInfoIn the Interval state, the aggregated incremental information of event notifications such as user joining, leaving, timeout, and status change in the previous period of the current channel.
    snapshotSnapshotInfoWhen the user first joins the channel, the server pushes the snapshot data of all users in the current channel and their statuses to the user.

    IntervalInfo contains the following properties:

    PropertiesTypeDescription
    joinUserListArrayList<String>List of users who joined the channel in the previous cycle.
    leaveUserListArrayList<String>List of users who left the channel in the previous cycle.
    timeoutUserListArrayList<String>List of users who timed out joining the channel in the previous cycle.
    userStateListArrayList<UserState>List of users whose status has changed in the previous cycle. Contains user ID and status key-value pairs.

    SnapshotInfo contains the following properties:

    PropertiesTypeDescription
    userStateListArrayList<UserState>Snapshot information of the user when first joining the channel, including user ID and key-value pairs of status.

    StateItem contains the following properties:

    PropertyTypeDescription
    keystringKey of user status. If the provided key already exists, the new value overwrites the previous one. If the provided key does not exist, a new key-value pair is created.用户状态的键。
    valuestringValue of user status.

    TopicEvent

    Topic event.

    TopicEvent contains the following properties:

    PropertiesTypeDescription
    typeRtmTopicEventTypeTopic event type. See RtmTopicEventType.
    channelNameStringChannel name.
    publisherStringUser ID.
    topicInfosArrayList<TopicInfo>Topic information.

    TopicInfo data type contains the following properties:

    PropertiesTypeDescription
    topicNameStringTopic name.
    publishersArrayList<PublisherInfo>Message publisher array.

    PublisherInfo data type contains the following properties:

    PropertiesTypeDescription
    publisherUserIdStringUser ID of the message publisher.
    publisherMetaStringMetadata of the message publisher.

    StorageEvent

    Storage event.

    StorageEvent contains the following properties:

    PropertiesTypeDescription
    channelTypeRtmChannelTypeChannel types. See RtmChannelType.
    storageTypeRtmStorageTypeStorage type. See RtmStorageType.
    eventTypeRtmStorageEventTypeStorage event type. See RtmStorageEventType.
    targetStringUser ID or channel name.
    dataMetadataMetadata item. See Metadata.

    LockEvent

    Lock event.

    LockEvent contains the following properties:

    PropertiesTypeDescription
    channelTypeRtmChannelTypeChannel types. See RtmChannelType.
    eventTypeRtmLockEventTypeLock event type. See RtmLockEventType.
    channelNameStringChannel name.
    lockDetailListArrayList<LockDetail>Details of lock.

    The LockDetail data type contains the following properties:

    PropertiesTypeDescription
    lockNameStringLock name.
    lockOwnerStringThe ID of the user who has a lock.
    ttlintThe expiration time of the lock. The value is in seconds, ranging from [10 to 300]. When the user who owns the lock goes offline, if the user returns to the channel within the time they can still use the lock; otherwise, the lock is released and the users who listen for the onLockEvent event receives the RELEASED event.

    login

    Description

    Information
    After the user successfully logs in to the Signaling service, the PCU of the application increases, which affects your billing data.

    Method

    You can log in to the Signaling system in the following way:


    _1
    void login(String token, ResultCallback<Void> resultCallback);

    ParametersTypeRequiredDefaultDescription
    tokenStringRequired-Dynamic keys are generally generated by the user's token server.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • After calling most of the APIs of the Signaling Java SDK, the SDK returns a resultCallback callback. Based on different invocation results, the SDK executes different methods in the resultCallback callback:

    • If the method call succeeds, the SDK executes the onSuccess method.
    • If the method call fails, the SDK executes the onFailure method and the onFailure method returns an errorInfo value of type ErrorInfo, which includes the error code, error reason, and API operation name as follows:

    Basic usage


    _8
    rtmClient.login(token, new ResultCallback<Void>() {
    _8
    @Override
    _8
    public void onSuccess(Void responseInfo) {
    _8
    }
    _8
    @Override
    _8
    public void onFailure(ErrorInfo errorInfo) {
    _8
    }
    _8
    });

    logout

    Description

    When you no longer need to operate, you can log out of the system. This operation affects the PCU item in your billing data.

    Method

    You can log out in the following way:


    _1
    void logout(ResultCallback<Void> resultCallback);

    ParametersTypeRequiredDefaultDescription
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • Basic usage


    _9
    rtmClient.logout(new ResultCallback<Void>() {
    _9
    @Override
    _9
    public void onSuccess(Void responseInfo) {
    _9
    }
    _9
    _9
    @Override
    _9
    public void onFailure(ErrorInfo errorInfo) {
    _9
    }
    _9
    });

    release

    Description

    Once you no longer need the Signaling service, it is best to destroy the RtmClient instance. Doing so protects you from the performance degradation caused by memory leaks, errors, and exceptions.

    Method

    You can destroy the RtmClient instance in the following way:


    _1
    void release();

    Basic usage


    _1
    rtmClient.release();

    Channels

    Signaling provides a highly efficient channel management mechanism for data transmission. Any user who subscribes or joins a channel can receive messages and events transmitted within 100 milliseconds. Signaling allows clients to subscribe to hundreds or even thousands of channels. Most Signaling APIs perform actions such as sending, receiving, and encrypting based on channels.

    Based on capabilities of Agora, Signaling channels are divided into two types to match different application scenarios:

    • Message Channel: Follows the industry-standard Pub/Sub (publish/subscribe) mode. You can send and receive messages within the channel by subscribing to a channel, and do not need to create the channel in advance. There is no limit to the number of publishers and subscribers in a channel.
    • Stream Channel: Follows a concept similar to the observer pattern in the industry, where users need to create and join a channel before sending and receiving messages. You can create different topics in the channel, and messages are organized and managed through topics.

    subscribe

    Description

    By calling the subscribe method, the client can subscribe to a message channel and start receiving messages and event notifications within the channel. After successfully calling this method, users who subscribe to the channel and enable the presence event listener can receive a REMOTE_JOIN type of the onPresenceEvent event. See Event Listeners.

    Information
    This method only applies to the message channel.

    Method

    You can call the subscribe method in the following way:


    _5
    void subscribe(
    _5
    String channelName,
    _5
    SubscribeOptions options,
    _5
    ResultCallback<Void> resultCallback
    _5
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.
    optionsSubscribeOptionsRequired-Options for subscribing to a channel.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • SubscribeOptions contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    withMessagebooleanOptionaltrueWhether to subscribe to message event notifications in the channel.
    withPresencebooleanOptionaltrueWhether to subscribe to presence event notifications in the channel.
    withMetadatabooleanOptionalfalseWhether to subscribe to storage event notifications in the channel.
    withLockbooleanOptionalfalseWhether to subscribe to lock event notifications in the channel.

    Basic usage


    _17
    SubscribeOptions options = new SubscribeOptions();
    _17
    options.setWithMessage(true);
    _17
    options.setWithPresence(true);
    _17
    options.setWithMetadata(false);
    _17
    options.setWithLock(false);
    _17
    _17
    rtmClient.subscribe("channel_name", options, new ResultCallback<Void>() {
    _17
    @Override
    _17
    public void onSuccess(Void responseInfo) {
    _17
    log(CALLBACK, "subscribe channel success");
    _17
    }
    _17
    _17
    @Override
    _17
    public void onFailure(ErrorInfo errorInfo) {
    _17
    log(ERROR, errorInfo.toString());
    _17
    }
    _17
    });

    unsubscribe

    Description

    If you no longer need to subscribe to a channel, you can call the unsubscribe method to unsubscribe from the channel. After successfully calling this method, users who subscribe to the channel and enable event listeners can receive the REMOTE_LEAVE type of the onPresenceEvent event notification. See Event Listeners.
    Information
    This method only applies to the message channel.

    Method

    You can call the unsubscribe method in the following way:


    _4
    void unsubscribe(
    _4
    String channelName,
    _4
    ResultCallback<Void> resultCallback
    _4
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • Basic usage


    _11
    rtmClient.unsubscribe("channel_name", new ResultCallback<Void>() {
    _11
    @Override
    _11
    public void onSuccess(Void responseInfo) {
    _11
    log(CALLBACK, "unsubscribe channel success");
    _11
    }
    _11
    _11
    @Override
    _11
    public void onFailure(ErrorInfo errorInfo) {
    _11
    log(ERROR, errorInfo.toString());
    _11
    }
    _11
    });

    createStreamChannel

    Description

    Before using a stream channel, you need to call the createStreamChannel method to create the StreamChannel instance. After successfully creating the instance, you can call its relevant methods to implement functions, such as joining the channel, leaving the channel, sending messages in a topic, and subscribing to messages in a topic.
    Information
    This method only applies to the stream channel.

    Method

    You can call the createStreamChannel method in the following way:


    _1
    StreamChannel createStreamChannel(String channelName) throws Exception;

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.

    Basic usage


    _5
    try {
    _5
    StreamChannel streamChannel = rtmClient.createStreamChannel("channel_name");
    _5
    } catch (Exception e) {
    _5
    log(ERROR, "create stream channel failed: " + e.toString());
    _5
    }

    Return Value

    The StreamChannel instance.

    join

    Description

    After successfully creating a stream channel, you can call the join method to join the stream channel. Once you join the channel, you can implement channel-related functions. At this point, users who subscribe to the channel and add event listeners can receive the following event notifications:

    • For the local user:
      • The SNAPSHOT type of the onPresenceEvent event.
      • The SNAPSHOT type of the onTopicEvent event.
    • For remote users: The REMOTE_JOIN type of the onPresenceEvent event.
    Information
    This method only applies to the stream channel.

    Method

    You can call the join method in the following way:


    _4
    void join(
    _4
    JoinChannelOptions options,
    _4
    ResultCallback<Void> resultCallback
    _4
    );

    ParametersTypeRequiredDefaultDescription
    optionsJoinChannelOptionsRequired-Options for joining a channel.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • The JoinChannelOptions data type contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    tokenStringRequired-The token used for joining a stream channel, which is currently the same as the RTC token.
    withPresencebooleanOptionaltrueWhether to subscribe to presence event notifications in the channel.
    withMetadatabooleanOptionalfalseWhether to subscribe to storage event notifications in the channel.
    withLockbooleanOptionalfalseWhether to subscribe to lock event notifications in the channel.

    Basic usage


    _17
    JoinChannelOptions options = new JoinChannelOptions();
    _17
    options.setToken("yourToken")
    _17
    options.setWithPresence(true);
    _17
    options.setWithMetadata(false);
    _17
    options.setWithLock(false);
    _17
    _17
    streamChannel.join(options, new ResultCallback<Void>() {
    _17
    @Override
    _17
    public void onSuccess(Void responseInfo) {
    _17
    log(CALLBACK, "join stream channel success");
    _17
    }
    _17
    _17
    @Override
    _17
    public void onFailure(ErrorInfo errorInfo) {
    _17
    log(ERROR, errorInfo.toString());
    _17
    }
    _17
    });

    leave

    Description

    If you no longer need to stay in a channel, you can call the leave method to leave the channel. After leaving the channel, you can no longer receive any messages, states, or event notifications from this channel. At the same time, you can no loger be the topic publisher or subscriber of all topics. If you want to restore your previous publisher role and subscribing relationship, you need to call join, joinTopic and subscribeTopic methods in order.

    After successfully leaving the channel, remote users in the channel can receive the REMOTE_LEAVE type of the onPresenceEvent event notification. For details, see Event Listeners.

    Information
    This method only applies to the stream channel.

    Method

    You can call the leave method in the following way:


    _1
    void leave(ResultCallback<Void> resultCallback);

    ParametersTypeRequiredDefaultDescription
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • Basic usage


    _11
    streamChannel.leave(new ResultCallback<Void>() {
    _11
    @Override
    _11
    public void onSuccess(Void responseInfo) {
    _11
    log(CALLBACK, "leave stream channel success");
    _11
    }
    _11
    _11
    @Override
    _11
    public void onFailure(ErrorInfo errorInfo) {
    _11
    log(ERROR, errorInfo.toString());
    _11
    }
    _11
    });

    release

    Description

    If you no longer need a channel, you can call the release method to destroy the corresponding stream channel instance and release resources. Calling the release method does not destroy the stream channel, and it can be re-joined later by calling createStreamChannel and join again.
    Information
    This method only applies to the stream channel. If you don't call leave to leave the channel before directly calling release to destroy the stream channel instance, the SDK automatically calls the leave and triggers the corresponding event.

    Method

    You can call the release method in the following way:


    _1
    RtmErrorCode release();

    Basic usage


    _1
    RtmErrorCode errorCode = streamChannel.release();

    Return Value

    This operation returns the RtmErrorCode data type. For details, see Error code.

    Topics

    Topic is a data stream management mechanism in stream channels. Users can use topics to subscribe to and distribute data streams, as well as notify events in data streams in stream channels.

    Information
    Topics only exist in stream channels. Therefore, before using relevant features, you need to create the StreamChannel instance.

    joinTopic

    Description

    The purpose of joining a topic is to register as one of the message publishers for the topic, so that the user can send messages in the topic. This operation does not affect whether or not the user becomes a subscriber to the topic.

    Currently, Signaling supports a single client joining up to 8 topics in the same stream channel at a time.

    Information
    Before joining a topic, a user needs to create the StreamChannel instance and call the join method to join the channel.

    After successfully joining a topic, users who subscribe to that topic and add event listeners can receive the REMOTE_JOIN type of the onTopicEvent event notification. For details, see Event Listeners.

    Method

    You can call the joinTopic method in the following way:


    _5
    void StreamChannel.joinTopic(
    _5
    String topicName,
    _5
    JoinTopicOptions options,
    _5
    ResultCallback<Void> resultCallback
    _5
    );

    ParametersTypeRequiredDefaultDescription
    topicNameStringRequired-Topic name.
    optionsJoinTopicOptionsRequired-Options for joining a topic.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • The options parameter contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    messageQosRtmMessageQosOptionalUNORDEREDWhether the data transmitted in the topic is ordered. See RtmMessageQos.
    priorityRtmMessagePriorityOptionalNORMALThe priority of data transmission in the topic compared to other topics in the same channel. See RtmMessagePriority.
    topicMetaStringOptional-Adds additional metadata when joining the topic.
    syncWithMediabooleanOptionalfalseWhether the data sent in this topic is synchronized (timestamp-aligned) with the RTC audio and video data stream of the common channel.

    Basic usage


    _13
    JoinTopicOptions options = new JoinTopicOptions();
    _13
    options.messageQos = RtmMessageQos.ORDERED;
    _13
    streamChannel.joinTopic("topic_name", options, new ResultCallback<Void>() {
    _13
    @Override
    _13
    public void onSuccess(Void responseInfo) {
    _13
    log(CALLBACK, "join topic success");
    _13
    }
    _13
    _13
    @Override
    _13
    public void onFailure(ErrorInfo errorInfo) {
    _13
    log(ERROR, errorInfo.toString());
    _13
    }
    _13
    });

    publishTopicMessage

    Description

    Use the publishTopicMessage method to send messages to a topic. Users who have subscribed to the topic and the message publisher in the channel can receive the message within 100 milliseconds. Before calling the publishTopicMessage method, users need to join the stream channel, and then register as a message publisher for that topic by calling the joinTopic method.

    The messages sent by users are encrypted with TLS during transmission, and data link encryption is enabled by default and cannot be disabled. To achieve a higher level of data security, users can also enable client encryption during initialization. For details, see Setup.

    Method

    You can call the publishTopicMessage[1/2] and publishTopicMessage[2/2] method in the following way:


    _7
    // publishTopicMessage [1/2]
    _7
    void StreamChannel.publishTopicMessage(
    _7
    String topicName,
    _7
    String message,
    _7
    PublishOptions options,
    _7
    ResultCallback<Void> resultCallback
    _7
    );


    _7
    // publishTopicMessage [2/2]
    _7
    void StreamChannel.publishTopicMessage(
    _7
    String topicName,
    _7
    byte[] message,
    _7
    PublishOptions options,
    _7
    ResultCallback<Void> resultCallback
    _7
    );

    ParametersTypeRequiredDefaultDescription
    topicNameStringRequired-Topic name.
    messageString\byte[]Required-Message payload.
    optionsPublishOptionsRequired-Message options.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • The PublishOptions data type contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    sendTslongOptional0The timestamp when the SDK sends a message. This parameter is only valid when you set syncWithMedia = true in the joinTopic method. The SDK synchronizes data with RTC audio and video streams based on this timestamp.
    customTypeStringOptional-A user-defined field. Only supports string type.

    Basic usage

    Example 1: Send string messages to a specified channel.


    _14
    String message = "message";
    _14
    PublishOptions options = new PublishOptions();
    _14
    options.customType = "PlainTxT";
    _14
    streamChannel.publishTopicMessage("topic_name", message, options, new ResultCallback<Void>() {
    _14
    @Override
    _14
    public void onSuccess(Void responseInfo) {
    _14
    log(CALLBACK, "publish topic message success");
    _14
    }
    _14
    _14
    @Override
    _14
    public void onFailure(ErrorInfo errorInfo) {
    _14
    log(ERROR, errorInfo.toString());
    _14
    }
    _14
    });

    Example 2: Send byte messages to a specified channel.


    _14
    byte[] message = new byte[] {1, 2, 3, 4};
    _14
    PublishOptions options = new PublishOptions();
    _14
    options.customType = "ByteArray";
    _14
    streamChannel.publishTopicMessage("topic_name", message, options, new ResultCallback<Void>() {
    _14
    @Override
    _14
    public void onSuccess(Void responseInfo) {
    _14
    log(CALLBACK, "publish topic message success");
    _14
    }
    _14
    _14
    @Override
    _14
    public void onFailure(ErrorInfo errorInfo) {
    _14
    log(ERROR, errorInfo.toString());
    _14
    }
    _14
    });

    leaveTopic

    Description

    When you no longer need to publish messages to a topic, to release resources, you can call the leaveTopic method to unregister as a message publisher for that topic. This method does not affect whether or not you subscribe to that topic or any other operations performed by other users on that topic.

    After successfully calling this method, users who subscribe to the channel and enable event listeners can receive the REMOTE_LEAVE type of the onTopicEvent event notification. See Event Listeners.

    Method

    You can call the leaveTopic method in the following way:


    _1
    void StreamChannel.leaveTopic(String topicName, ResultCallback<Void> resultCallback);

    ParametersTypeRequiredDefaultDescription
    topicNameStringRequired-Topic name.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • Basic usage


    _11
    streamChannel.leaveTopic("topic_name", new ResultCallback<Void>() {
    _11
    @Override
    _11
    public void onSuccess(Void responseInfo) {
    _11
    log(CALLBACK, "leave topic success");
    _11
    }
    _11
    _11
    @Override
    _11
    public void onFailure(ErrorInfo errorInfo) {
    _11
    log(ERROR, errorInfo.toString());
    _11
    }
    _11
    });

    subscribeTopic

    Description

    subscribeTopic is an incremental method. For example, if you call this method for the first time with a subscribing list of [UserA, UserB], and then call it again with a subscribing list of [UserB, UserC], the final successful subscribing result is [UserA, UserB, UserC].

    A user can subscribe to a maximum of 50 topics in each channel, and a maximum of 64 message publishers in each topic. See API Limitation.

    Method

    You can call the subscribeTopic method in the following way:


    _5
    void StreamChannel.subscribeTopic(
    _5
    String topicName,
    _5
    TopicOptions options,
    _5
    ResultCallback<SubscribeTopicResult> resultCallback
    _5
    );

    ParametersTypeRequiredDefaultDescription
    topicNameStringRequired-Topic name.
    optionsTopicOptionsRequired-Options for subscribing to a topic.
    resultCallbackResultCallback<SubscribeTopicResult>Required-Callback of invocation result:
  • Success: Executes the onSuccess method and return the SubscribeTopicResult data.
  • Failure: Executes the onFailure method.
  • The options parameter contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    usersArrayList<String>Optional-A list of UserId of message publishers that you want to subscribe to. If you do not set this property, you can randomly subscribe to up to 64 users by default.

    SubscribeTopicResult parameter contains the following properties:

    PropertiesTypeDescription
    succeedUsersArrayList<String>A list of successfully subscribed users.
    failedUsersArrayList<String>A list of users that the SDK fails to subscribe to.

    Basic usage

    Example 1: Subscribe to the specified message publisher in the topic.


    _13
    TopicOptions options = new TopicOptions();
    _13
    options.users = new ArrayList<>(Arrays.asList("UserA","UserB","UserC"));
    _13
    streamChannel.subscribeTopic("topic_name", options, new ResultCallback<SubscribeTopicResult>() {
    _13
    @Override
    _13
    public void onSuccess(SubscribeTopicResult responseInfo) {
    _13
    log(CALLBACK, "subscribe topic success");
    _13
    }
    _13
    _13
    @Override
    _13
    public void onFailure(ErrorInfo errorInfo) {
    _13
    log(ERROR, errorInfo.toString());
    _13
    }
    _13
    });

    Example 2: Randomly subscribe to 64 message publishers in the topic.


    _12
    TopicOptions options = new TopicOptions();
    _12
    mStreamChannel.subscribeTopic("topic_name", options, new ResultCallback<SubscribeTopicResult>() {
    _12
    @Override
    _12
    public void onSuccess(SubscribeTopicResult responseInfo) {
    _12
    log(CALLBACK, "subscribe topic success");
    _12
    }
    _12
    _12
    @Override
    _12
    public void onFailure(ErrorInfo errorInfo) {
    _12
    log(ERROR, errorInfo.toString());
    _12
    }
    _12
    });

    unsubscribeTopic

    Description

    If you are no longer interested in a specified topic, or no longer need to subscribe to one or more message publishers in the topic, you can call the unsubscribeTopic method to unsubscribe from the topic or the specified message publishers in the topic.

    Method

    You can call the unsubscribeTopic method in the following way:


    _5
    void StreamChannel.unsubscribeTopic(
    _5
    String topicName,
    _5
    TopicOptions options,
    _5
    ResultCallback<Void> resultCallback
    _5
    );

    ParametersTypeRequiredDefaultDescription
    topicNameStringRequired-Topic name.
    optionsTopicOptionsRequired-Options for unsubscribe from a topic.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • The options parameter contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    usersArrayList<String>Optional-A list of UserId of message publishers that you want to unsubscribe from. If you do not set this property, you can randomly unsubscribe from up to 64 users by default.

    Basic usage

    Example 1: Unsubscribe the specified message publisher in the topic


    _14
    TopicOptions options = new TopicOptions();
    _14
    options.users = new ArrayList<>(Arrays.asList("Tony","Bo"));
    _14
    _14
    streamChannel.unsubscribeTopic("topicName", options, new ResultCallback<Void>() {
    _14
    @Override
    _14
    public void onSuccess(Void responseInfo) {
    _14
    log(CALLBACK, "unsubscribe topic success");
    _14
    }
    _14
    _14
    @Override
    _14
    public void onFailure(ErrorInfo errorInfo) {
    _14
    log(ERROR, errorInfo.toString());
    _14
    }
    _14
    });

    Example 2: Randomly unsubscribe 64 message publishers from the topic.


    _12
    TopicOptions options = new TopicOptions();
    _12
    streamChannel.unsubscribeTopic("topicName", options, new ResultCallback<Void>() {
    _12
    @Override
    _12
    public void onSuccess(Void responseInfo) {
    _12
    log(CALLBACK, "unsubscribe topic success");
    _12
    }
    _12
    _12
    @Override
    _12
    public void onFailure(ErrorInfo errorInfo) {
    _12
    log(ERROR, errorInfo.toString());
    _12
    }
    _12
    });

    Messages

    Sending and receiving messages is the most basic function of the Signaling service. Any message sent by the Signaling server can be delivered to any online subscribing user within 100 ms. Depending on your business requirements, you can send messages to one user only or broadcast messages to multiple users.

    Signaling offers two types of channels: message channels and stream channels. These channel types have the following differences in how messages are transmitted and methods are called:

    • Message Channel: The real-time channel. Messages are transmitted through the channel, and the channel is highly scalable. Local users can call the publish method to send messages in the channel, and remote users can call the subscribe method to subscribe to the channel and receive messages.
    • Stream Channel: The streaming transmission channel. Messages are transmitted through the topic. Users need to join a channel first, and then join a topic. Local users can call the publishTopicMessage method to send messages in the topic, and remote users can call the subscribeTopic method to subscribe to the topic and receive messages.

    This page introduces how to send and receive messages in a Message Channel.

    publish

    Description

    You can directly call the publish method to send messages to all online users subscribed to this channel. Even if you do not subscribe to the channel, you can still send messages in the channel.
    Information
    The following practices can effectively improve the reliability of message transmission:
    • The message payload should be within 32 KB; otherwise, the sending will fail.
    • The upper limit of the rate at which messages are sent to a single channel is 30 QPS. If the sending rate exceeds the limit, some messages will be discarded. A lower rate is better, as long as the requirements are met.
    • Signaling does not guarantee that the order in which all subscribers receive messages is the same as the order in which the sender sends messages. If you want to ensure that messages are strictly ordered, Agora suggests that you customize the message sequence number in the message payload.

    After successfully calling this method, the SDK triggers a onMessageEvent event notification. Users who subscribe to the channel and enabled the event listener can receive this event notification. For details, see Event Listeners.

    Method

    You can call the publish method in the following way:


    _7
    // publish [1/2]
    _7
    void publish(
    _7
    String channelName,
    _7
    String message,
    _7
    PublishOptions options,
    _7
    ResultCallback<Void> resultCallback
    _7
    );


    _7
    // publish [2/2]
    _7
    void publish(
    _7
    String channelName,
    _7
    byte[] message,
    _7
    PublishOptions options,
    _7
    ResultCallback<Void> resultCallback
    _7
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name. You can only send messages to one channel at a time.
    messageString\byte[]Required-Message payload.
    optionsPublishOptionsRequired-Message options.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • The options parameter contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    sendTslongOptional0The timestamp when the SDK sends a message. This parameter is invalid in the Message Channel.
    customTypeStringOptional-A user-defined field. Only supports string type.

    Basic usage

    Example 1: Send string messages to a specified channel.


    _14
    String message = "Hello world";
    _14
    PublishOptions options = new PublishOptions();
    _14
    options.customType = 'PlainText';
    _14
    rtmClient.publish("my_channel", message, options, new ResultCallback<Void>() {
    _14
    @Override
    _14
    public void onSuccess(Void responseInfo) {
    _14
    log(CALLBACK, "send message to channel success");
    _14
    }
    _14
    _14
    @Override
    _14
    public void onFailure(ErrorInfo errorInfo) {
    _14
    log(ERROR, errorInfo.toString());
    _14
    }
    _14
    });

    Example 2: Send byte messages to a specified channel.


    _14
    byte[] message = new byte[] {1, 2, 3, 4};
    _14
    PublishOptions options = new PublishOptions();
    _14
    options.customType = 'ByteArray';
    _14
    rtmClient.publish("my_channel", message, options, new ResultCallback<Void>() {
    _14
    @Override
    _14
    public void onSuccess(Void responseInfo) {
    _14
    log(CALLBACK, "send message to channel success");
    _14
    }
    _14
    _14
    @Override
    _14
    public void onFailure(ErrorInfo errorInfo) {
    _14
    log(ERROR, errorInfo.toString());
    _14
    }
    _14
    });

    Receive

    Signaling provides event notifications for messages, states, and event changes. By setting up event listeners, you can receive messages and events within subscribed channels.

    For information on how to add and set event listeners, see Event Listeners.

    Presence

    The presence feature provides the ability to monitor user online, offline, and user historical state change. With the Presence feature, you can get real-time access to the following information:

    • Real-time event notification when a user joins or leaves a specified channel.
    • Real-time event notification when the custom temporary user state changes.
    • Query which channels a specified user has joined or subscribed to.
    • Query which users have joined a specified channel and their temporary user state data.
    Information
    Presence applies to both message channels and stream channels.

    getOnlineUsers

    Description

    By calling the getOnlineUsers method, you can query real-time information about the number of online users, the list of online users, and the temporary state of online users in a specified channel.

    Method

    You can call the getOnlineUsers method in the following way:


    _6
    void getOnlineUsers(
    _6
    String channelName,
    _6
    RtmChannelType channelType,
    _6
    GetOnlineUsersOptions options,
    _6
    ResultCallback<GetOnlineUsersResult> resultCallback
    _6
    );

    ParametersTypeRequiredDefaultDescription
    channelNamestringRequired-Channel name.
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    optionsGetOnlineUsersOptionsRequired-Query options.
    resultCallbackResultCallback<GetOnlineUsersResult>Required-Callback of invocation result:
  • Success: Executes the onSuccess method and return the GetOnlineUsersResult query result.
  • Failure: Executes the onFailure method and return an error result.
  • The options parameter contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    includeUserIdbooleanOptionaltrueWhether the returned result includes the user ID of online members.
    includeStatebooleanOptionalfalseWhether the returned result includes temporary state data of online users.
    pageStringOptional-Page number of the returned result. If you do not provide this property, the SDK returns the first page by default. You can check whether there is next page in the returned result.

    GetOnlineUsersResult data contains the following properties:

    PropertiesTypeDescription
    nextPageStringPage number of the next page. Confirm whether there is a next page:
  • A null value indicates that next page does not exist.
  • A non-null value indicates that there is a next page. You can fill this value in the page property of the getOnlineUsers method to query the next page results.
  • userStateListArrayList<UserState>List of online users and their temporary state information in a specified channel.
    totalOccupancylongThe list length of UserStateList. When you set both includeUserId and includeState properties in the getOnlineUsers method to false, this value represents the total number of current online users in the channel.

    Basic usage


    _22
    GetOnlineUsersOptions options = new GetOnlineUsersOptions();
    _22
    options.setIncludeUserId(true);
    _22
    options.setIncludeState(true);
    _22
    options.setPage("yourBookMark");
    _22
    _22
    rtmClient.getPresence().getOnlineUsers("channelName", RtmChannelType.MESSAGE, options, new ResultCallback<GetOnlineUsersResult>() {
    _22
    @Override
    _22
    public void onSuccess(GetOnlineUsersResult result) {
    _22
    log(CALLBACK, "get getOnlineUsers success");
    _22
    for (UserState state : result.getUserStateList()) {
    _22
    log(INFO, "user id: " + state.getUserId());
    _22
    for (StateItem item : state.getStates()) {
    _22
    log(INFO, item.toString());
    _22
    }
    _22
    }
    _22
    }
    _22
    _22
    @Override
    _22
    public void onFailure(ErrorInfo errorInfo) {
    _22
    log(ERROR, errorInfo.toString());
    _22
    }
    _22
    });

    getUserChannels

    Description

    In scenarios such as statistic analytics and debugging, you may need to know all the channels that a specified user has subscribed to or joined. Call the getUserChannels method to get the list of channels where the specified user is in real time.

    Method

    You can call the getUserChannels method in the following way:


    _4
    void getUserChannels(
    _4
    String userId,
    _4
    ResultCallback<ArrayList<ChannelInfo>> resultCallback
    _4
    );

    ParametersTypeRequiredDefaultDescription
    userIdstringRequired-User ID.
    resultCallbackResultCallback<ArrayList<ChannelInfo>>Required-Callback of invocation result:
  • Success: Executes the onSuccess method and return the ArrayList<ChannelInfo> query result.
  • Failure: Executes the onFailure method.
  • ChannelInfo data type contains the following properties:

    PropertiesTypeDescription
    channelNameStringChannel name.
    channelTypeRtmChannelTypeChannel types. See RtmChannelType.

    Basic usage


    _14
    rtmClient.getPresence().getUserChannels("Tony", new ResultCallback<ArrayList<ChannelInfo>>() {
    _14
    @Override
    _14
    public void onSuccess(ArrayList<ChannelInfo> channels) {
    _14
    log(CALLBACK, "get " + queryUserId + " getUserChannels success");
    _14
    for (ChannelInfo channel : channels) {
    _14
    log(INFO, channel.toString());
    _14
    }
    _14
    }
    _14
    _14
    @Override
    _14
    public void onFailure(ErrorInfo errorInfo) {
    _14
    log(ERROR, errorInfo.toString());
    _14
    }
    _14
    });

    setState

    Description

    To meet different requirements in different business scenarios for setting user states, Signaling provides the setState method to customize the temporary user state. Users can add custom states such as scores, game state, location, mood, and hosting state for themselves.

    After successful setup, as long as the user keeps subscribing to the channel and stays online, the custom states can persist in the channel. setState method sets the temporary user state, and the state disappears when the user leaves the channel or disconnects from Signaling. If you need to restore user states when rejoining a channel or reconnecting, you need to cache the data locally in real time. If you want to permanently save user states, Agora recommends you use the setUserMetadata method of the storage function instead.

    If a user modifies the temporary user state, Signaling triggers the REMOTE_STATE_CHANGED type of the onPresenceEvent event in real time. You can receive the event by subscribing to the channel and configuring the corresponding property.

    Method

    You can call the setState method in the following way:


    _6
    void setState(
    _6
    String channelName,
    _6
    RtmChannelType channelType,
    _6
    ArrayList<StateItem> items,
    _6
    ResultCallback<Void> resultCallback
    _6
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    itemsArrayList<StateItem>Required-User state, an array of StateItem.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • StateItem contains the following properties:

    PropertyTypeDescription
    keystringKey of user status. If the provided key already exists, the new value overwrites the previous one. If the provided key does not exist, a new key-value pair is created.用户状态的键。
    valuestringValue of user status.

    Basic usage


    _14
    ArrayList<StateItem> stateItems = new ArrayList<>();
    _14
    stateItems.add(new StateItem("mood", "pumped"));
    _14
    _14
    rtmClient.getPresence().setState("channelName", RtmChannelType.MESSAGE, stateItems, new ResultCallback<Void>() {
    _14
    @Override
    _14
    public void onSuccess(Void responseInfo) {
    _14
    log(CALLBACK, "set state success");
    _14
    }
    _14
    _14
    @Override
    _14
    public void onFailure(ErrorInfo errorInfo) {
    _14
    log(ERROR, errorInfo.toString());
    _14
    }
    _14
    });

    getState

    Description

    To get the temporary user state of a specified user in the channel, you can use the getState method.

    Method

    You can call the getState method in the following way:


    _6
    void getState(
    _6
    String channelName,
    _6
    RtmChannelType channelType,
    _6
    String userId,
    _6
    ResultCallback<UserState> resultCallback
    _6
    )

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    userIdStringRequired-User ID.
    resultCallbackResultCallback<UserState>Required-Callback of invocation result:
  • Success: Executes the onSuccess method and return the UserState query result.
  • Failure: Executes the onFailure method.
  • The UserState data type contains the following properties:

    PropertiesTypeDescription
    userIdStringUser ID.
    statesArrayList<StateItem>Temporary user state, an array of StateItem.

    StateItem contains the following properties:

    PropertyTypeDescription
    keystringKey of user status. If the provided key already exists, the new value overwrites the previous one. If the provided key does not exist, a new key-value pair is created.用户状态的键。
    valuestringValue of user status.

    _4
    class UserState {
    _4
    String userId; // User ID
    _4
    ArrayList<StateItem> states; // Return user state key-value pairs
    _4
    }

    Basic usage


    _14
    rtmClient.getPresence().getState("channelName", RtmChannelType.MESSAGE, "Tony", new ResultCallback<UserState>() {
    _14
    @Override
    _14
    public void onSuccess(UserState state) {
    _14
    log(CALLBACK, "get users(" + state.getUserId() + ") state success");
    _14
    for (StateItem item : state.getStates()) {
    _14
    log(INFO, item.toString());
    _14
    }
    _14
    }
    _14
    _14
    @Override
    _14
    public void onFailure(ErrorInfo errorInfo) {
    _14
    log(ERROR, errorInfo.toString());
    _14
    }
    _14
    });

    removeState

    Description

    When a temporary user state is no longer needed, you can call the removeState method to remove one or more of your temporary states. When the user state is removed, the user who has subscribed to the channel and enabled the presence event listener receives the REMOTE_STATE_CHANGED type of onPresenceEvent event notification. See Event Listeners.

    Method

    You can call the removeState method in the following way:


    _6
    void removeState(
    _6
    String channelName,
    _6
    RtmChannelType channelType,
    _6
    ArrayList<String> keys,
    _6
    ResultCallback<Void> resultCallback
    _6
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    keysArrayList<String>Required-List of keys to be deleted. ``If you do not provide this property, the SDK removes all states.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • Basic usage


    _12
    ArrayList<String> keys = new ArrayList<>(Arrays.asList("A", "B", "C"));
    _12
    rtmClient.getPresence().removeState("channelName", RtmChannelType.MESSAGE, keys, new ResultCallback<Void>() {
    _12
    @Override
    _12
    public void onSuccess(Void responseInfo) {
    _12
    log(CALLBACK, "remove state success");
    _12
    }
    _12
    _12
    @Override
    _12
    public void onFailure(ErrorInfo errorInfo) {
    _12
    log(ERROR, errorInfo.toString());
    _12
    }
    _12
    });

    Storage

    The storage feature provides a dynamic database mechanism that allows developers to dynamically set, store, update, and delete data such as channel metadata and user metadata.

    setChannelMetadata

    Description

    The setChannelMetadata method sets metadata for a message channel or stream channel. A channel can only have one set of metadata, but each set of metadata can have one or more metadata items. If you call this method multiple times, the SDK retrieves the key of the metadata items in turn and apply settings according to the following rules:

    • If you set metadata with different key, the SDK adds each set of metadata in sequence according to the order of the method calls.
    • If you set metadata with the same key, the value of the last setting overwrites the previous one.

    After successfully setting channel metadata, users who subscribe to the channel and enable event listeners can receive the CHANNEL type of the onStorageEvent event notification. See Event listeners.

    Channel metadata also introduces the version control logic CAS (Compare And Set). This method provides two independent version control fields, and you can set one or more of them according to your actual business scenario:

    • Enable version number verification for the entire set of channel metadata by setting the majorRevision property through the setMajorRevision method in the Metadata data type.
    • Enable version number verification for a single metadata item by setting the revision property in the MetadataItem class.

    When setting channel metadata or metadata items, you can control whether to enable version number verification by specifying the revision property:

    • The default value of the revision property is -1, indicating that this method call does not perform any CAS verification. If the channel metadata or metadata item already exists, the latest value overwrites the previous one. If the channel metadata or metadata item does not exist, the SDK creates it.
    • If the revision property is a positive integer, this method call performs the CAS verification. If the channel metadata or metadata item already exists, the SDK updates the corresponding value after the version number verification succeeds. If the channel metadata or metadata item does not exist, the SDK returns the error code.

    Method

    You can call the setChannelMetadata method in the following way:


    _8
    void setChannelMetadata(
    _8
    String channelName,
    _8
    RtmChannelType channelType,
    _8
    Metadata data,
    _8
    MetadataOptions options,
    _8
    String lockName,
    _8
    ResultCallback<Void> resultCallback
    _8
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    dataMetadataRequired-Metadata item. See Metadata.
    optionsMetadataOptionsRequired-Options for setting the channel metadata.
    lockNameStringRequired-Lock name. If set, only users who call the acquireLock method to acquire the lock can perform operations.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • The MetadataOptions data type contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    recordTsbooleanOptionalfalseWhether to record the timestamp of the edits.
    recordUserIdbooleanOptionalfalseWhether to record the user ID of the editor.

    Basic usage


    _23
    // Create a metadata instance
    _23
    Metadata metadata = rtmClient.getStorage().createMetadata();
    _23
    // Set the Major Revision
    _23
    metadata.setMajorRevision(174298270);
    _23
    // Add a metadata item
    _23
    metadata.setMetadataItem(new MetadataItem("Apple", "100", 174298200));
    _23
    // Add another metadata item
    _23
    metadata.setMetadataItem(new MetadataItem("Banana", "200", 174298100));
    _23
    // Record who and when set the metadata
    _23
    MetadataOptions options = new MetadataOptions();
    _23
    options.setRecordTs(true);
    _23
    options.setRecordUserId(true);
    _23
    _23
    rtmClient.getStorage().setChannelMetadata("channel_name", RtmChannelType.MESSAGE, metadata, options, "lockName", new ResultCallback<Void>() {
    _23
    @Override
    _23
    public void onSuccess(Void responseInfo) {
    _23
    log(CALLBACK, "update channel metadata success");
    _23
    }
    _23
    @Override
    _23
    public void onFailure(ErrorInfo errorInfo) {
    _23
    log(ERROR, errorInfo.toString());
    _23
    }
    _23
    });

    getChannelMetadata

    Description

    The getChannelMetadata method can get the metadata of the specified channel.

    Method

    You can call the getChannelMetadata method in the following way:


    _5
    void getChannelMetadata(
    _5
    String channelName,
    _5
    RtmChannelType channelType,
    _5
    ResultCallback<Metadata> resultCallback
    _5
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    resultCallbackResultCallback<Metadata>Required-Callback of invocation result:
  • Success: Executes the onSuccess method and return the Metadata query result.
  • Failure: Executes the onFailure method.
  • Basic usage


    _15
    rtmClient.getStorage().getChannelMetadata("channelName", RtmChannelType.MESSAGE, new ResultCallback<Metadata>() {
    _15
    @Override
    _15
    public void onSuccess(Metadata data) {
    _15
    log(CALLBACK, "get channel metadata success");
    _15
    log(INFO, "metadata major revision: " + data.getMajorRevision());
    _15
    MetadataItem[] metadataItems = data.getMetadataItems();
    _15
    for (MetadataItem item : metadataItems) {
    _15
    log(INFO, item.toString);
    _15
    }
    _15
    }
    _15
    @Override
    _15
    public void onFailure(ErrorInfo errorInfo) {
    _15
    log(ERROR, errorInfo.toString());
    _15
    }
    _15
    });

    removeChannelMetadata

    Description

    The removeChannelMetadata method can remove channel metadata or metadata items.

    When removing channel metadata or metadata items, you can control whether to enable version number verification by specifying the revision property:

    • The default value of the revision property is -1, indicating that this method call does not perform any CAS verification. If the channel metadata or metadata item already exists, the SDK removes it. If the channel metadata or metadata item does not exist, the SDK returns the error code.
    • If the revision property is a positive integer, this method call performs the CAS verification. If the channel metadata or metadata item already exists, the SDK removes the corresponding value after the version number verification succeeds. If the channel metadata or metadata item does not exist, the SDK returns the error code.

    After successfully removing channel metadata or metadata items, users who subscribe to the channel and enable event listeners can receive the CHANNEL type of the onStorageEvent event notification. See Event listeners.

    Method

    You can call the removeChannelMetadata method in the following way:


    _8
    void removeChannelMetadata(
    _8
    String channelName,
    _8
    RtmChannelType channelType,
    _8
    Metadata data,
    _8
    MetadataOptions options,
    _8
    String lockName,
    _8
    ResultCallback<Void> resultCallback
    _8
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    dataMetadataRequired-Metadata item. See Metadata.
    optionsMetadataOptionsRequired-Options for setting the channel metadata.
    lockNameStringRequired-Lock name. If set, only users who call the acquireLock method to acquire the lock can perform operations.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • The MetadataOptions data type contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    recordTsbooleanOptionalfalseWhether to record the timestamp of the edits.
    recordUserIdbooleanOptionalfalseWhether to record the user ID of the editor.

    Basic usage


    _22
    // Create a metadata instance
    _22
    Metadata metadata = rtmClient.getStorage().createMetadata();
    _22
    // Set the Major Revision
    _22
    metadata.setMajorRevision(174298270);
    _22
    // Add a metadata item
    _22
    MetadataItem item = new MetadataItem();
    _22
    item.setKey("Apple");
    _22
    item.setRevision(174298200);
    _22
    metadata.setMetadataItem(item);
    _22
    //Record who and when set the metadata
    _22
    MetadataOptions options = new MetadataOptions();
    _22
    _22
    rtmClient.getStorage().removeChannelMetadata("channel_name", RtmChannelType.MESSAGE, metadata, options, "", new ResultCallback<Void>() {
    _22
    @Override
    _22
    public void onSuccess(Void responseInfo) {
    _22
    log(CALLBACK, "remove channel metadata success");
    _22
    }
    _22
    @Override
    _22
    public void onFailure(ErrorInfo errorInfo) {
    _22
    log(ERROR, errorInfo.toString());
    _22
    }
    _22
    });

    updateChannelMetadata

    Description

    The updateChannelMetadata method can update existing channel metadata. Each time you call this method, you can update one channel metadata or a channel metadata item.

    After successfully updating channel metadata, users who subscribe to the channel and enable event listeners can receive the CHANNEL type of the onStorageEvent event notification. See Event listeners.

    Information
    You cannot use this method to update metadata items which do not exist.

    Method

    You can call the updateChannelMetadata method in the following way:


    _8
    void updateChannelMetadata(
    _8
    String channelName,
    _8
    RtmChannelType channelType,
    _8
    Metadata data,
    _8
    MetadataOptions options,
    _8
    String lockName,
    _8
    ResultCallback<Void> resultCallback
    _8
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    dataMetadataRequired-Metadata item. See Metadata.
    optionsMetadataOptionsRequired-Options for setting the channel metadata.
    lockNameStringRequired-Lock name. If set, only users who call the acquireLock method to acquire the lock can perform operations.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • The options parameter contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    recordTsbooleanOptionalfalseWhether to record the timestamp of the edits.
    recordUserIdbooleanOptionalfalseWhether to record the user ID of the editor.

    Basic usage


    _19
    // Create a metadata instance
    _19
    Metadata metadata = rtmClient.getStorage().createMetadata();
    _19
    // Set the Major Revision
    _19
    metadata.setMajorRevision(174298270);
    _19
    // Add a metadata item
    _19
    metadata.setMetadataItem(new MetadataItem("Apple", "120", 174298200));
    _19
    // Add another metadata item
    _19
    metadata.setMetadataItem(new MetadataItem("Banana", "220", 174298100));
    _19
    _19
    rtmClient.getStorage().updateChannelMetadata("channel_name", RtmChannelType.MESSAGE, metadata, new MetadataOptions(true, true), "lockName", new ResultCallback<Void>() {
    _19
    @Override
    _19
    public void onSuccess(Void responseInfo) {
    _19
    log(CALLBACK, "update channel metadata success");
    _19
    }
    _19
    @Override
    _19
    public void onFailure(ErrorInfo errorInfo) {
    _19
    log(ERROR, errorInfo.toString());
    _19
    }
    _19
    });

    setUserMetadata

    Description

    The setUserMetadata method can set metadata for a user. If you call this method multiple times, the SDK retrieves the key of the metadata items in turn and apply settings according to the following rules:

    • If you set metadata with different key, the SDK adds each set of metadata in sequence according to the order of the method calls.
    • If you set metadata with the same key, the value of the last setting overwrites the previous one.

    After successfully setting user metadata, users who subscribe to the user and enable event listeners can receive the USER type of the onStorageEvent event notification. See Event listeners.

    User metadata also introduces the version control logic CAS (Compare And Set). This method provides two independent version control fields, and you can set one or more of them according to your actual business scenario:

    • Enable version number verification for the entire set of channel metadata by setting the majorRevision property through the setMajorRevision method in the Metadata data type.
    • Enable version number verification for a single metadata item by setting the revision property in the MetadataItem class.

    When setting user metadata or metadata items, you can control whether to enable version number verification by specifying the revision property:

    • The default value of the revision property is -1, indicating that this method call does not perform any CAS verification. If the user metadata or metadata item already exists, the latest value overwrites the previous one. If the user metadata or metadata item does not exist, the SDK creates it.
    • If the revision property is a positive integer, this method call performs the CAS verification. If the user metadata or metadata item already exists, the SDK updates the corresponding value after the version number verification succeeds. If the user metadata or metadata item does not exist, the SDK returns the error code.

    Method

    You can call the setUserMetadata method in the following way:


    _6
    void setUserMetadata(
    _6
    String userId,
    _6
    Metadata data,
    _6
    MetadataOptions options,
    _6
    ResultCallback<Void> resultCallback
    _6
    );

    ParametersTypeRequiredDefaultDescription
    userIdStringRequired-User ID.
    dataMetadataRequired-Metadata item. See Metadata.
    optionsMetadataOptionsRequired-Options for setting the channel metadata.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • The options parameter contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    recordTsbooleanOptionalfalseWhether to record the timestamp of the edits.
    recordUserIdbooleanOptionalfalseWhether to record the user ID of the editor.

    Basic usage


    _19
    // Create a metadata instance
    _19
    Metadata metadata = mRtmClient.getStorage().createMetadata();
    _19
    // Set the Major Revision
    _19
    metadata.setMajorRevision(174298270);
    _19
    // Add a metadata item
    _19
    metadata.setMetadataItem(new MetadataItem("Name", "Tony", 174298200));
    _19
    // Add another metadata item
    _19
    metadata.setMetadataItem(new MetadataItem("Mute", "true", 174298100));
    _19
    _19
    rtmClient.getStorage().setUserMetadata(userName, mMetadata, new MetadataOptions(true, true), new ResultCallback<Void>() {
    _19
    @Override
    _19
    public void onSuccess(Void responseInfo) {
    _19
    log(CALLBACK, "set user metadata success");
    _19
    }
    _19
    @Override
    _19
    public void onFailure(ErrorInfo errorInfo) {
    _19
    log(ERROR, errorInfo.toString());
    _19
    }
    _19
    });

    getUserMetadata

    Description

    The getUserMetadata method can get the metadata and metadata item for the specified user.

    Method

    You can call the getUserMetadata method in the following way:


    _4
    void getUserMetadata(
    _4
    String userId,
    _4
    ResultCallback<Metadata> resultCallback
    _4
    );

    ParametersTypeRequiredDefaultDescription
    userIdStringRequired-User ID.``
    resultCallbackResultCallback<Metadata>Required-Callback of invocation result:
  • Success: Executes the onSuccess method and return the Metadata query result.
  • Failure: Executes the onFailure method.
  • Basic usage


    _15
    rtmClient.getStorage().getUserMetadata("userName", new ResultCallback<Metadata>() {
    _15
    @Override
    _15
    public void onSuccess(Metadata data) {
    _15
    log(CALLBACK, "get user metadata success");
    _15
    MetadataItem[] items = data.getMetadataItems();
    _15
    log(INFO, "major revision: " + data.getMajorRevision());
    _15
    for (MetadataItem item : items) {
    _15
    log(INFO, item.toString());
    _15
    }
    _15
    }
    _15
    @Override
    _15
    public void onFailure(ErrorInfo errorInfo) {
    _15
    log(ERROR, errorInfo.toString());
    _15
    }
    _15
    });

    removeUserMetadata

    Description

    The removeUserMetadata method can remove user metadata or metadata items.

    After successfully removing user metadata, users who subscribe to the user and enable event listeners can receive the USER type of the onStorageEvent event notification. See Event listeners.

    Method

    You can call the removeUserMetadata method in the following way:


    _6
    void removeUserMetadata(
    _6
    String userId,
    _6
    Metadata data,
    _6
    MetadataOptions options,
    _6
    ResultCallback<Void> resultCallback
    _6
    );

    ParametersTypeRequiredDefaultDescription
    userIdStringRequired-User ID.
    dataMetadataRequired-Metadata item. See Metadata.
    optionsMetadataOptionsRequired-Options for setting the channel metadata.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • The options parameter contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    recordTsbooleanOptionalfalseWhether to record the timestamp of the edits.
    recordUserIdbooleanOptionalfalseWhether to record the user ID of the editor.

    Basic usage


    _22
    // Create a metadata instance
    _22
    Metadata metadata = rtmClient.getStorage().createMetadata();
    _22
    // Set the Major Revision
    _22
    metadata.setMajorRevision(174298270);
    _22
    // Add a metadata item
    _22
    MetadataItem item = new MetadataItem();
    _22
    item.setKey("Mute");
    _22
    item.setRevision(174298100);
    _22
    metadata.setMetadataItem(item);
    _22
    // Record who and when set the metadata
    _22
    MetadataOptions options = new MetadataOptions();
    _22
    _22
    rtmClient.getStorage().removeUserMetadata("Tony", metadata, options, new ResultCallback<Void>() {
    _22
    @Override
    _22
    public void onSuccess(Void responseInfo) {
    _22
    log(CALLBACK, "remove user metadata success");
    _22
    }
    _22
    @Override
    _22
    public void onFailure(ErrorInfo errorInfo) {
    _22
    log(ERROR, errorInfo.toString());
    _22
    }
    _22
    });

    updateUserMetadata

    Description

    The updateUserMetadata method can update existing user metadata. After successfully updating channel metadata, users who subscribe to the user and enable event listeners can receive the USER type of the onStorageEvent event notification. See Event listeners.
    Information
    You cannot use this method to update metadata items which do not exist.

    Method

    You can call the updateUserMetadata method in the following way:


    _6
    void updateUserMetadata(
    _6
    String userId,
    _6
    Metadata data,
    _6
    MetadataOptions options,
    _6
    ResultCallback<Void> resultCallback
    _6
    );

    ParametersTypeRequiredDefaultDescription
    userIdStringRequired-User ID.
    dataMetadataRequired-Metadata item. See Metadata.
    optionsMetadataOptionsRequired-Options for setting the channel metadata.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • The MetadataOptions data type contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    recordTsbooleanOptionalfalseWhether to record the timestamp of the edits.
    recordUserIdbooleanOptionalfalseWhether to record the user ID of the editor.

    Basic usage


    _21
    // Create a metadata instance
    _21
    Metadata metadata = mRtmClient.getStorage().createMetadata();
    _21
    // Set the Major Revision
    _21
    metadata.setMajorRevision(174298270);
    _21
    // Add a metadata item
    _21
    metadata.setMetadataItem(new MetadataItem("Mute", "false", 174298100));
    _21
    // Record who and when set the metadata
    _21
    MetadataOptions options = new MetadataOptions();
    _21
    options.setRecordTs(true);
    _21
    options.setRecordUserId(true);
    _21
    _21
    rtmClient.getStorage().updateUserMetadata("Tony", metadata, options, new ResultCallback<Void>() {
    _21
    @Override
    _21
    public void onSuccess(Void responseInfo) {
    _21
    log(CALLBACK, "update user metadata success");
    _21
    }
    _21
    @Override
    _21
    public void onFailure(ErrorInfo errorInfo) {
    _21
    log(ERROR, errorInfo.toString());
    _21
    }
    _21
    });

    subscribeUserMetadata

    Description

    The subscribeUserMetadata method can subscribe to metadata for a specified user. After successfully subscribing to the user metadata, you can receive the USER type of the onStorageEvent event notification when the metadata for that user changes. See Event listeners.

    Method

    You can call the subscribeUserMetadata method in the following way:


    _4
    void subscribeUserMetadata(
    _4
    String userId,
    _4
    ResultCallback<Void> resultCallback
    _4
    );

    ParametersTypeRequiredDefaultDescription
    userIdStringRequired-User ID.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • Basic usage


    _10
    rtmClient.getStorage().subscribeUserMetadata("Tony", new ResultCallback<Void>() {
    _10
    @Override
    _10
    public void onSuccess(Void responseInfo) {
    _10
    log(CALLBACK, "subscribe user metadata success");
    _10
    }
    _10
    @Override
    _10
    public void onFailure(ErrorInfo errorInfo) {
    _10
    log(ERROR, errorInfo.toString());
    _10
    }
    _10
    });

    unsubscribeUserMetadata

    Description

    If you do not need to receive notifications of changes to a user metadata, call the unsubscribeUserMetadata method to unsubscribe.

    Method

    You can call the unsubscribeUserMetadata method in the following way:


    _4
    void unsubscribeUserMetadata(
    _4
    String userId,
    _4
    ResultCallback<Void> resultCallback
    _4
    );

    ParametersTypeRequiredDefaultDescription
    userIdStringRequired-User ID.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • Basic usage


    _10
    rtmClient.getStorage().unsubscribeUserMetadata("Tony", new ResultCallback<Void>() {
    _10
    @Override
    _10
    public void onSuccess(Void responseInfo) {
    _10
    log(CALLBACK, "unsubscribe user metadata success");
    _10
    }
    _10
    @Override
    _10
    public void onFailure(ErrorInfo errorInfo) {
    _10
    log(ERROR, errorInfo.toString());
    _10
    }
    _10
    });

    Metadata

    Description

    The Metadata data type provides methods for setting and getting metadata items and their versions.

    Method

    You can call the relevant methods in the following ways:


    _7
    class Metadata {
    _7
    void setMajorRevision(long revision);
    _7
    long getMajorRevision();
    _7
    void setMetadataItem(MetadataItem item);
    _7
    MetadataItem[] getMetadataItems();
    _7
    void clearMetadata();
    _7
    }

    MethodsDescription
    Sets the version control switch:
  • -1: Disable the version verification.
  • > 0: Enable the version verification. The operation can only be performed if the target version number matches this value.
  • Gets major revision.
    Sets metadata items.
    Gets metadata items.

    The MetadataItem data type contains the following properties:

    PropertiesTypeRequiredDefaultDescription
    keyStringOptional-Key.
    valueStringOptional-Value.
    authorUserIdStringOptional-The user ID of the editor. This value is read-only and does not support writing.
    revisionlongOptional-1
  • Returns the real version number in read operations.
  • Serves as a version control switch in write operations:
    • -1: Disable the version verification.
    • > 0: Enable version verification, only perform the operation if the target version number matches this value.
    updateTslongOptional0Update timestamp. This value is read-only and does not support writing.

    Basic usage


    _17
    // Set metadata
    _17
    Metadata metadata = mRtmClient.getStorage().createMetadata();
    _17
    metadata.setMajorRevision(174298270);
    _17
    // new MetadataItem
    _17
    MetadataItem item1 = new MetadataItem();
    _17
    item1.setKey("Name");
    _17
    item1.setValue("Tony");
    _17
    item1.setRevision(174298200);
    _17
    // or MetadataItem item1 = new MetadataItem("Name", "Tony", 174298200);
    _17
    metadata.setMetadataItem(item1);
    _17
    _17
    // Get metadata
    _17
    long majorRevision = metadata.getMajorRevision();
    _17
    MetadataItem[] items = metadata.getMetadataItems();
    _17
    for (MetadataItem item : items) {
    _17
    log(INFO, item.toString());
    _17
    }

    Lock

    A critical resource can only be used by one process at a time. If a critical resource is shared between different processes, each process needs to adopt a mutually exclusive method to prevent mutual interference. Signaling provides a full set of lock solutions. By controlling different processes in a distributed system, you can solve the competition problem when users access shared resources.

    Information
    The client is able to set, remove, and revoke locks. We recommend that you control the permissions of these operations on the client side based on your business needs.

    setLock

    Description

    You need to configure the lock name, time to live (TTL) and other parameters by calling the setLock method. If the configuration succeeds, all users in the channel receives the onLockEvent event notifications of the SET type. For details, see Event Listeners.

    Method

    You can call the setLock method in the following way:


    _7
    void setLock(
    _7
    String channelName,
    _7
    RtmChannelType channelType,
    _7
    String lockName,
    _7
    long ttl,
    _7
    ResultCallback<Void> resultCallback
    _7
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    lockNameStringRequired-Lock name.
    ttllongRequired-The expiration time of the lock. The value is in seconds, ranging from [10 to 300]. When the user who owns the lock goes offline, if the user returns to the channel within the time they can still use the lock; otherwise, the lock is released and the users who listen for the onLockEvent event receives the RELEASED event.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • Basic usage


    _12
    long ttl = 30;
    _12
    rtmClient.getLock().setLock("my_channel", RtmChannelType.STREAM, "my_lock", ttl, new ResultCallback<Void>() {
    _12
    @Override
    _12
    public void onSuccess(Void responseInfo) {
    _12
    log(CALLBACK, "set lock success");
    _12
    }
    _12
    _12
    @Override
    _12
    public void onFailure(ErrorInfo errorInfo) {
    _12
    log(ERROR, errorInfo.toString());
    _12
    }
    _12
    });

    acquireLock

    Description

    After successfully configuring a lock, you can call the acquireLock method on the client to acquire the right to own the lock. When you acquire the lock, other users in the channel receives the ACQUIRED type of the onLockEvent event. For details, see Event Listeners.

    Method

    You can call the acquireLock method in the following way:


    _7
    void acquireLock(
    _7
    String channelName,
    _7
    RtmChannelType channelType,
    _7
    String lockName,
    _7
    boolean retry,
    _7
    ResultCallback<Void> resultCallback
    _7
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    lockNameStringRequired-Lock name.
    retrybooleanRequired-If the lock acquisition fails, whether to retry until the acquisition succeeds or the user leaves the channel.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • Basic usage


    _12
    boolean retry = false;
    _12
    rtmClient.getLock().acquireLock("chat_room", RtmChannelType.STREAM, "my_lock", retry, new ResultCallback<Void>() {
    _12
    @Override
    _12
    public void onSuccess(Void responseInfo) {
    _12
    log(CALLBACK, "acquire lock success");
    _12
    }
    _12
    _12
    @Override
    _12
    public void onFailure(ErrorInfo errorInfo) {
    _12
    log(ERROR, errorInfo.toString());
    _12
    }
    _12
    });

    release

    Description

    When a user no longer needs to own a lock, the user can call the releaseLock method on the client side to release the lock. After successful release the lock, other users in the channel receives the RELEASED type of the onLockEvent event. See Event Listeners.

    At this time, if other users want to acquire the lock, they can call the acquireLock method on the client side to compete. New users acquiring locks have the same contention priority as the users who set the retry property to automatically retry to acquire locks.

    Method

    You can call the releaseLock method in the following way:


    _6
    void releaseLock(
    _6
    String channelName,
    _6
    RtmChannelType channelType,
    _6
    String lockName,
    _6
    ResultCallback<Void> resultCallback
    _6
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    lockNameStringRequired-Lock name.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • Basic usage


    _11
    rtmClient.getLock().releaseLock("chat_room", RtmChannelType.STREAM, "my_lock", new ResultCallback<Void>() {
    _11
    @Override
    _11
    public void onSuccess(Void responseInfo) {
    _11
    log(CALLBACK, "release lock success");
    _11
    }
    _11
    _11
    @Override
    _11
    public void onFailure(ErrorInfo errorInfo) {
    _11
    log(ERROR, errorInfo.toString());
    _11
    }
    _11
    });

    revokeLock

    Description

    When the lock is occupied, to ensure that your business is not affected, you may need to revoke the lock and give other users a chance to obtain it. Revoke the occupied lock by calling revokeLock. When the lock is revoked, all users in the channel receives the RELEASED type of the onLockEvent event. See Event Listeners.

    At this time, if other users want to acquire the lock, they can call the acquireLock method on the client side to compete. New users acquiring locks have the same contention priority as the users who set the retry property to automatically retry to acquire locks.

    Method

    You can call the revokeLock method in the following way:


    _7
    void revokeLock(
    _7
    String channelName,
    _7
    RtmChannelType channelType,
    _7
    String lockName,
    _7
    String owner,
    _7
    ResultCallback<Void> resultCallback
    _7
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    lockNameStringRequired-Lock name.
    ownerStringRequired-The ID of the user who has a lock.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • Basic usage


    _12
    String lockOwner = "Tony";
    _12
    rtmClient.getLock().revokeLock("chat_room", RtmChannelType.STREAM, "my_lock", lockOwner, new ResultCallback<Void>() {
    _12
    @Override
    _12
    public void onSuccess(Void responseInfo) {
    _12
    log(CALLBACK, "revoke lock(" + lockName + ") success");
    _12
    }
    _12
    _12
    @Override
    _12
    public void onFailure(ErrorInfo errorInfo) {
    _12
    log(ERROR, errorInfo.toString());
    _12
    }
    _12
    });

    getLocks

    Description

    If you want to query the lock information such as lock total number, lock name, and lock user, time to live, you can call the getLocks method on the client.

    Method

    You can call the getLocks method in the following way:


    _5
    void getLocks(
    _5
    String channelName,
    _5
    RtmChannelType channelType,
    _5
    ResultCallback<ArrayList<LockDetail>> resultCallback
    _5
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    resultCallbackResultCallback<ArrayList<LockDetail>>Required-
  • Success: Executes the onSuccess method and return the LockDetail data type.
  • Failure: Executes the onFailure method.
  • The LockDetail data type contains the following properties:

    PropertiesTypeDescription
    lockNameStringLock name.
    lockOwnerStringThe ID of the user who has a lock.
    ttlintThe expiration time of the lock. The value is in seconds, ranging from [10 to 300]. When the user who owns the lock goes offline, if the user returns to the channel within the time they can still use the lock; otherwise, the lock is released and the users who listen for the onLockEvent event receives the RELEASED event.

    Basic usage


    _15
    rtmClient.getLock().getLocks("chat_room", RtmChannelType.STREAM, new ResultCallback<ArrayList<LockDetail>>() {
    _15
    @Override
    _15
    public void onSuccess(ArrayList<LockDetail> details) {
    _15
    log(CALLBACK, "get channel locks success");
    _15
    _15
    for (LockDetail detail : details) {
    _15
    log(INFO, "lock name: " + detail.lockName + ", lock owner: " + detail.lockOwner + ", ttl: " + detail.ttl);
    _15
    }
    _15
    }
    _15
    _15
    @Override
    _15
    public void onFailure(ErrorInfo errorInfo) {
    _15
    log(ERROR, errorInfo.toString());
    _15
    }
    _15
    });

    removeLock

    Description

    If you no longer need a lock, you can call the removeLock method to remove the lock. After successfully removing the lock, all users in the channel receives the REMOVED type of onLockEvent event notification. See Event Listeners.

    Method

    You can call the removeLock method in the following way:


    _6
    void removeLock(
    _6
    String channelName,
    _6
    RtmChannelType channelType,
    _6
    String lockName,
    _6
    ResultCallback<Void> resultCallback
    _6
    );

    ParametersTypeRequiredDefaultDescription
    channelNameStringRequired-Channel name.
    channelTypeRtmChannelTypeRequired-Channel types. See RtmChannelType.
    lockNameStringRequired-Lock name.
    resultCallbackResultCallback<Void>Required-Callback of invocation result:
  • Success: Executes the onSuccess method.
  • Failure: Executes the onFailure method.
  • Basic usage


    _11
    rtmClient.getLock().removeLock("chat_room", RtmChannelType.STREAM, "my_lock", new ResultCallback<Void>() {
    _11
    @Override
    _11
    public void onSuccess(Void responseInfo) {
    _11
    log(CALLBACK, "remove lock success");
    _11
    }
    _11
    _11
    @Override
    _11
    public void onFailure(ErrorInfo errorInfo) {
    _11
    log(ERROR, errorInfo.toString());
    _11
    }
    _11
    });

    Enumerated types

    Enum

    RtmAreaCode

    The region for connection, which is the region where the server the SDK connects to is located.
    ValueDescription
    CN0x00000001: Mainland China.
    NA0x00000002: North America.
    EU0x00000004: Europe.
    AS0x00000008: Asia, excluding Mainland China.
    JP0x00000010: Japan.
    IN0x00000020: India.
    GLOB0xFFFFFFFF: Global.

    RtmChannelType

    Channel types.
    ValueDescription
    MESSAGE1: Message channel.
    STREAM2: Stream channel.

    RtmConnectionChangeReason

    Reasons causing the change of the connection state.
    ValueDescription
    CONNECTING0: The SDK is connecting with the server.
    JOIN_SUCCESS1: The SDK has joined the channel successfully.
    INTERRUPTED2: The connection between the SDK and the server is interrupted.
    BANNED_BY_SERVER3: The connection between the SDK and the server is banned by the server.
    JOIN_FAILED4: The SDK fails to join the channel. When the SDK fails to join the channel for more than 20 minutes, this error occurs and the SDK stops reconnecting to the channel.
    LEAVE_CHANNEL5: The SDK has left the channel.
    INVALID_APP_ID6: The connection failed because the App ID is not valid.
    INVALID_CHANNEL_NAME7: The connection failed because the channel name is not valid.
    INVALID_TOKEN8: The connection failed because the token is not valid.
    TOKEN_EXPIRED9: The connection failed because the token is expired.
    REJECTED_BY_SERVER10: The connection is rejected by server.
    SETTING_PROXY_SERVER11: The connection state changed to reconnecting because the SDK has set a proxy server.
    RENEW_TOKEN12: The connection state changed because the token is renewed.
    CLIENT_IP_ADDRESS_CHANGED13: The IP address of the client has changed, possibly because the network type, IP address, or port has been changed.
    KEEP_ALIVE_TIMEOUT14: Timeout for the keep-alive of the connection between the SDK and the server. The connection state changes to reconnecting.
    REJOIN_SUCCESS15: The user has rejoined the channel successfully.
    LOST16: The connection between the SDK and the server is lost.
    ECHO_TEST17: The connection state changes due to the echo test.
    CLIENT_IP_ADDRESS_CHANGED_BY_USER18: The local IP address was changed by the user. The connection state changes to reconnecting.
    SAME_UID_LOGIN19: The user joined the same channel from different devices with the same UID.
    TOO_MANY_BROADCASTERS20: The number of hosts in the channel has reached the upper limit.
    STREAM_CHANNEL_NOT_AVAILABLE22: The stream channel does not exist.
    INCONSISTENT_APPID23: The App ID does not match the token.
    LOGIN_SUCCESS10001: The SDK logs in to the Signaling system.
    LOGOUT10002: The SDK logs out from the Signaling system.
    PRESENCE_NOT_READY10003: Presence service is not ready.

    RtmConnectionState

    SDK connection states.
    ValueDescription
    DISCONNECTED1: The SDK has disconnected with the server.
    CONNECTING2: The SDK is connecting with the server.
    CONNECTED3: The SDK has connected with the server.
    RECONNECTING4: The connection is lost. The SDK is reconnecting with the server.
    FAILED5: The SDK failed to connect with the server.

    RtmEncryptionMode

    Encryption mode.
    ValueDescription
    NONE0: No encryption.
    AES_128_GCM1: AES-128-GCM mode.
    AES_256_GCM2: AES-256-GCM mode.

    RtmLockEventType

    Lock event type.
    ValueDescription
    SNAPSHOT1: The snapshot of the lock when the user joined the channel.
    SET2: The lock is set.
    REMOVED3: The lock is removed.
    ACQUIRED4: The lock is acquired.
    RELEASED5: The lock is released.
    EXPIRED6: The lock expired.

    RtmLogLevel

    Log output levels.
    ValueDescription
    NONE0x0000: No log.
    INFO0x0001: Output the log at the FATAL, ERROR, WARN, or INFO level. We recommend you set to this value.
    WARN0x0002: Output the log at the FATAL, ERROR, WARN level.
    ERROR0x0004: Output the log at the FATAL, ERROR level.
    FATAL0x0008: Output the log at the FATAL level.

    RtmMessagePriority

    Message priority.
    ValueDescription
    HIGHEST0: Highest.
    HIGH1: High.
    NORMAL4: Normal.
    LOW8: Low.

    RtmMessageQos

    QoS guarantee when sending topic messages.
    ValueDescription
    UNORDERED0: Message data is not guaranteed to arrive in order.
    ORDERED1: Message data arrives in order.

    RtmMessageType

    Message type.
    ValueDescription
    BINARY0: Binary type.
    STRING1: String type.

    RtmPresenceEventType

    Presence event type.
    ValueDescription
    SNAPSHOT1: The snapshot of the presence when the user joined the channel.
    INTERVAL2: When users in the channel reach the setting value, the event notifications are sent at intervals rather than in real time.
    REMOTE_JOIN3: A remote user joined the channel.
    REMOTE_LEAVE4: A remote user left the channel.
    REMOTE_TIMEOUT5: A remote user's connection timed out.
    REMOTE_STATE_CHANGED6: A remote user's temporary state changed.
    ERROR_OUT_OF_SERVICE7: The user did not enable presence when joining the channel.

    RtmProxyType

    Cloud proxy type.
    ValueDescription
    NONE0: Do not enable the cloud proxy.
    HTTP1: Enable the cloud proxy for the HTTP protocol.

    RtmStorageEventType

    Storage event type.
    ValueDescription
    SNAPSHOT1: When a user subscribes to channel metadata or user etadata for the first time, or joins a channel, the local user receives notifications of this type of event.
    SET2: Occurs when calling setChannelMetadata or setUserMetadata.
    Caution
    This event only occurs in incremental data update mode.
    UPDATE3: Occurs when calling methods to set, update, or delete the channel metadata or user metadata.
    REMOVE4: Occurs when calling removeChannelMetadata or removeUserMetadata.
    Caution
    This event only occurs in incremental data update mode.

    RtmStorageType

    Storage type.
    ValueDescription
    USER1: User metadata event.
    CHANNEL2: Channel metadata event.

    RtmTopicEventType

    Topic event type.
    ValueDescription
    SNAPSHOT1: The snapshot of the topic when the user joined the channel.
    REMOTE_JOIN2: A remote user joined the channel.
    REMOTE_LEAVE3: A remote user left the channel.

    Troubleshooting

    Refer to the following information for troubleshooting API calls.

    ErrorInfo

    PropertiesTypeDescription
    errorCodeRtmErrorCodeError code for this operation.
    reasonStringError reason for this operation.
    operationStringOperation type.

    To find out the cause of the error and get the corresponding solution, using the errorCode field with the error code.

    Error codes table

    Refer to the following error codes table to identify and troubleshoot the problem:

    Error codeError descriptionCause and solution
    0OKCorrect call
    -10002NOT_LOGINThe user called the API without logging in to Signaling, disconnected due to timeout, or actively logged out. Please log in to Signaling first.
    -10003INVALID_APP_IDInvalid App ID:
    - Check that the App ID is correct.
    - Ensure that Signaling has been activated for the App ID.
    -10005INVALID_TOKENInvalid Token:
    - The token is invalid, check whether the Token Provider generates a valid Signaling Token.
    -10006INVALID_USER_IDInvalid User ID:
    - Check if user ID is empty.
    - Check if the user ID contains illegal characters.
    -10008INVALID_CHANNEL_NAMEInvalid channel name:
    - Check if the channel name is empty.
    - Check if the channel name contains illegal characters.
    -10009TOKEN_EXPIREDToken expired. Call renewToken to reacquire the Token.
    -10010LOGIN_NO_SERVER_RESOURCESServer resources are limited. It is recommended to log in again.
    -10011LOGIN_TIMEOUTLogin timeout. Check whether the current network is stable and switch to a stable network environment.
    -10012LOGIN_REJECTEDSDK login rejected by the server:
    - Check tha Signaling is activated on your App ID.
    - Check if the token or userId is banned.
    -10013LOGIN_ABORTEDSDK login interrupted due to unknown problem:
    - Check that the current network is stable and switch to a stable network environment.
    - The current userId is logged in.
    -10015LOGIN_NOT_AUTHORIZEDNo RTM service permissions. Check that the console opens Signaling services.
    -10018INSTANCE_ALREADY_RELEASEDRepeat rtm instantiation or RTMStreamChannel instantiation.
    -10019The channel type is invalid. SDK only supports the following channel types. Please fill in the correct value:
    • MESSAGE: Message Channel
    • STREAM: Stream Channel
    -10020Message encryption parameters are invalid.
    • Check that the encryption key generated is a String.
    • Check that the generated encryption salt is Uint8Array type and that the length is 32 bytes.
    • Check that the encryption method matches the encryption key and the encryption salt.
    -10021Channel metadata or User Metadata -related API call frequency is exceeding the limit. Please control the call frequency within 10/second.
    -11001CHANNEL_NOT_JOINEDThe user has not joined the channel:
    - The user is not online, offline or has not joined the channel
    - Check for typos in userId.
    -11002CHANNEL_NOT_SUBSCRIBEDThe user has not subscribed to the channel:
    - The user is not online, offline or has not joined the channel
    - Check for typos in userId.
    -11003CHANNEL_EXCEED_TOPIC_USER_LIMITATIONThe number of subscribers to this topic exceeds the limit.
    -11005CHANNEL_INSTANCE_EXCEED_LIMITATIONThe number of created or subscribed channels exceeds the limit. See API usage limits for details.
    -11006CHANNEL_IN_ERROR_STATEChannel is not available. Please recreate the Stream Channel or resubscribe to the Message Channel.
    -11007CHANNEL_JOIN_FAILEDFailed to join this channel:
    - Check if the number of joined channels exceeds the limit.
    - Check if the channel name is illegal.
    - Check if the network is disconnected.
    -11008CHANNEL_INVALID_TOPIC_NAMEInvalid topic name:
    - Check whether the topic name contains illegal characters.
    - Check if the topic name is empty.
    -11009CHANNEL_INVALID_MESSAGEInvalid message. Check whether the message type is legal, Signaling only supports string, Uint8Array type messages.
    -11010CHANNEL_MESSAGE_LENGTH_EXCEED_LIMITATIONMessage length exceeded limit. Check if the message payload size exceeds the limit:
    - Message Channel single message package limit is 32 KB.
    - Stream Channel single message package limit is 1 KB.
    -11012RTM_ERROR_CHANNEL_NOT_AVAILABLEInvalid user list:
    - Check if the user list is empty
    - Check if the user list contains illegal items.
    -11013CHANNEL_TOPIC_NOT_SUBSCRIBEDThe topic is not subscribed.
    -11014CHANNEL_EXCEED_TOPIC_LIMITATIONThe number of topics exceeds the limit.
    -11015CHANNEL_JOIN_TOPIC_FAILEDFailed to join this topic. Check whether the number of added topics exceeds the limit.
    -11016CHANNEL_TOPIC_NOT_JOINEDThe topic has not been joined. To send a message, you need to join the Topic first.
    -11017CHANNEL_TOPIC_NOT_EXISTThe topic does not exist. Check that the topic name is correct.
    -11018CHANNEL_INVALID_TOPIC_METAThe meta parameters in the topic are invalid. Check if the meta parameter exceeds 256 bytes.
    -11019CHANNEL_SUBSCRIBE_TIMEOUTChannel subscription timed out. Check for broken connections.
    -11020CHANNEL_SUBSCRIBE_TOO_FREQUENTThe channel subscription operation is too frequent. Make sure that the subscription operation of the same channel within a 5 seconds interval does not exceed 2 attempts.
    -11021CHANNEL_SUBSCRIBE_FAILEDChannel subscription failed. Check if the number of subscribed channels exceeds the limit.
    -11023CHANNEL_ENCRYPT_MESSAGE_FAILEDMessage encryption failed:
    - Check that the cipherKey is valid.
    - Check that the salt is valid.
    - Check if encryptionMode mode matches the cipherKey and salt.
    -11024CHANNEL_PUBLISH_MESSAGE_FAILEDMessage publishing failed. Check for broken connections.
    -11026CHANNEL_PUBLISH_MESSAGE_TIMEOUTMessage publishing timed out. Check for broken connections.
    -11028CHANNEL_LEAVE_FAILEDFailed to leave the channel. Check for broken connections.
    -11029CHANNEL_CUSTOM_TYPE_LENGTH_OVERFLOWCustom type length overflow. The length of the customType field must to be within 32 characters.
    -11030CHANNEL_INVALID_CUSTOM_TYPEcustomType field is invalid. Check the customType field for illegal characters.
    -12001STORAGE_OPERATION_FAILEDStorage operation failed.
    -12002STORAGE_METADATA_ITEM_EXCEED_LIMITATIONThe number of Storage Metadata Items exceeds the limit.
    -12003STORAGE_INVALID_METADATA_ITEMInvalid Metadata Item.
    -12004STORAGE_INVALID_ARGUMENTInvalid argument.
    -12005STORAGE_INVALID_REVISIONInvalid Revision parameter.
    -12006STORAGE_METADATA_LENGTH_OVERFLOWMetadata overflows.
    -12007STORAGE_INVALID_LOCK_NAMEInvalid Lock name.
    -12008STORAGE_LOCK_NOT_ACQUIREDThe Lock was not acquired.
    -12009STORAGE_INVALID_KEYInvalid Metadata key.
    -12010STORAGE_INVALID_VALUEInvalid metadata value.
    -12011STORAGE_KEY_LENGTH_OVERFLOWMetadata key length overflow.
    -12012STORAGE_VALUE_LENGTH_OVERFLOWMetadata value length overflow.
    -12014STORAGE_OUTDATED_REVISIONOutdated Revision parameter.
    -12015STORAGE_NOT_SUBSCRIBEThis channel is not subscribed.
    -12017STORAGE_SUBSCRIBE_USER_EXCEED_LIMITATIONThe number of subscribers exceeds the limit.
    -12018STORAGE_OPERATION_TIMEOUTStorage operation timed out.
    -12019STORAGE_NOT_AVAILABLEThe Storage service is not available.
    -13001PRESENCE_NOT_CONNECTEDThe user is not connected to the system.
    -13003PRESENCE_INVALID_ARGUMENTInvalid argument.
    -13004PRESENCE_CACHED_TOO_MANY_STATESThe temporary user state cached before joining the channel exceeds the limit. See API usage limits for details.
    -13005PRESENCE_STATE_COUNT_OVERFLOWThe number of temporary user state key/value pairs exceeds the limit. See API usage limits for details.
    -13006PRESENCE_INVALID_STATE_KEYInvalid state key.
    -13008PRESENCE_STATE_KEY_SIZE_OVERFLOWPresence key length overflow.
    -13009PRESENCE_STATE_VALUE_SIZE_OVERFLOWPresence value overflow
    -13010PRESENCE_STATE_DUPLICATE_KEYRepeated state key.
    -13011PRESENCE_USER_NOT_EXISTThe user does not exist.
    -13012PRESENCE_OPERATION_TIMEOUTPresence operation timed out.
    -13013PRESENCE_OPERATION_FAILEDPresence operation failed.
    -14001LOCK_OPERATION_FAILEDLock operation failed.
    -14002LOCK_OPERATION_TIMEOUTLock operation timed out.
    -14003LOCK_OPERATION_PERFORMINGLock operation in progress.
    -14004LOCK_ALREADY_EXISTLock already exists.
    -14005LOCK_INVALID_NAMEInvalid Lock name.
    -14006LOCK_NOT_ACQUIREDThe Lock was not acquired.
    -14007LOCK_ACQUIRE_FAILEDFailed to acquire the Lock.
    -14008LOCK_NOT_EXISTThe Lock does not exist.
    -14009LOCK_NOT_AVAILABLELock service is not available.

    Signaling