SDK quickstart
This page shows you how to create your first Signaling using Signaling SDK.
Understand the tech
Log in to Signaling
The login process includes:
-
The app client requests a token from your app server.
-
The app server returns the token to the app client.
-
The app client logs in to Signaling with the token.
Peer-to-peer messaging
The peer messaging process includes:
-
Client A sends a peer message to Signaling.
-
Signaling sends the message to client B. Client B receives the peer message.
Channel messaging
The channel messaging process includes:
-
Client A creates a channel and join the channel.
-
Client B and client C joins the channel created by client A.
-
Client A sends a channel message to Signaling.
-
Signaling sends the channel message to client B and C. Client B and client C receives the message.
For an app client to join a channel, you need the following information:
-
The App ID: A randomly generated string provided by Agora for identifying your app. You can get the App ID from Agora Console.
-
The user ID: The unique identifier of a user. You need to specify the user ID yourself, and ensure that it is unique in the channel.
-
A token: In a test or production environment, your app client retrieves tokens from your server.
-
The channel name: A string that identifies the channel for the channel messaging.
Prerequisites
In order to follow this procedure you must have:
-
A computer with Internet access.
Ensure that no firewall is blocking your network communication.
Create a Java project
Create a new folder RTM_quickstart
with the following subfolders:
Integrate Signaling SDK for Java
-
Download the latest version of Signaling SDK and decompress the file. Copy the
*.so
file and the*.jar
file to thelib
folder. -
Create a file named
pom.xml
inRTM_quickstart
with the following content:
Implement Signaling
Create a RtmJavaDemo.java
file in RTM_quickstart\src\main\java\io\agora
and implement the file with the following steps:
- Import the following libraries.
- Configure your App ID and token.
- Implement the
RtmChannelListener
interface and override the following callbacks:
onMessageReceived
: Occurs when the user receives a channel message. This callback returns sender uid and message instance.onMemberJoined
: Occurs when a member joins the channel. This callback returns the member uid.onMemberLeft
: Occurs when a member left the channel. This callback returns the member uid.
-
Implement the app class
RtmJavaDemo
with the following logic:- Initialize the client instance
- Override the following callbacks:
onConnectionStateChanged
: Occurs when the connection state changes and returns the new state with reasononMessageReceived
: Occurs when receiving a peer-to-peer message and returns a message instance and the sender uid- Log in to the Signaling
- Log out of the Signaling
- Send a peer-to-peer message
- Send a channel message
- Get channel member list
Test your Java app
Refer to the following steps to run the sample project:
-
Install the
.jar
file to local maven. -
Run
mvn package
in the folder ofpom.xml
. -
Run the sample project.
Considerations for Java
-
The Agora Signaling SDK supports creating multiple RtmClient instances that are independent of each other.
-
To send and receive peer-to-peer or channel messages, ensure that you have successfully logged in the Agora Signaling (you have received onSuccess.
-
To use any of the channel features, you must first call the createChannel method to create a channel instance.
-
You can create multiple channel instances for each RtmClient instance, but you can only join a maximum of 20 channels at the same time. The
channelId
parameter needs to be channel-specific. -
When you leave a channel and do not want to join it again, you can call the release method to release all resources used by the channel instance.
-
You cannot reuse a received RtmMessage instance.
Next steps
Generating a token by hand is not helpful in a production context. Authenticate Your Users with Tokens shows you how to start live streaming with a token that you retrieve from your server.