API reference
The Signaling SDK API Reference is divided in to the following sections:
Setup
The API reference for the Signaling SDK documents interface descriptions, methods, basic usage, and return values of the Signaling APIs.
RtmConfig
Description
Use theRtmConfig 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 as follows:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
appId | string | Required | - | App ID obtained when creating a project in the Agora Console. |
userId | string | Required | - | 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. |
areaCode | RtmAreaCode | Optional | GLOB | Service area code, you can choose according to the region where your business is deployed. See RtmAreaCode. |
eventListener | RtmEventListener | Required | - | Signaling event notification listener settings. See Event listeners. |
protocolType | RtmProtocolType | Optional | TCP_UDP | Protocol types for message transmission. By default, Signaling utilizes one-way TCP and one-way UDP protocols for transmission. You have the flexibility to modify the protocol types based on your requirements. See RtmProtocolType. |
presenceTimeout | int | Optional | 300 | Presence timeout in seconds, and the value range is [5,300]. This parameter refers the delay imposed by the Signaling server before sending a REMOTE_TIMEOUT event notification to other users once it determines that a client has timed out. If the client reconnects and returns to the channel within the specified time, the Signaling server does not send the REMOTE_TIMEOUT event notification to other participants or delete the temporary user data associated with the user. |
heartbeatInterval | int | Optional | 5 | Heartbeat interval in seconds, and the value range is [5,1800]. This parameter refers to the time interval at which the client sends heartbeat packets to the Signaling server. If the client fails to send heartbeat packets to the Signaling server within the specified time, the Signaling server determines that the client has timed out. Please note that this parameter affects the PCU count, which in turn affects billing. |
useStringUserId | Bool | Optional | true | Whether to use string-type user IDs:
userId parameter is consistent. |
logConfig | RtmLogConfig | Optional | - | Log configuration properties such as the log storage size, storage path, and level. |
proxyConfig | RtmProxyConfig | Optional | - | When using the Proxy feature of Signaling, you need to configure this parameter. |
encryptionConfig | RtmEncryptionConfig | Optional | - | When using the client-side encryption feature of Signaling, you need to configure this parameter. |
privateConfig | RtmPrivateConfig | Optional | - | When using the private deployment 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:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
filePath | String | Optional | - | Log file storage paths. |
fileSizeInKB | int | Optional | 1024 | Log file size in KB, with a value range of [128,1024]. |
level | RtmLogLevel | Optional | INFO | Output level of log information. See RtmLogLevel. |
RtmProxyConfig
Use theRtmProxyConfig instance to set properties related to the client Proxy service. In some restricted network environments, you might need to use this feature.
RtmProxyConfig contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
proxyType | RtmProxyType | Optional | NONE | Proxy protocol type. See RtmProxyType. |
server | String | Optional | - | Proxy server domain name or IP address. |
port | int | Optional | - | Proxy listening port. |
account | String | Optional | - | Proxy login account. |
password | String | Optional | - | Proxy login password. |
RtmEncryptionConfig
Use theRtmEncryptionConfig 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.
RtmEncryptionConfig contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
encryptionMode | RtmEncryptionMode | Optional | NONE | Encryption mode. See RtmEncryptionMode. |
encryptionKey | String | Optional | - | User-defined encryption key, unlimited length. Agora recommends using a 32-byte key. |
encryptionKdfSalt | byte[] | Optional | null | User-defined encryption salt, length is 32 bytes. Agora recommends using OpenSSL to generate salt on the server side. |
RtmPrivateConfig
Use theRtmPrivateConfig instance to set the properties required for the private deployment.
RtmPrivateConfig contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
serviceType | EnumSet<RtmServiceType> | Optional | - | Service type. See RtmServiceType. |
accessPointHosts | ArrayList<String> | Optional | - | An array of server addresses, where you can fill in domain names or IP addresses. |
Basic usage
create
Description
Call thecreate method to create and initialize the Signaling Client instance.
- 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
userIdparameter is globally unique and remains unchanged throughout the user or device's lifecycle.
Method
You can create and initialize an instance as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
config | RtmConfig | Required | - | Initialize the configuration parameters of the Signaling Client. See RtmConfig. |
Basic usage
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 8 types of event notifications, as shown in the following table:
| Event Type | Description |
|---|---|
onPresenceEvent | Receive presence event notifications in subscribed message channels and joined stream channels. See PresenceEvent |
onTopicEvent | Receive all topic event notifications in joined stream channels. See TopicEvent |
onStorageEvent | Receive channel metadata event notifications in subscribed message channels and joined stream channels, and the user metadata event notification of the subscribed users. See StorageEvent |
onLockEvent | Receive lock event notifications in subscribed message channels and joined stream channels. See LockEvent |
onConnectionStateChanged | (Deprecated) Receive event notifications when client connection status changes. For details, see RtmConnectionState and RtmConnectionChangeReason. |
onLinkStateEvent | Receive event notifications when client connection status changes. See LinkStateEvent. |
onTokenPrivilegeWillExpire | Receive 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
addEventListenermethod.
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:
Adding at Any Time
At any point during the app's lifecycle, if you need to add multiple event listener objects, you can call theaddEventListener method multiple times.
removeEventListener method to remove the specified event listener object.
MessageEvent
MessageEvent contains the following properties:
| Properties | Type | Description |
|---|---|---|
channelType | RtmChannelType | Channel types. See RtmChannelType. |
channelName | String | Channel name. |
topicName | String | Topic name. |
message | RtmMessage | Message. |
publisher | String | User ID of the message publisher. |
customType | String | A user-defined field. Only supports string type. |
timestamp | long | The timestamp when the event occurs. |
RtmMessage contains the following properties:
| Properties | Type | Description |
|---|---|---|
message | String | String type message. |
data | byte[] | Byte type message. |
messageType | RtmMessageType | Message type. See RtmMessageType. |
PresenceEvent
PresenceEvent contains the following properties:
| Properties | Type | Description |
|---|---|---|
type | RtmPresenceEventType | Presence event type. See RtmPresenceEventType. |
channelType | RtmChannelType | Channel types. See RtmChannelType. |
channelName | String | Channel name. |
publisher | String | User ID of the message publisher. |
stateItems | ArrayList<StateItem> | Key-value pair that identifies the user's presence state. |
interval | IntervalInfo | In 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. |
snapshot | SnapshotInfo | When 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. |
timestamp | long | The timestamp when the event occurred. |
IntervalInfo contains the following properties:
| Properties | Type | Description |
|---|---|---|
joinUserList | ArrayList<String> | List of users who joined the channel in the previous cycle. |
leaveUserList | ArrayList<String> | List of users who left the channel in the previous cycle. |
timeoutUserList | ArrayList<String> | List of users who timed out joining the channel in the previous cycle. |
userStateList | ArrayList<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:
| Properties | Type | Description |
|---|---|---|
userStateList | ArrayList<UserState> | Snapshot information of the user when first joining the channel, including user ID and key-value pairs of status. |
StateItem data type contains the following properties:
| Properties | Type | Description |
|---|---|---|
key | string | Key of the user state. If the specified key already exists, the SDK overwrites the value; if the specified key does not exist, the SDK creates the key-value pair. |
value | string | Value of the user state. |
TopicEvent
TopicEvent contains the following properties:
| Properties | Type | Description |
|---|---|---|
type | RtmTopicEventType | Topic event type. See RtmTopicEventType. |
channelName | String | Channel name. |
publisher | String | User ID. |
topicInfos | ArrayList<TopicInfo> | Topic information. |
timestamp | long | The timestamp when the event occurs. |
TopicInfo data type contains the following properties:
| Properties | Type | Description |
|---|---|---|
topicName | String | Topic name. |
publishers | ArrayList<PublisherInfo> | Message publisher array. |
PublisherInfo data type contains the following properties:
| Properties | Type | Description |
|---|---|---|
publisherUserId | String | User ID of the message publisher. |
publisherMeta | String | Metadata of the message publisher. |
StorageEvent
StorageEvent contains the following properties:
| Properties | Type | Description |
|---|---|---|
channelType | RtmChannelType | Channel types. See RtmChannelType. |
storageType | RtmStorageType | Storage type. See RtmStorageType. |
eventType | RtmStorageEventType | Storage event type. See RtmStorageEventType. |
target | String | User ID or channel name. |
data | Metadata | Metadata item. See Metadata. |
timestamp | long | The timestamp when the event occurs. |
LockEvent
LockEvent contains the following properties:
| Properties | Type | Description |
|---|---|---|
channelType | RtmChannelType | Channel types. See RtmChannelType. |
eventType | RtmLockEventType | Lock event type. See RtmLockEventType. |
channelName | String | Channel name. |
lockDetailList | ArrayList<LockDetail> | Details of lock. |
timestamp | long | The timestamp when the event occurs. |
The LockDetail data type contains the following properties:
| Properties | Type | Description |
|---|---|---|
lockName | String | Lock name. |
lockOwner | String | The ID of the user who has a lock. |
ttl | int | 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. |
LinkStateEvent
SDK link state event.
LinkStateEvent data type contains the following properties:
| Parameters | Type | Description |
|---|---|---|
currentState | RtmLinkState | The current link state. See RtmLinkState. |
previousState | RtmLinkState | The previous link state. See RtmLinkState. |
serviceType | RtmServiceType | The network connection type. See RtmServiceType. |
operation | RtmLinkOperation | The operation that triggered the current state transition. See RtmLinkOperation. |
reasonCode | AgoraRtmLinkStateChangeReason | The reason for this state transition. See AgoraRtmLinkStateChangeReason. |
reason | String | The reason for the current state transition. This parameter will be deprecated in the future, please use the reasonCode parameter instead. |
affectedChannels | ArrayList<String> | The channels affected by the current state transition. |
unrestoredChannels | ArrayList<String> | The information about the channels to which subscription or joining has not been restored, including the channel name, channel type, and temporary state data in the channel. Typically, this information is empty. |
isResumed | boolean | Within 2 minutes of the disconnection, whether the state transitions from DISCONNECTED to CONNECTED. true refers to the state has transitioned. |
timestamp | long | The timestamp when the event occurs. |
login
Description
After creating and initializing the Signaling instance, you need to perform thelogin operation to log in to the Signaling service. After successful login, the client establishes a long connection with the Signaling server, and then the SDK allows the client to access Signaling resources.
Method
You can log in to the Signaling system as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
token | const char* | Required | - | The token used for logging in to Signaling. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.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
onSuccessmethod. - If the method call fails, the SDK executes the
onFailuremethod and theonFailuremethod returns anerrorInfovalue of typeErrorInfo, which includes the error code, error reason, and API operation name as follows:
| Properties | Type | Description |
|---|---|---|
errorCode | RtmErrorCode | Error code for this operation. |
reason | String | Error reason for this operation. |
operation | String | Operation type. |
To find out the cause of the error and get the corresponding solution, use the errorCode field with the error codes table.
Basic usage
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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
Basic usage
release
Description
Once you no longer need the Signaling service, it is best to destroy theRtmClient instance. Doing so protects you from the performance degradation caused by memory leaks, errors, and exceptions.
Method
You can destroy the RtmClient instance as follows:
Basic usage
User authentication
Authentication is the process of validating the identity of each user before they access a system. Agora uses digital tokens to authenticate users and their privileges.
Different types of channels in SIgnaling require different types of tokens:
- Message channels and User channels: When logging in to Signaling using the
loginmethod, you only need to pass the token that enables Signaling. - Stream channels: In addition to the Signaling token, when joining a stream channel using the
joinmethod, you also need to pass the token that enables RTC service.
The token is valid for up to 24 hours. Agora recommends that you update the token before it expires. This section describes how to update the token.
For more information on generating and using tokens, see Secure authentication with tokens.
RtmClient.renewToken
Description
Call theRtmClient.renewToken method to renew the Signaling token.
To ensure timely token updates, Agora recommends listening for the onTokenPrivilegeWillExpire callback. See Event listeners for details. Once you successfully add the event listener, the SDK triggers the onTokenPrivilegeWillExpire callback 30 seconds before the Signaling token is set to expire to notify you about the impending token expiration.
Upon receiving this callback, you can obtain a new Signaling token from the token server and call the renewToken method to provide the SDK with the newly generated Signaling token.
Method
You can call the RtmClient.renewToken method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
token | string | Required | - | The newly generated Signaling token. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
Basic usage
StreamChannel.renewToken
Description
Call theStreamChannel.renewToken method to renew the RTC token.
To ensure timely token updates, Agora recommends listening for the onTokenPrivilegeWillExpire callback. See Event listeners for details. Once you successfully add the event listener, when the RTC token is about to expire within 30 seconds, the SDK triggers the onTokenPrivilegeWillExpire callback to notify the user about the impending token expiration.
Upon receiving this callback, you can generate a new RTC token on the server-side and call the renewToken method to provide the SDK with the newly generated RTC token.
Method
You can call the StreamChannel.renewToken method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
token | string | Required | - | The newly generated RTC token. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback: onSuccess method.onFailure method. |
Basic usage
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 use-cases:
-
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.
-
User Channel: Point-to-point message sending and receiving based on the Pub/Sub (publish/subscribe) model. Users do not need to subscribe to the channel, they can directly specify the user ID to send messages. To receive messages, they only need to listen to
onMessageEventevents. -
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
Signaling provides event notification capabilities for messages and states. By listening for callbacks, you can receive messages and events within subscribed channels. For information on how to add and set event listeners, see Event Listeners.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.
Method
You can call the subscribe method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
options | SubscribeOptions | Required | - | Options for subscribing to a channel. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
SubscribeOptions contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
withMessage | boolean | Optional | true | Whether to subscribe to message event notifications in the channel. |
withPresence | boolean | Optional | true | Whether to subscribe to presence event notifications in the channel. |
withMetadata | boolean | Optional | false | Whether to subscribe to storage event notifications in the channel. |
withLock | boolean | Optional | false | Whether to subscribe to lock event notifications in the channel. |
beQuiet | boolean | Optional | false | Whether to enable silent mode. If you set this parameter to true, the SDK behaves as follows:getOnlineUsers method, your information is not included.getUserChannels method, the channels that you subscribe to in silent mode are not included. |
Basic usage
unsubscribe
Description
If you no longer need to subscribe to a channel, you can call theunsubscribe 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.
Method
You can call the unsubscribe method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
Basic usage
createStreamChannel
Description
Before using a stream channel, you need to call thecreateStreamChannel 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.
Method
You can call the createStreamChannel method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
Basic usage
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
SNAPSHOTtype of theonPresenceEventevent. - The
SNAPSHOTtype of theonTopicEventevent.
- The
- For remote users: The
REMOTE_JOINtype of theonPresenceEventevent.
Method
You can call the join method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
options | JoinChannelOptions | Required | - | Options for joining a channel. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
The JoinChannelOptions data type contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
token | String | Required | - | An RTC token for joining a stream channel. |
withPresence | boolean | Optional | true | Whether to subscribe to presence event notifications in the channel. |
withMetadata | boolean | Optional | false | Whether to subscribe to storage event notifications in the channel. |
withLock | boolean | Optional | false | Whether to subscribe to lock event notifications in the channel. |
beQuiet | boolean | Optional | false | Whether to enable silent mode. If you set this parameter to true, the SDK behaves as follows:getOnlineUsers method, your information is not included.getUserChannels method, the channels that you subscribe to in silent mode are not included. |
Basic usage
leave
Description
If you no longer need to stay in a channel, you can call theleave 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.
Method
You can call the leave method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
Basic usage
release
Description
If you no longer need a channel, you can call therelease 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.
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 as follows:
Basic usage
Return Value
This operation returns the RtmErrorCode data type.
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.
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.
- Before joining a topic, a user needs to create the
StreamChannelinstance and call thejoinmethod 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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
topicName | String | Required | - | Topic name. |
options | JoinTopicOptions | Required | - | Options for joining a topic. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
The options parameter contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
messageQos | RtmMessageQos | Optional | UNORDERED | Whether the data transmitted in the topic is ordered. See RtmMessageQos. |
priority | RtmMessagePriority | Optional | NORMAL | The priority of data transmission in the topic compared to other topics in the same channel. See RtmMessagePriority. |
topicMeta | String | Optional | - | Adds additional metadata when joining the topic. |
syncWithMedia | boolean | Optional | false | Whether the data sent in this topic is synchronized (timestamp-aligned) with the RTC audio and video data stream of the common channel. |
Basic usage
publishTopicMessage
Description
Use thepublishTopicMessage 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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
topicName | String | Required | - | Topic name. |
message | String\byte[] | Required | - | Message payload. |
options | TopicMessageOptions | Required | - | Message options. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
The TopicMessageOptions data type contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
sendTs | long | Optional | 0 | The 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. |
customType | String | Optional | - | A user-defined field. Only supports string type. |
Basic usage
Example 1: Send string messages to a specified channel.
Example 2: Send byte messages to a specified channel.
leaveTopic
Description
When you no longer need to publish messages to a topic, to release resources, you can call theleaveTopic 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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
topicName | String | Required | - | Topic name. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
Basic usage
subscribeTopic
Description
After joining the channel, you can call thesubscribeTopic method to subscribe to the message publisher of the topic in the channel.
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 usage restrictions.
Method
You can call the subscribeTopic method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
topicName | String | Required | - | Topic name. |
options | TopicOptions | Required | - | Options for subscribing to a topic. |
resultCallback | ResultCallback<SubscribeTopicResult> | Required | - | Invocation result callback:onSuccess method and return the SubscribeTopicResult data.onFailure method. |
The options parameter contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
users | ArrayList<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:
| Properties | Type | Description |
|---|---|---|
succeedUsers | ArrayList<String> | A list of successfully subscribed users. |
failedUsers | ArrayList<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.
Example 2: Randomly subscribe to 64 message publishers in the topic.
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 theunsubscribeTopic method to unsubscribe from the topic or the specified message publishers in the topic.
Method
You can call the unsubscribeTopic method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
topicName | String | Required | - | Topic name. |
options | TopicOptions | Required | - | Options for unsubscribe from a topic. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
The options parameter contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
users | ArrayList<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
Example 2: Randomly unsubscribe 64 message publishers from the topic.
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 the following channel types:
- Message Channel: The real-time channel. Messages are transmitted through the channel, and the channel is highly scalable. Local users can call the
publishmethod, set thechannelTypeparameter toMESSAGE, and set thechannelNameparameter to the channel name to send messages in the channel. The remote users can call thesubscribemethod to subscribe to the channel and receive messages. - User Channel: The real-time channel. Messages are transmitted to the specified user. Local users can call the
publishmethod, set thechannelTypeparameter toUSER, and set thechannelNameparameter to the user ID to send messages to the specified user. The specified remote users receive messages through theonMessageEventevent notifications. - 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
publishTopicMessagemethod to send messages in the topic, and remote users can call thesubscribeTopicmethod to subscribe to the topic and receive messages.
This section shows you how to send and receive messages in a message channel or a user channel.
publish
Description
You can directly call thepublish 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.
- 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 60 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.
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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Fill in a channel name to send messages to a specified channel, or fill in a user ID to send messages to a specified user. |
message | String\byte[] | Required | - | Message payload. |
options | PublishOptions | Required | - | Message options. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
The options parameter contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
channelType | RtmChannelType | Required | - | Channel types. See RtmChannelType. |
customType | String | Optional | - | A user-defined field. Only supports string type. |
Basic usage
Example 1: Send string messages to a specified channel.
Example 2: Send byte messages to a specified channel.
Example 3: Send string messages to a specified user.
Example 4: Send byte messages to a specified user.
Receive
Signaling provides event notifications for messages, states, and event changes. By listening for callbacks, you can receive messages and events within subscribed channels. As an example, the code snippet below shows how to receive messages from the user channel.
-
Adding during initialization:
-
Adding at any time:
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.
getOnlineUsers
Description
By calling thegetOnlineUsers 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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | string | Required | - | Channel name. |
channelType | RtmChannelType | Required | - | Channel types. See RtmChannelType. |
options | GetOnlineUsersOptions | Required | - | Query options. |
resultCallback | ResultCallback<GetOnlineUsersResult> | Required | - | Invocation result callback:onSuccess method and return the GetOnlineUsersResult query result.onFailure method and return an error result. |
The options parameter contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
includeUserId | boolean | Optional | true | Whether the returned result includes the user ID of online members. |
includeState | boolean | Optional | false | Whether the returned result includes temporary state data of online users. |
page | String | Optional | - | 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:
| Properties | Type | Description |
|---|---|---|
nextPage | String | Page number of the next page. Confirm whether there is a next page:page property of the getOnlineUsers method to query the next page results. |
userStateList | ArrayList<UserState> | List of online users and their temporary state information in a specified channel. |
totalOccupancy | long | The 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. |
The UserState data type contains the following properties:
| Properties | Type | Description |
|---|---|---|
userId | String | User ID. |
states | HashMap<String, String> | Temporary user state. |
Basic usage
getUserChannels
Description
In use-cases such as statistic analytics and debugging, you may need to know all the channels that a specified user has subscribed to or joined. Call thegetUserChannels method to get the list of channels where the specified user is in real time.
Method
You can call the getUserChannels method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
userId | string | Required | - | User ID. |
resultCallback | ResultCallback<ArrayList<ChannelInfo>> | Required | - | Invocation result callback:onSuccess method and return the ArrayList<ChannelInfo> query result.onFailure method. |
ChannelInfo data type contains the following properties:
| Properties | Type | Description |
|---|---|---|
channelName | String | Channel name. |
channelType | RtmChannelType | Channel types. See RtmChannelType. |
Basic usage
setState
Description
To meet different requirements in different business use-cases for setting user states, Signaling provides thesetState 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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name |
channelType | RtmChannelType | Required | - | Channel types. See RtmChannelType. |
items | Map<String, String> | Required | - | User state. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
StateItem data type contains the following properties:
| Properties | Type | Description |
|---|---|---|
key | string | Key of the user state. If the specified key already exists, the SDK overwrites the value; if the specified key does not exist, the SDK creates the key-value pair. |
value | string | Value of the user state. |
Basic usage
getState
Description
To get the temporary user state of a specified user in the channel, you can use thegetState method.
Method
You can call the getState method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
channelType | RtmChannelType | Required | - | Channel types. See RtmChannelType. |
userId | String | Required | - | User ID. |
resultCallback | ResultCallback<UserState> | Required | - | Invocation result callback:onSuccess method and return the UserState query result.onFailure method. |
The UserState data type contains the following properties:
| Properties | Type | Description |
|---|---|---|
userId | String | User ID. |
states | HashMap<String, String> | Temporary user state. |
Basic usage
removeState
Description
When a temporary user state is no longer needed, you can call theremoveState 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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name |
channelType | RtmChannelType | Required | - | Channel types. See RtmChannelType. |
keys | ArrayList<String> | Required | - | List of keys to be deleted. If you do not provide this property, the SDK removes all states. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
Basic usage
Storage
The storage feature provides a 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 a 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 and applies settings according to the following rules:
- If you set metadata with different
keyvalues, 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, thevalueof the last setting overwrites the previous one.
After successfully setting channel metadata, users who subscribe to the channel and enable event listeners 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 these according to your actual business use-case:
- Enable version number verification for the entire set of channel metadata by setting the
majorRevisionproperty in theMetadatadata type. - Enable version number verification for a single metadata item by setting the
revisionproperty in theMetadataItemclass.
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 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 an error code.
Method
You can call the setChannelMetadata method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
channelType | RtmChannelType | Required | - | Channel type. See RtmChannelType. |
data | Metadata | Required | - | Metadata item. See Metadata. |
options | MetadataOptions | Required | - | Options for setting the channel metadata. |
lockName | String | Required | - | Lock name. If set, only users who call the acquireLock method to acquire the lock can perform operations. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
The MetadataOptions data type contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
recordTs | boolean | Optional | false | Whether to record the timestamp of the edits. |
recordUserId | boolean | Optional | false | Whether to record the user ID of the editor. |
Basic usage
getChannelMetadata
Description
ThegetChannelMetadata method gets the metadata of the specified channel.
Method
You can call the getChannelMetadata method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
channelType | RtmChannelType | Required | - | Channel type. See RtmChannelType. |
resultCallback | ResultCallback<Metadata> | Required | - | Invocation result callback:onSuccess method and return the Metadata query result.onFailure method. |
Basic usage
removeChannelMetadata
Description
TheremoveChannelMetadata method removes 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 an error code. - If the revision property is a positive integer, this method call performs 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 an error code.
After successfully removing channel metadata or metadata items, users who subscribe to the channel and enable event listeners receive the CHANNEL type of the onStorageEvent event notification. See Event listeners.
Method
You can call the removeChannelMetadata method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
channelType | RtmChannelType | Required | - | Channel type. See RtmChannelType. |
data | Metadata | Required | - | Metadata item. See Metadata . |
options | MetadataOptions | Required | - | Options for setting the channel metadata. |
lockName | String | Required | - | Lock name. If set, only users who call the acquireLock method to acquire the lock can perform operations. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
The MetadataOptions data type contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
recordTs | boolean | Optional | false | Whether to record the timestamp of the edits. |
recordUserId | boolean | Optional | false | Whether to record the user ID of the editor. |
Basic usage
updateChannelMetadata
Description
TheupdateChannelMetadata method updates 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 receive the CHANNEL type of the onStorageEvent event notification. See Event listeners.
Method
You can call the updateChannelMetadata method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
channelType | RtmChannelType | Required | - | Channel type. See RtmChannelType. |
data | Metadata | Required | - | Metadata item. See Metadata . |
options | MetadataOptions | Required | - | Options for setting the channel metadata. |
lockName | String | Required | - | Lock name. If set, only users who call the acquireLock method to acquire the lock can perform operations. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
The options parameter contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
recordTs | boolean | Optional | false | Whether to record the timestamp of the edits. |
recordUserId | boolean | Optional | false | Whether to record the user ID of the editor. |
Basic usage
setUserMetadata
Description
The setUserMetadata method sets metadata for a user. If you call this method multiple times, the SDK retrieves the key of the metadata items and applies 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, thevalueof the last setting overwrites the previous one.
After successfully setting user metadata, users who subscribe to the user and enable event listeners 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 use-case:
- Enable version number verification for the entire set of channel metadata by setting the
majorRevisionproperty in theMetadatadata type. - Enable version number verification for a single metadata item by setting the
revisionproperty in theMetadataItemclass.
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 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 an error code.
Method
You can call the setUserMetadata method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
userId | String | Required | - | User ID. |
data | Metadata | Required | - | Metadata item. See Metadata . |
options | MetadataOptions | Required | - | Options for setting the channel metadata. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
The options parameter contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
recordTs | boolean | Optional | false | Whether to record the timestamp of the edits. |
recordUserId | boolean | Optional | false | Whether to record the user ID of the editor. |
Basic usage
getUserMetadata
Description
ThegetUserMetadata method gets the metadata and metadata item for the specified user.
Method
You can call the getUserMetadata method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
userId | String | Required | - | User ID. |
resultCallback | ResultCallback<Metadata> | Required | - | Invocation result callback:onSuccess method and return the Metadata query result.onFailure method. |
Basic usage
removeUserMetadata
Description
TheremoveUserMetadata method removes user metadata or metadata items.
After successfully removing user metadata, users who subscribe to the user and enable event listeners receive the USER type of the onStorageEvent event notification. See Event listeners.
Method
You can call the removeUserMetadata method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
userId | String | Required | - | User ID. |
data | Metadata | Required | - | Metadata item. See Metadata . |
options | MetadataOptions | Required | - | Options for setting the channel metadata. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
The options parameter contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
recordTs | boolean | Optional | false | Whether to record the timestamp of the edits. |
recordUserId | boolean | Optional | false | Whether to record the user ID of the editor. |
Basic usage
updateUserMetadata
Description
TheupdateUserMetadata method updates existing user metadata. After successfully updating channel metadata, users who subscribe to the user and enable event listeners receive the USER type of the onStorageEvent event notification. See Event listeners.
Method
You can call the updateUserMetadata method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
userId | String | Required | - | User ID. |
data | Metadata | Required | - | Metadata item. See Metadata . |
options | MetadataOptions | Required | - | Options for setting the channel metadata. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
The MetadataOptions data type contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
recordTs | boolean | Optional | false | Whether to record the timestamp of the edits. |
recordUserId | boolean | Optional | false | Whether to record the user ID of the editor. |
Basic usage
subscribeUserMetadata
Description
ThesubscribeUserMetadata method can subscribe to metadata for a specified user. After successfully subscribing to the user metadata, you 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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
userId | String | Required | - | User ID. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
Basic usage
unsubscribeUserMetadata
Description
If you do not need to receive notifications of changes to a user metadata, call theunsubscribeUserMetadata method to unsubscribe.
Method
You can call the unsubscribeUserMetadata method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
userId | String | Required | - | User ID. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
Basic usage
Metadata
Use the Metadata data type to set and manage metadata, containing the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
majorRevision | long | Optional | -1 | 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. |
items | ArrayList<MetadataItem> | Optional | null | Metadata items. |
The MetadataItem data type contains the following properties:
| Properties | Type | Required | Default | Description |
|---|---|---|---|---|
key | String | Optional | - | Key. |
value | String | Optional | - | Value. |
authorUserId | String | Optional | - | The user ID of the editor. This value is read-only and does not support writing. |
revision | long | Optional | -1 |
|
updateTs | long | Optional | 0 | Update timestamp. This value is read-only and does not support writing. |
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.
setLock
Description
You need to configure the lock name, time to live (TTL) and other parameters by calling thesetLock 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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
channelType | RtmChannelType | Required | - | Channel types. See RtmChannelType. |
lockName | String | Required | - | Lock name. |
ttl | long | Required | - | 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. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
Basic usage
acquireLock
Description
After successfully configuring a lock, you can call theacquireLock 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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
channelType | RtmChannelType | Required | - | Channel types. See RtmChannelType. |
lockName | String | Required | - | Lock name. |
retry | boolean | Required | - | If the lock acquisition fails, whether to retry until the acquisition succeeds or the user leaves the channel. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
Basic usage
releaseLock
Description
When a user no longer needs to own a lock, the user can call thereleaseLock 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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
channelType | RtmChannelType | Required | - | Channel types. See RtmChannelType. |
lockName | String | Required | - | Lock name. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
Basic usage
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 callingrevokeLock. 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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
channelType | RtmChannelType | Required | - | Channel types. See RtmChannelType. |
lockName | String | Required | - | Lock name. |
owner | String | Required | - | The ID of the user who has a lock. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
Basic usage
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 thegetLocks method on the client.
Method
You can call the getLocks method as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
channelType | RtmChannelType | Required | - | Channel types. See RtmChannelType. |
resultCallback | ResultCallback<ArrayList<LockDetail>> | Required | - | onSuccess method and return the LockDetail data type.onFailure method. |
The LockDetail data type contains the following properties:
| Properties | Type | Description |
|---|---|---|
lockName | String | Lock name. |
lockOwner | String | The ID of the user who has a lock. |
ttl | int | 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. |
Basic usage
removeLock
Description
If you no longer need a lock, you can call theremoveLock 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 as follows:
| Parameters | Type | Required | Default | Description |
|---|---|---|---|---|
channelName | String | Required | - | Channel name. |
channelType | RtmChannelType | Required | - | Channel types. See RtmChannelType. |
lockName | String | Required | - | Lock name. |
resultCallback | ResultCallback<Void> | Required | - | Invocation result callback:onSuccess method.onFailure method. |
Basic usage
Enumerated types
Enum
RtmAreaCode
The region for connection, which is the region where the server the SDK connects to is located.| Value | Description |
|---|---|
CN | 0x00000001: Mainland China. |
NA | 0x00000002: North America. |
EU | 0x00000004: Europe. |
AS | 0x00000008: Asia, excluding Mainland China. |
JP | 0x00000010: Japan. |
IN | 0x00000020: India. |
GLOB | 0xFFFFFFFF: Global. |
RtmChannelType
Channel types.| Value | Description |
|---|---|
MESSAGE | 1: Message channel. |
STREAM | 2: Stream channel. |
USER | 3: User Channel. |
RtmConnectionChangeReason
Reasons causing the change of the connection state.| Value | Description |
|---|---|
CONNECTING | 0: The SDK is connecting with the server. |
JOIN_SUCCESS | 1: The SDK has joined the channel successfully. |
INTERRUPTED | 2: The connection between the SDK and the server is interrupted. |
BANNED_BY_SERVER | 3: The connection between the SDK and the server is banned by the server. |
JOIN_FAILED | 4: 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_CHANNEL | 5: The SDK has left the channel. |
INVALID_APP_ID | 6: The connection failed because the App ID is not valid. |
INVALID_CHANNEL_NAME | 7: The connection failed because the channel name is not valid. |
INVALID_TOKEN | 8: The connection failed because the token is not valid. |
TOKEN_EXPIRED | 9: The connection failed because the token is expired. |
REJECTED_BY_SERVER | 10: The connection is rejected by server. |
SETTING_PROXY_SERVER | 11: The connection state changed to reconnecting because the SDK has set a proxy server. |
RENEW_TOKEN | 12: The connection state changed because the token is renewed. |
CLIENT_IP_ADDRESS_CHANGED | 13: The IP address of the client has changed, possibly because the network type, IP address, or port has been changed. |
KEEP_ALIVE_TIMEOUT | 14: Timeout for the keep-alive of the connection between the SDK and the server. The connection state changes to reconnecting. |
REJOIN_SUCCESS | 15: The user has rejoined the channel successfully. |
LOST | 16: The connection between the SDK and the server is lost. |
ECHO_TEST | 17: The connection state changes due to the echo test. |
CLIENT_IP_ADDRESS_CHANGED_BY_USER | 18: The local IP address was changed by the user. The connection state changes to reconnecting. |
SAME_UID_LOGIN | 19: The user joined the same channel from different devices with the same UID. |
TOO_MANY_BROADCASTERS | 20: The number of hosts in the channel has reached the upper limit. |
LICENSE_VALIDATION_FAILURE | 21: License validation failure. |
CERTIFICATION_VERIFY_FAILURE | 22: The server certificate verification has encountered an error. |
STREAM_CHANNEL_NOT_AVAILABLE | 23: The stream channel does not exist. |
INCONSISTENT_APPID | 24: The App ID does not match the token. |
LOGIN_SUCCESS | 10001: The SDK logs in to the Signaling system. |
LOGOUT | 10002: The SDK logs out from the Signaling system. |
PRESENCE_NOT_READY | 10003: Presence service is not ready. You need to call the login method again to log in to the Signaling system and re-execute all operations on the SDK. |
RtmConnectionState
SDK connection states.| Value | Description |
|---|---|
DISCONNECTED | 1: The SDK has disconnected with the server. |
CONNECTING | 2: The SDK is connecting with the server. |
CONNECTED | 3: The SDK has connected with the server. |
RECONNECTING | 4: The connection is lost. The SDK is reconnecting with the server. |
FAILED | 5: The SDK failed to connect with the server. |
RtmEncryptionMode
Encryption mode.| Value | Description |
|---|---|
NONE | 0: No encryption. |
AES_128_GCM | 1: AES-128-GCM mode. |
AES_256_GCM | 2: AES-256-GCM mode. |
RtmLockEventType
Lock event type.| Value | Description |
|---|---|
SNAPSHOT | 1: The snapshot of the lock when the user joined the channel. |
SET | 2: The lock is set. |
REMOVED | 3: The lock is removed. |
ACQUIRED | 4: The lock is acquired. |
RELEASED | 5: The lock is released. |
EXPIRED | 6: The lock expired. |
RtmLogLevel
Log output levels.| Value | Description |
|---|---|
NONE | 0x0000: No log. |
INFO | 0x0001: Output the log at the FATAL, ERROR, WARN, or INFO level. We recommend you set to this value. |
WARN | 0x0002: Output the log at the FATAL, ERROR, WARN level. |
ERROR | 0x0004: Output the log at the FATAL, ERROR level. |
FATAL | 0x0008: Output the log at the FATAL level. |
RtmMessagePriority
| Value | Description |
|---|---|
HIGHEST | 0: Highest. |
HIGH | 1: High. |
NORMAL | 4: Normal. |
LOW | 8: Low. |
RtmMessageQos
| Value | Description |
|---|---|
UNORDERED | 0: Message data is not guaranteed to arrive in order. |
ORDERED | 1: Message data arrives in order. |
RtmMessageType
| Value | Description |
|---|---|
BINARY | 0: Binary type. |
STRING | 1: String type. |
RtmPresenceEventType
Presence event type.| Value | Description |
|---|---|
SNAPSHOT | 1: The snapshot of the presence when the user joined the channel. |
INTERVAL | 2: When users in the channel reach the setting value, the event notifications are sent at intervals rather than in real time. |
REMOTE_JOIN | 3: A remote user joined the channel. |
REMOTE_LEAVE | 4: A remote user left the channel. |
REMOTE_TIMEOUT | 5: A remote user's connection timed out. |
REMOTE_STATE_CHANGED | 6: A remote user's temporary state changed. |
ERROR_OUT_OF_SERVICE | 7: The user did not enable presence when joining the channel. |
RtmLinkOperation
Operation type.| Value | Description |
|---|---|
LOGIN | 0: The user logins to the Signaling system. |
LOGOUT | 1: The user logouts of the Signaling system. |
JOIN | 2: The user joins in a stream channel. |
LEAVE | 3: The user leaves a stream channel. |
SERVER_REJECT | 4: The Signaling server reject the connection. |
AUTO_RECONNECT | 5: The SDK is automatically reconnecting to the Signaling server. |
RECONNECTED | 6: The SDK is reconnected to the Signaling server. |
HEARTBEAT_TIMEOUT | 7: The Signaling server does not receive the heartbeat packet within the specified timeout period. |
SERVER_TIMEOUT | 8: The Signaling server has timed out. |
NETWORK_CHANGE | 9: The network status changes. |
RtmLinkState
Link state type.| Value | Description |
|---|---|
IDLE | 0: The init state. |
CONNECTING | 1: Connecting. |
CONNECTED | 2: Connected. |
DISCONNECTED | 3: Disconnected. |
SUSPENDED | 4: Suspended. |
FAILED | 5: Failed. |
RtmLinkStateChangeReason
Link state change reason.
| Value | Description |
|---|---|
UNKNOWN | 0: Unknown reason. |
LOGIN | 1: Logging in. |
LOGIN_SUCCESS | 2: Login successful. |
LOGIN_TIMEOUT | 3: Login timeout. |
LOGIN_NOT_AUTHORIZED | 4: Login not authorized. |
LOGIN_REJECTED | 5: Login rejected. |
RELOGIN | 6: Re-login. |
LOGOUT | 7: Logout. |
AUTO_RECONNECT | 8: Auto-reconnect. |
RECONNECT_TIMEOUT | 9: Reconnect timeout. |
RECONNECT_SUCCESS | 10: Reconnect successful. |
JOIN | 11: Joining a channel. |
JOIN_SUCCESS | 12: Join channel successful. |
JOIN_FAILED | 13: Join channel failed. |
REJOIN | 14: Re-join a channel. |
LEAVE | 15: Leave a channel. |
INVALID_TOKEN | 16: Invalid token. |
TOKEN_EXPIRED | 17: Token expired. |
INCONSISTENT_APP_ID | 18: Inconsistent app ID. |
INVALID_CHANNEL_NAME | 19: Invalid channel name. |
INVALID_USER_ID | 20: Invalid user ID. |
NOT_INITIALIZED | 21: SDK not initialized. |
RTM_SERVICE_NOT_CONNECTED | 22: RTM service not connected. |
CHANNEL_INSTANCE_EXCEED_LIMITATION | 23: Channel instance exceeds the limit. |
OPERATION_RATE_EXCEED_LIMITATION | 24: Operation frequency exceeds the limit. |
CHANNEL_IN_ERROR_STATE | 25: Channel in error state. |
PRESENCE_NOT_CONNECTED | 26: Presence service not connected. |
SAME_UID_LOGIN | 27: Login with the same user ID. |
KICKED_OUT_BY_SERVER | 28: Kicked out by the server. |
KEEP_ALIVE_TIMEOUT | 29: Keepalive timeout. |
CONNECTION_ERROR | 30: Connection error. |
PRESENCE_NOT_READY | 31: Presence service not ready. |
NETWORK_CHANGE | 32: Network changed. |
SERVICE_NOT_SUPPORTED | 33: Service not supported. |
STREAM_CHANNEL_NOT_AVAILABLE | 34: Stream Channel not available. |
STORAGE_NOT_AVAILABLE | 35: Storage service not available. |
LOCK_NOT_AVAILABLE | 36: Lock service not available. |
LOGIN_TOO_FREQUENT | 37: The login operation is too frequent. |
RtmProtocolType
Protocol type.| Value | Description |
|---|---|
TCP_UDP | 0: Both TCP and UDP protocols. |
TCP_ONLY | 1: Only TCP protocol. |
RtmServiceType
Service type| Value | Description |
|---|---|
MESSAGE | The foundational services comprise the message channel, user channel, presence, storage, and lock services. |
STREAM | The stream channel service. |
To fully utilize all services offered by Signaling, use bitwise operations to simultaneously configure two service types.
RtmProxyType
Proxy type.| Value | Description |
|---|---|
NONE | 0: Do not enable the proxy. |
HTTP | 1: Enable the proxy for the HTTP protocol. |
CLOUD_TCP | 2: Enable cloud proxy for the TCP protocol. |
RtmStorageEventType
Storage event type.| Value | Description |
|---|---|
SNAPSHOT | 1: 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. |
SET | 2: Occurs when calling setChannelMetadata or setUserMetadata.Caution This event only occurs in incremental data update mode. |
UPDATE | 3: Occurs when calling methods to set, update, or delete the channel metadata or user metadata. |
REMOVE | 4: Occurs when calling removeChannelMetadata or removeUserMetadata.Caution This event only occurs in incremental data update mode. |
RtmStorageType
Storage type.| Value | Description |
|---|---|
USER | 1: User metadata event. |
CHANNEL | 2: Channel metadata event. |
RtmTopicEventType
Topic event type.| Value | Description |
|---|---|
SNAPSHOT | 1: The snapshot of the topic when the user joined the channel. |
REMOTE_JOIN | 2: A remote user joined the channel. |
REMOTE_LEAVE | 3: A remote user left the channel. |