Migration guide
This migration guide helps you migrate from Signaling 1.x
to Signaling 2.x
.
In December 2023, Agora released Signaling 2.x
in response to market and industry needs. Signaling 2.x
brings significant innovation to users in terms of:
-
Features coverage: Signaling
2.x
expands its scope to encompass a broader range of business scenarios through the introduction of functional modules includingChannel
,Message
,Topic
,Presence
,Storage
, andLock
. These additions empower you to shift your attention from fundamental feature implementation to fostering business innovation. -
Performance improvement: Signaling
2.x
revamps the backend architecture, enhancing overall performance through optimized network connections. This overhaul results in sustained low-latency, higher reliability, increased concurrency, and seamless scalability for real-time network access. With these advancements, businesses can confidently rely on the backend, to ensure both optimal performance and high-quality service. -
Experience optimization: All documents, including user guides and API references, have been optimized and furnished more comprehensive sample code. These enhancements empower developers with a cost-effective learning experience, enable swift integration and improve development efficiency when utilizing the SDK.
For a seamless transition from Signaling 1.x
to 2.x
, refer to the following document. This resource is designed to expedite the migration process, ensuring that you can swiftly leverage the new features in Signaling 2.x
and start reaping their benefits.
Activate Signaling
To activate Signaling 2.x
, take the following steps:
- Log in to Agora Console
- Create a new Agora project or choose an existing project from the project list.
- Select the project on the Project Management page and click the pencil icon to configure it.
- Go to All features > Signaling > Basic information and select a data center in the dropdown.
- Go to Subscriptions > Signaling and subscribe to a plan.
- Copy the App ID for your project for use in your code.
Signaling version 2.x
differs from 1.x
in the support of naming character sets. For example, 2.x
does not support channel names, user names, or topic names that start with _
or contain .
characters. When upgrading from 1.x
to 2.x
or using both versions together, be aware of possible incompatibilities caused by character set differences. Best practice is to use the character set supported by 2.x
when migrating. See Channel naming for the character set supported by 2.x
.
Integrate the SDK
The SDK package names and integration methods for 2.x
and 1.x
remain unchanged. CDN and CocoaPods integration methods are both supported. The Podfile
content for CocoaPods integration is as follows:
Initialize an RTM Client instance
Signaling 2.x
has made significant adjustments to the initialization parameters, adding many new features such as end-to-end encryption, and cloud proxy. For details, refer to the API reference. Additionally, 2.x
has enriched the error information for API calls. You can retrieve error codes, reasons, and API operation names through the AgoraRtmErrorInfo
data structure, making it easier to troubleshoot issues.
-
For
1.x
: -
For
2.x
:
Log in to Signaling
The login method for 2.x
differs from 1.x
, as follows:
-
For
1.x
: -
For
2.x
:
Event notifications
Signaling 2.x
has redesigned the system's event notification method and API interface, providing more detailed categorization and aggregation of event notification types, as well as optimizing the payload data structure. Version 2.x
features the following event notification types:
Event Type | Description |
---|---|
didReceiveMessageEvent | Message event notification: Receive notifications for all message events in subscribed Message channels and topics. |
didReceivePresenceEvent | User Presence and custom state change event notification (Presence event Notification): Receive notifications for all Presence events in subscribed Message channels and joined Stream channels. |
didReceiveTopicEvent | Topic change event notification: Receive notifications for all Topic change events in joined Stream channels. |
didReceiveStorageEvent | Channel and User Property event notification: Receive notifications for all Channel metadata events in subscribed Message channels and joined Stream channels, and User Metadata events for subscribed users. |
didReceiveLockEvent | Lock change event notification: Receive notifications for all Lock events in subscribed Message channels and joined Stream channels. |
connectionChangedToState | (Deprecated) Network connection state change event notification: Receive notifications for changes in client network connection status. |
didReceiveLinkStateEvent | Receives notifications of changes in the client's network connection state, including information such as the connection state before and after the change, service type, operation type that caused the change, reason for the change, and channel list. |
tokenPrivilegeWillExpire | Receive event notifications when the client token is about to expire. |
For more information on event notifications and payload data structures, see Event listeners.
Examine the following code to observe the differences between the 1.x
and 2.x
implementations.
-
For
1.x
: -
For
2.x
:
Observe the following differences in the sample code.
-
In
1.x
, channel message event notification is bound to specificchannel
instances. Users need to create achannel
instance by calling thecreateChannelWithId:delegate
method, then register themessageReceived
callback to handle events. The SDK notifies the handler through this callback when a message is received, and it needs to be bound multiple times for multiple channels. In2.x
, message event notification is bound to the client instance globally. When creating and initializing theAgoraRtmClientKit
instance, you register the event listener instance once, and it listens to all subscribed channels or topics. -
The payload data structure for
1.x
message event notification contains limited information. The2.x
payload data structure contains more information, which helps you better implement your business logic.
Channel messages
In version 1.x
, to send a channel message, you needed to:
- Create a Channel instance
- Join the channel
- Send and receive channel messages
The disadvantage to this design is that you cannot independently send messages. You must also receive messages because sending and receiving is coupled. Signaling 2.x
adopts a new Pub/Sub-based model designed to decouple sending and receiving messages. When sending messages, you only need to publish to the specified channel without joining the channel. To receive channel messages, you only need to subscribe to the specified channel. The two operations are independent.
-
For
1.x
: -
For
2.x
:
Peer-to-peer messaging
In version 1.x
, peer-to-peer messaging API is used to send messages to specified users. For example, if you want to send a message to the user whose UserId is "Tony", you can do it as follows:
The design of this interface in version 1.x
is tailored to fulfill the requirements of an end-to-end message transmission scenario. In this context, User A seeks to send a message exclusively to User B, and User B only desires to receive this specific message without subscribing to other events. The channel mechanism in version 1.x
is structured based on the Room model. However, this design lacks the capability to decouple message sending and receiving.
In version 2.x
, Agora redesigned the distribution of channel messages using the Pub/Sub model to decouple sending and receiving of messages. You can still implement point-to-point messages using channels. Use the following scheme to implement peer-to-peer messaging with Signaling 2.x
.
-
Each user subscribes to a private channel named
inbox_ + UserID
after initialization, which you call Inbox. Only the user with the specificUserID
can subscribe to this channel. -
To send a peer-to-peer message to a user, just send the message to the user's Inbox.
Sample code:
To receive messages, you also need to implement the didReceiveMessageEvent
event listener function.
Images and file messages
For reasons of user data privacy/protection compliance and cost optimization, Signaling 2.x
no longer directly supports image and file message types. After version 1.5.0
, the related interfaces have been removed. However, this does not mean that you cannot use Signaling to transmit and distribute image and file messages. You can build image and file message functions with the help of Signaling 2.x
and third-party object storage services, such as Amazon S3 or Alibaba Cloud OSS. Not only can you get the best factual message transmission experience, you can also implement more flexible technical solutions. For example, CDN static resource acceleration or image and text moderation.
The following code sample shows you how to use Signaling 2.x
and Amazon S3 object storage service to build and send image and file messages.
When using Amazon S3 for static file storage, go to the Amazon S3 console and set the correct user permissions and access policies. Refer to Access Control Best Practices for more information.
User presence and custom status
In Signaling 1.x
, you can subscribe to or query the online status of multiple users, query the number of users in a channel, or obtain the list of online members in a channel. Signaling 2.x
not only retains these features, but also implements upgrades and extends them. In Signaling 2.x
, these capabilities are redefined and implemented in the Presence module. Presence provides the ability to monitor user online, user offline and user status change notifications. Through the Presence module, you can obtain the following information in real time:
- A user joins or leaves the specified channel
- Customize temporary user status and its changes
- Query which channels a specified user has joined or is subscribed to
- Query which users have joined the specified channel and their temporary status data
Call the getOnlineUsers
method to query the number of online users in the specified channel, the list of online users, and the temporary status of online users in real-time.
You use the getUserChannels
method to obtain the list of channels in which a specified user is currently present.
To meet the user status requirements of business scenarios, Signaling 2.x
provides temporary user status capabilities. Customize temporary user status through the setState
method. Users can add their scores, game status, location, mood, and other customized statuses.
You use the getState
method to retrieve the online status of a user, or the removeState
method to delete a user's status. After the temporary user state changes, the RTM server triggers the AgoraRtmPresenceEventTypeRemoteStateChanged
type of didReceivePresenceEvent
event notification. For specific usage, refer to Temporary User State.
In 2.x
, real-time monitoring of user join, leave, timeout, or temporary status change notifications in a channel is more convenient. Just follow these steps:
- Implement a Presence event listener.
- When joining a channel, enable the
withPresence
switch.
In Signaling 2.x
real-time notifications have been redesigned. The presence event notification mode refers to how subscribed users of presence events in the channel are notified. There are two available modes:
- Real-time notification mode (Announce)
- Scheduled notification mode (Interval)
You can determine the conditions for switching between the two modes through the Announce Max parameter in the project settings of the Agora Console. The interval notification mode can prevent noisy events caused by too many online users in the channel. For details, see Event Listeners.
User metadata and channel metadata
Signaling 2.x
retains the full functionality of user metadata and channel metadata, with new capabilities such as versioning and locking. It adds optimized interfaces to make these features easier to use.
In 2.x
, user attributes and channel attributes are mounted under the Storage
module. To set channel attributes, refer to the following code:
To learn more about how to get, update, and delete channel attributes, how to use version control and lock control, refer to the Storage guide. The use of user attributes is similar to that of channel attributes.
Events for channel and user attributes are distributed to users through events of type didReceiveStorageEvent
. To listen for didReceiveStorageEvent
events, refer to the following steps:
-
Implement the Storage event listener.
-
When joining a channel, enable the
withMetadata
switch.
Restrict access area
Signaling supports the restricted access area feature to comply with the laws and regulations of different countries or regions. After turning on the restricted access area feature, no matter which area the user uses your app from, the SDK will only access the Agora server in the geographical specified area. Signaling 1.x
implements access area limitation as follows.
-
For
1.x
: -
For
2.x
:
Other new features
In addition to the enhancements presented in this document, Signaling 2.x
introduces an array of additional features. Choose and implement features that fit the needs of your project. The following table outlines key new features of Signaling 2.x
:
Module | Function | Signaling 2.x API Interface |
---|---|---|
Setup | Create Instance | initWithConfig:delegate:error |
Destroy Instance | [rtm destroy] | |
Token Configuration | AgoraRtmClientConfig with token parameter | |
End-to-End Encryption | AgoraRtmClientConfig with encryptionConfig parameter | |
Presence Timeout Setting | AgoraRtmClientConfig with presenceTimeout parameter | |
Log Level Setting | AgoraRtmLogConfig with level parameter | |
Proxy Configuration | AgoraRtmProxyConfig with proxyType , server , port , account , password parameters | |
Event Listener | - [rtm addDelegate:delegate] - [rtm removeDelegate:delegate] | |
Login Service | [rtm loginByToken:completion:] | |
Logout Service | [rtm logout:completion] | |
Channel | Subscribe Channel | [rtm subscribeWithChannel:option:completion] |
Unsubscribe Channel | [rtm unsubscribeWithChannel:completion] | |
Create Stream Channel | [rtm createStreamChannel:error] | |
Join Stream Channel | [streamChannel joinWithOption:completion] | |
Leave Stream Channel | [streamChannel leave] | |
Destroy Stream Channel | [streamChannel destroy] | |
Topic | Join Topic | [streamChannel joinTopic:withOption:completion] |
Publish Topic Message | [streamChannel publishTopicMessage:data:option:completion] | |
Leave Topic | [streamChannel leaveTopic:completion] | |
Subscribe Topic | [streamChannel subscribeTopic:withOption:completion] | |
Unsubscribe Topic | [streamChannel unsubscribeTopic:withOption:completion] | |
Message | Send Message | [rtm publish:message:option:completion] |
Presence | Query Channel's Online Users | [[rtm getPresence] getOnlineUsers:channelType:options:completion] |
Query User's Channel | [[rtm getPresence] getUserChannels:completion] | |
Set User's Temporary State | [[rtm getPresence] setState:channelType:items:completion] | |
Query User Temporary State | [[rtm getPresence] getState:channelType:userId:completion] | |
Remove User Temporary State | [[rtm getPresence] removeState:channelType:keys:completion] | |
Storage | Set Channel Metadata | [[rtm getStorage] setChannelMetadata:channelType:data:options:lock:completion] |
Get Channel Metadata | [[rtm getStorage] getChannelMetadata:channelType:completion] | |
Remove Channel Metadata | [[rtm getStorage] removeChannelMetadata:channelType:data:options:lock:completion] | |
Update Channel Metadata | [[rtm getStorage] updateChannelMetadata:channelType:data:options:lock:completion] | |
Set User Attributes | [[rtm getStorage] setUserMetadata:data:options:completion] | |
Get User Attributes | [[rtm getStorage] getUserMetadata:completion] | |
Update User Attributes | [[rtm getStorage] updateChannelMetadata:data:options:completion] | |
Subscribe User Attributes | [[rtm getStorage] subscribeUserMetadata:completion] | |
Unsubscribe User Attributes | [[rtm getStorage] unsubscribeUserMetadata:completion] | |
Lock | Set Lock | [[rtm getLock] setLock:channelType:lockName:ttl:completion] |
Acquire Lock | [[rtm getLock] acquireLock:channelType:lockName:retry:completion] | |
Release Lock | [[rtm getLock] releaseLock:channelType:lockName:completion] | |
Revoke Lock | [[rtm getLock] revokeLock:channelType:lockName:userId:completion] | |
Query Lock | [[rtm getLock] getLocks:channelType:completion] | |
Remove Lock | [[rtm getLock] removeLock:channelType:lockName:completion] |