Signaling API¶
Methods¶
Note
Only the built-in attributes come after an underscore; the custom attributes do not.
Life Cycle¶
Get an AgoraAPIOnlySignal Instance (getInstance)¶
This method gets an AgoraAPIOnlySignal instance.
public static AgoraAPIOnlySignal getInstance(Context context, String appId);
Parameter | Description |
context | Context of the Android activity. |
appId | The App ID provided by Agora. For more information, see Get an App ID . |
Destroy the AgoraAPIOnlySignal Instance (destroy)¶
This method destroys the AgoraAPIOnlySignal instance.
public void destroy();
Set a Callback (callbackSet)¶
This method sets a callback.
public native void callbackSet(ICallBack handler);
Parameter | Description |
handler | A handler of ICallBack. |
Note
Avoid using synchronous or blocking callback operations. Otherwise, the signaling system may crash.
Get a Callback (callbackGet)¶
This method gets an ICallBack object.
public ICallBack callbackGet();
Return Value | Description |
ICallBack | An object of ICallBack. |
Login¶
Login (login)¶
public void login(String appId,String account,String token,int uid,String deviceID);
Use this method to login Agora’s signaling system. Users must always login before performing any operation.
- When login is successful, it triggers the onLoginSuccess callback,
- When login fails, it triggers the onLoginFailed callback,
- When the SDK loses connection with the server, it triggers the onLogout callback.
Parameter | Description |
appId | The App ID provided by Agora. For more information, see Get an App ID . |
account | User ID defined by the client. It can be up to 128 visible characters (space is not allowed). It can be a uid, nickname, guid, and other content that must be unique. The account parameters in this document follow this rule. |
token | SignalingToken generated by the App ID and App Certificate. See Get a SignalingToken for details. |
uid | N/A: Set it as 0 |
deviceID | Set it as NULL. |
Note
You can skip the generation of the token in a test environment by setting token to _no_need_token. Agora does not recommend doing so in a production environment. By default, if you are already logged in, the call of login() will be ignored. To cancel the previous login, call logout() beforehand without having to wait until it is successfully executed.
Login (login2)¶
public void login2(String appId,String account,String token,int uid,String deviceID, int retry_time_in_s, int retry_count);
Use this method to login Agora’s signaling system. Users must always login before performing any operation.
- When login is successful, it triggers the onLoginSuccess callback,
- When login fails, it triggers the onLoginFailed callback,
- When the SDK loses connection with the server, it triggers the onLogout callback.
Parameter | Description |
appId | App ID provided by Agora. For more information, see Get an App ID . |
account | User ID defined by the client. It can be up to 128 visible characters (space is not allowed). It can be a uid, nickname, guid and other content that is unique. The account parameters in this document follow this rule. |
token | SignalingToken generated by the App ID and App Certificate. See Get a SignalingToken for details. |
uid | N/A: Set it as 0 |
deviceID | Set it as NULL. |
retry_time_in_s | Maximum time allowed to re-login, 30 seconds by default. |
retry_count | Maximum times allowed to re-login, 3 times by default. |
Note
You can skip the generation of the token in a test environment by setting token to _no_need_token. Agora does not recommend doing so in a production environment. onLoginFailed will be triggered when either retry_time_in_s or retry_count is reached.
Logout (logout)¶
It triggers the onLogout callback upon a successful execution.
public void logout();
Remote Calling Process (invoke)¶
public void invoke(String name, String req, String callID);
This method is used for the remote calling process. When called successfully, it will trigger the onInvokeRet callback.
Function | Parameter Settings and Returns |
Query the user status |
|
Set a user attribute |
|
Get a user attribute |
|
Get all attributes of a user |
|
Retrieve the number of the users in a channel |
|
Check if a user is in a specific channel |
|
Get a list of the users in a channel |
|
Get a list of the latest users in a channel |
|
Clear all attributes of a specific channel |
|
Delete an attribute of a specific channel |
|
Set an attribute of a specific channel |
|
Query the User Status (queryUserStatus)¶
This method checks whether a user is online. Calling this method triggers the onQueryUserStatusResult callback.
public void queryUserStatus(String account);
Parameter | Description |
account | Account of the user. |
Set a User Attribute (setAttr)¶
public void setAttr(String name,String value);
This method sets the user attributes.
Parameter | Description |
name | The attribute name, can be up to 128 visible characters. For example, _conn_timeout is the built-in attribute and refers to the offline timeout in seconds. It is set to 120s by default value and ranges between 20s and 120s. The SDK automatically readjusts settings below 20s to 20s and settings exceeding 120s to 120s. |
value | Attribute value, can be up to 8096 visible characters. |
Get Your Specified Attribute (getAttr)¶
This method gets your specified attribute. It triggers the onUserAttrResult callback when called successfully.
public void getAttr(String name);
Parameter | Description |
---|---|
name | Attribute name. It can be up to 128 visible characters |
Get all of Your Attributes (getAttrAll)¶
This method gets all of your attributes. You will receive the onUserAttrAllResult callback upon a successful execution.
public void getAttrAll();
Get the Attributes of a Specified User (getUserAttr)¶
This method allows the user to get the attributes of a specified user. The user will receive the onUserAttrResult callback.
public void getUserAttr(String account,String name);
Parameter | Description |
---|---|
account | User ID defined by the client. |
name | Attribute name. It can be up to 128 visible characters |
Get all Attributes of a Specified User (getUserAttrAll)¶
This method allows the user to get all the attributes of a specified user. The user will receive the onUserAttrAllResult callback upon a successful execution.
public void getUserAttrAll(String account);
Parameter | Description |
---|---|
account | User ID defined by the client. |
Send a Point-to-point Message (messageInstantSend)¶
This method sends a point-to-point message to a specified user.
Upon successful execution, the user receives the onMessageSendSuccess callback, and the other user receives the onMessageInstantReceive callback.
If execution fails, the user receives the onMessageSendError callback.
public void messageInstantSend(String account,int uid,String msg,String msgID);
Parameter | Description |
account | User ID defined by the client. |
uid | N/A: Set as 0. |
msg | Message body. Each message must not exceed 8196 visible characters. |
msgID | Message ID. |
The Channel¶
Join a Channel (channelJoin)¶
This method allows the users to join a specified channel.
Once the user joins a channel, he/she receives the onChannelJoined callback, and the other users in the same channel receive the onChannelUserJoined callback. If the user fails to join a specified channel, he/she receives an onChannelJoinFailed callback.
public void channelJoin(String channelID);
Parameter | Description |
channelID | Channel name. It can be up to 128 visible characters and include the following special channel names and attributes:
|
Note
Special channels are used by servers only to receive login and channel events.
Leave a Channel (channelleave)¶
This method allows users to leave the current channel. Once the user has left the channel, the other users in the channel receive the onChannelUserLeaved callback.
public void channelLeave(String channelID);
Parameter | Description |
---|---|
channelID | Channel name. It can be up to 128 visible characters. |
Query the Number of Users in a Channel (channelQueryUserNum)¶
This method allows a user to query the number of users in a specified channel. Upon a successful execution, the user will receive the onChannelQueryUserNumResult callback.
public void channelQueryUserNum(String channelID);
Parameter | Description |
---|---|
channelID | Channel name. It can be up to 128 visible characters. |
Query if a User is in a Channel (channelQueryUserIsIn)¶
public void channelQueryUserIsIn(String channelID, String account)
Use this method to query if a specified user is in a specified channel. It triggers the onChannelQueryUserIsIn callback upon successful execution.
Parameter | Description |
channelID | Channel name. Maximum length is 128 visible characters. |
account | User ID defined by the client. |
Set the Channel Attributes (channelSetAttr)¶
This method sets the channel attributes. Whenever a change is made to the attributes, all users in the channel will receive the onChannelAttrUpdated callback.
public void channelSetAttr(String channelID,String name,String value);
Parameter | Description |
channelID | Channel name, can be up to 128 visible characters. |
name | Attribute name, can be up to 128 visible characters. |
value | Attribute value, can be up to 8096 visible characters. |
The following table shows the in-built attributes of the parameter, name:
Attributes | Description |
_userNotification |
|
_channel_ttl | Time (s) between the last user leaving a channel and the system destroying the channel. The default value is 7200. A special channel will never be destroyed. |
_member_num | Number of the users currently in the channel. It is automatically updated by the system. |
_auto_update_num | Indicates whether to automatically refresh the number of the users currently in the channel.
|
Delete the Channel Attributes (channelDelAttr)¶
This method deletes the channel attributes. All users in the channel will receive the onChannelAttrUpdated callback, when the method is called successfully.
public void channelDelAttr(String channelID,String name);
Parameter | Description |
---|---|
channelID | Channel name. It can be up to 128 visible characters. |
name | Attribute name. It can be up to 128 visible characters. |
Delete all Channel Attributes (channelClearAttr)¶
This method deletes all attributes of a specified channel. When it is called successfully, all users in the channel will receive the onChannelAttrUpdated callback.
public void channelClearAttr(String channelID);
Parameter | Description |
---|---|
channelID | Channel name. It can be up to 128 visible characters. |
Send a Channel Message (messageChannelSend)¶
This method sends a channel message, and all users in the same channel receive the onMessageChannelReceive callback.
The user who sent the message receives the onMessageSendSuccess callback upon a successful execution; otherwise, receives the onMessageSendError callback.
public void messageChannelSend(String channelID,String msg,String msgID);
Parameter | Description |
channelID | Channel name. It can be up to 128 visible characters. |
msg | Message body. Each channel message must not exceed 8196 visible characters. Each user cannot send more than 60 messages per second, and the entire channel cannot send more than 1,000 messages per second. |
msgID | Visible characters, can be set to NULL. It marks the callback message. |
Calling¶
Initiate a Call (channelInviteUser)¶
This method initiates a call, that is, invites a user to join a specified channel.
Note
Calling and joining a channel are two separate processes. The user has to call channelJoin() to join the channel. The user can either join the channel before sending a call invitation or send a call invitation before joining the channel (when the counterpart accepts the invitation).
If the call fails, the user will receive the onInviteFailed callback. Possible reasons include:
- The other user is offline;
- Local network issues;
- Server errors;
If the caller gets a confirmation from the callee, the caller will receive the onInviteReceivedByPeer callback, and the callee will receive the onInviteReceived callback.
public void channelInviteUser(String channelID,String account,int uid);
Parameter | Description |
---|---|
channelID | Channel name. It can be up to 128 visible characters. |
account | User ID of the other user defined by the client. |
uid | N/A. Set as 0. |
Initiate a Call (channelInviteUser2)¶
Same as channelInviteUser except for the parameters.
public void channelInviteUser2(String channelID,String account,String extra);
Parameter | Description |
channelID | Channel name: It can be up to 128 visible characters. |
account | User ID of the other user defined by the client. |
extra | Extra information to send to the user being called. It can be up to 8196 visible characters and must be in the JSON format. For example, it may have the following fields:
|
Note
You do not need to set the _require_peer_online field when making a SIP call.
Send a DTMF (Dual-tone Multi-frequency) Message to the Other User (channelInviteDTMF)¶
This method sends a DTMF message to the other user by calling through the SIP gateway. The receiver will receive the onInviteMsg callback.
public void channelInviteDTMF(String channelID,String phoneNum,String dtmf);
Parameter | Description |
---|---|
channelID | Channel name. It can be up to 128 visible characters. |
phoneNum | Phone number of the other user. |
dtmf | Subsequent analog phone number (DTMF) to be entered after the call gets through. |
Accept a Call (channelInviteAccept)¶
This method accepts the received call request/invitation. Once this API is called, the other user will receive the onInviteAcceptedByPeer callback.
public void channelInviteAccept(String channelID,String account,int uid,String extra);
Parameter | Description |
---|---|
channelID | Channel name. It can be up to 128 visible characters. |
account | The caller’s user ID. |
uid | N/A. Set as 0. |
extra | In JSON format. Can be “”. User-defined information. Can be used for a SIP call. |
Reject a Call (channelInviteRefuse)¶
This method rejects a call invitation/request. Once this API is called, the other user receives the onInviteRefusedByPeer callback.
public void channelInviteRefuse(String channelID,String account,int uid, String extra);
Parameter | Description |
channelID | Channel name. It can be up to 128 visible characters. |
account | User ID of the other user defined by the client. |
uid | N/A: Set as 0. |
extra | Extra information. It can be up to 8196 visible characters and must be in the JSON format. |
End a Call (channelInviteEnd)¶
This method ends a call after the call has been connected. The user receives the onInviteEndByMyself callback, and the other user receives the onInviteEndByPeer callback.
public void channelInviteEnd(String channelID,String account,int uid);
Parameter | Description |
---|---|
channelID | Channel name. It can be up to 128 visible characters. |
account | User ID of the other user defined by the client. |
uid | N/A. Set as 0. |
Miscellaneous¶
Get the User Status (getStatus)¶
This method gets the user status.
public int getStatus();
Return Value | Description |
LOGIN_STATE_NOT_LOGIN | 0: The user has not logged in. |
LOGIN_STATE_LOGINING | 1: The user is logging in. |
LOGIN_STATE_LOGINED | 2: The user has logged in. |
LOGIN_STATE_RECONNECTING | 3: The user is reconnecting. |
Get the SDK Version (getSdkVersion)¶
This method gets the version of the SDK.
public int getSdkVersion();
Return Value | Description |
The SDK version. | For example, 1010104019 means version 1.1.4.19. |
Send a Channel Message (messageChannelSendForce)¶
This method sends a channel message without joining the channel. Agora does not recommend using it at the application level.
public native void messageChannelSendForce(String channelID,String msg,String msgID);
Parameter | Description |
channelID | The channel ID. |
msg | The message to send. |
msgID | The ID of the message. |
Obsolete Interfaces¶
Interfaces | Prototype |
messageDTMFSend | public void messageDTMFSend(int uid,String msg,String msgID); |
channelInvitePhone | public void channelInvitePhone(String channelID,String phoneNum,int uid); |
channelInvitePhone2 | public void channelInvitePhone2(String channelID,String phoneNum,String sourcesNum); |
channelInvitePhone3 | public void channelInvitePhone3(String channelID,String phoneNum,String sourcesNum,String extra); |
isOnline | public int isOnline(); |
Callbacks¶
The following callbacks are related to Agora’s signaling system.
Connection Lost Callback (onReconnecting)¶
This callback is triggered when the connection to Agora’s signaling system is lost after login.
public void onReconnecting(int nretry);
Parameter | Description |
---|---|
nretry | The current reconnection number. |
Error Callback (onError)¶
This callback returns a detailed description of the error.
public void onError(String name,int ecode,String desc)
Parameter | Description |
name | Error type. |
ecode | Error code. For more information, see Error Codes and Warning Codes.
|
desc | Description of the error. |
User Status Query Callback (onQueryUserStatusResult)¶
This callback returns the query result of the user status. It is triggered when queryUserStatus() is called.
public void onQueryUserStatusResult(String name,String status)
Parameter | Description |
name | Account of the user. |
status | Status of the user: Whether the user is online.
|
Connection Recovered Callback (onReconnected)¶
public void onReconnected(int fd);
This callback is triggered when the application is reconnected to Agora’s signaling system. When the reconnection fails, the onLogout callback will be triggered instead.
Parameter | Description |
---|---|
fd | Agora internal use only. |
User Online Callback (onLoginSuccess)¶
public void onLoginSuccess(int uid,int fd);
This callback is triggered when a user is logged into Agora’s signaling system.
Parameter | Description |
uid | N/A. Set as 0. |
fd | Agora internal use only. |
User Offline Callback (onLogout)¶
public void onLogout(int ecode);
This callback is triggered when a user logged out of Agora’s signaling system.
Parameter | Description |
---|---|
ecode | Error code |
User Login Failed Callback (onLoginFailed)¶
public void onLoginFailed(int ecode);
This callback is triggered when the user fails to login Agora’s signaling system.
Parameter | Description |
---|---|
ecode | Error code |
Remote Calling Process Succeeded Callback (onInvokeRet)¶
void onInvokeRet(String callID, String err, String resp);
This callback is triggered when the remote calling process succeeds.
Parameter | Description |
callID | Call ID introduced by invoke() |
err | Error code |
resp | Returned JSON value |
User Joined Channel Callback (onChannelJoined)¶
public void onChannelJoined(String channelID);
This callback is triggered when a user has joined a channel.
Parameter | Description |
---|---|
channelID | Channel name |
User Failed to Join Channel Callback (onChannelJoinFailed)¶
public void onChannelJoinFailed(String channelID,int ecode);
This callback is triggered when a user fails to join a channel.
Parameter | Description |
---|---|
channelID | Channel name |
ecode | Error code |
User Left Channel Callback (onChannelLeaved)¶
public void onChannelLeaved(String channelID,int ecode);
This callback is triggered when a user has left a channel.
Parameter | Description |
---|---|
channelID | Channel name |
ecode | error code |
Other User Joined Channel Callback (onChannelUserJoined)¶
public void onChannelUserJoined(String account,int uid);
This callback is triggered when another user joined the channel.
Parameter | Description |
account | User ID defined by the client. |
uid | N/A: Set as 0. |
Other User Left Channel Callback (onChannelUserLeaved)¶
public void onChannelUserLeaved(String account,int uid);
This callback is triggered when another user has left the channel.
Parameter | Description |
account | User ID defined by the client. |
uid | N/A: Set as 0. |
User List Callback (onChannelUserList)¶
public void onChannelUserList(String[] accounts, int[] uids);
A user will receive this callback when he/she has joined a channel.
Note
The retrieved user list includes 200 users at the most.
Parameter | Description |
account | User ID defined by the client. |
uids | List of users in the channel. |
Number of Users Callback (onChannelQueryUserNumResult)¶
public void onChannelQueryUserNumResult(String channelID,int ecode,int num);
This callback is triggered when a user queries the number of users in a channel.
Parameter | Description |
---|---|
channelID | Channel name |
ecode | Error code |
num | The query result |
Query Whether a User is in a Channel Status Callback (onChannelQueryUserIsIn)¶
public virtual void onChannelQueryUserIsIn(std::string channelID, std::string account, int isIn){}
This callback is triggered when a user queries whether he/she is in the channel.
Parameter | Description |
channelID | Channel name. |
account | User ID defined by the client. |
isIn | Whether the user is in the channel:
|
Channel Attribute Changed Callback (onChannelAttrUpdated)¶
public void onChannelAttrUpdated(String channelID,String name,String value,String type);
This callback is triggered when the channel attribute is changed.
Parameter | Description |
channelID | Channel name. |
name | Attribute name. |
value | Attribute value. |
type | Change types:
|
Call Invitation Received Callback (onInviteReceived)¶
public void onInviteReceived(String channelID,String account,int uid,String extra);
This callback is received by the callee when the callee has received a call invitation/request.
Parameter | Description |
channelID | Channel name. |
account | User ID of the other user defined by the client. |
uid | N/A: Set as 0. |
extra | Extra information to send to the user being called. It can be up to 8196 visible characters and must be in the JSON format. |
Callee Received Call Callback (onInviteReceivedByPeer)¶
public void onInviteReceivedByPeer(String channelID,String account,int uid);
This callback is received by the caller when the callee has received the call invitation/request.
Parameter | Description |
---|---|
channelID | Channel name |
account | User ID of the callee defined by the client. |
uid | N/A |
Callee Accepted Call Callback (onInviteAcceptedByPeer)¶
public void onInviteAcceptedByPeer(String channelID,String account,int uid, String extra);
This callback is received by the caller when the callee has accepted the call invitation/request.
Parameter | Description |
---|---|
channelID | Channel name |
account | User ID of the callee defined by the client. |
uid | N/A |
extra | Extra information the caller wants to send to the callee. For example, this is a video call or voice call. It must be in JSON format. |
Callee Rejected Call Callback (onInviteRefusedByPeer)¶
public void onInviteRefusedByPeer(String channelID,String account,int uid, String extra);
This callback is received by the caller when the callee rejects the call invitation/request.
Parameter | Description |
channelID | Channel name. |
account | User ID of the callee defined by the client. |
uid | N/A: Set as 0. |
extra | Extra information: NULL or in JSON format. |
Call Failed Callback (onInviteFailed)¶
public void onInviteFailed(String channelID,String account,int uid,int ecode, String extra);
This callback is triggered when a call fails.
Parameter | Description |
---|---|
channelID | Channel name |
account | User ID of the other user defined by the client. |
uid | N/A |
extra | Extra information: NULL or in JSON format. |
Other User Ended Call Callback (onInviteEndByPeer)¶
public void onInviteEndByPeer(String channelID,String account,int uid, String extra);
This callback is triggered when the callee ends the call.
Parameter | Description |
---|---|
channelID | Channel name. |
account | User ID of the callee defined by the client. |
msg | Message body |
extra | Extra information the caller wants to send to the callee. For example, this is a video call or voice call. It must be in JSON format. |
Call Ended Callback (onInviteEndByMyself)¶
public void onInviteEndByMyself(String channelID,String account,int uid);
This callback is received by the user when the other user ends the call.
Parameter | Description |
---|---|
channelID | Channel name. |
account | User ID of the user defined by the client. |
uid | N/A. |
Message Received Callback (onInviteMsg)¶
public void onInviteMsg(String channelID, String account, int uid, String msgType, String msgData, String extra)
This callback is triggered when you have received a DTMF message sent from the other user.
Parameter | Description |
---|---|
channelID | Channel name. It can be up to 128 visible characters. |
account | User ID of the other user defined by the client. |
uid | N/A. |
msgType | Message type (DTMF). |
msgData | Detailed DTMF message. Supported strings include: 0-9, * and #. |
extra | Extra information of the call, which can be a string, a JSON string, or NULL. |
Message Failed Callback (onMessageSendError)¶
public void onMessageSendError(String messageID,int ecode);
This callback is triggered when a user fails to send a message.
Parameter | Description |
---|---|
messageID | Message ID |
ecode | Error code |
Message Sent Callback (onMessageSendSuccess)¶
public void onMessageSendSuccess(String messageID);
This callback is triggered when a user sent a message successfully.
Parameter | Description |
---|---|
messageID | Message ID |
Message Received Callback (onMessageInstantReceive)¶
public void onMessageInstantReceive(String account,int uid,String msg);
This callback notifies a user that he/she has received a message.
Parameter | Description |
---|---|
account | User ID defined by the client |
uid | N/A |
msg | Message body |
Channel Message Received Callback (onMessageChannelReceive)¶
public void onMessageChannelReceive(String channelID,String account,int uid,String msg);
This callback is trigged when a channel message is received.
Parameter | Description |
---|---|
channelID | Channel name |
account | User ID defined by the client |
uid | N/A |
msg | Message body |
Log Printed Callback (onLog)¶
public void onLog(String txt);
This callback is trigged when a line is printed in a log file.
Parameter | Description |
---|---|
txt | Line in the log file |
Attribute Received Callback (onUserAttrResult)¶
public void onUserAttrResult(String account,String name,String value);
This callback is triggered when the user queries an attribute of a specific user.
Parameter | Description |
account | User ID defined by the client. |
name | Attribute name. |
value | Value of the attribute. |
All Attribute Received Callback (onUserAttrAllResult)¶
public void onUserAttrAllResult(String account,String value);
This callback is triggered when the user queries all attributes of a specified user.
Parameter | Description |
account | User ID defined by the client. |
value | JSON values of all attributes of the user. |