Package io.agora.rtm
Class RtmClient
java.lang.Object
io.agora.rtm.RtmClient
The RtmClient class.
This class provides the main methods that can be invoked by your app.
RtmClient is the basic interface class of the Agora RTM SDK.
Creating an RtmClient object and then calling the methods of
this object enables you to use Agora RTM SDK's functionality.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidaddEventListener(RtmEventListener listener) Adds an event listener for receiving rtm events.static RtmClientCreate rtm client instance.abstract StreamChannelcreateStreamChannel(String channelName) Create a stream channel instance.abstract StringgetErrorReason(RtmConstants.RtmErrorCode errorCode) Convert error code to error string.abstract RtmHistoryGet the history instance.static RtmClientGet rtm client instance.abstract RtmLockgetLock()Get the lock instance.abstract RtmPresenceGet the presence instance.abstract RtmStorageGet the storage instance.static StringGet the version info of the Agora RTM SDK.abstract voidlogin(String token, ResultCallback<Void> resultCallback) Login the Agora RTM service.abstract voidlogout(ResultCallback<Void> resultCallback) Logout the Agora RTM service.abstract voidpublish(String channelName, byte[] message, PublishOptions options, ResultCallback<Void> resultCallback) Publish a binary message in the channel.abstract voidpublish(String channelName, String message, PublishOptions options, ResultCallback<Void> resultCallback) Publish a string message in the channel.static voidrelease()Release the rtm client instance.abstract voidremoveEventListener(RtmEventListener listener) Remove the specified event listener.abstract voidrenewToken(String token, ResultCallback<Void> resultCallback) Renews the token.abstract RtmConstants.RtmErrorCodesetParameters(String parameters) Set parameters of the sdk or engineabstract voidsubscribe(String channelName, SubscribeOptions options, ResultCallback<Void> resultCallback) Subscribe a channel.abstract voidunsubscribe(String channelName, ResultCallback<Void> resultCallback) Unsubscribe a channel.
-
Constructor Details
-
RtmClient
public RtmClient()
-
-
Method Details
-
create
Create rtm client instance.- Returns:
- If the method call succeeds, will return
RtmClientinstance, if the method call fails, will throw an exception. - Throws:
Exception- If error occurs
-
getInstance
Get rtm client instance.- Returns:
- The instance of RtmClient
RtmClient.
-
release
public static void release()Release the rtm client instance. -
getVersion
Get the version info of the Agora RTM SDK.- Returns:
- The version info of the Agora RTM SDK.
-
addEventListener
Adds an event listener for receiving rtm events.Note: The listener must implement the RtmEventListener interface or use RtmEventListener default implements if do not care about some event.
- Parameters:
listener- the RtmEventListener object to be added
-
removeEventListener
Remove the specified event listener.Note: By removing the event listener, the listener will no longer receive notifications from rtm client.
- Parameters:
listener- The event specified listener object
-
login
Login the Agora RTM service.- Parameters:
token- Token used to login RTM service.resultCallback- AResultCallbackobject. - Success: will receives theResultCallback.onSuccess(Object)callback. - Failure: will receives theResultCallback.onFailure(ErrorInfo)callback.
-
logout
Logout the Agora RTM service.- Parameters:
resultCallback- AResultCallbackobject. - Success: will receives theResultCallback.onSuccess(Object)callback. - Failure: will receives theResultCallback.onFailure(ErrorInfo)callback.
-
getStorage
Get the storage instance.- Returns:
- The instance of
RtmStorage
-
getLock
Get the lock instance.- Returns:
- The instance of
RtmLock
-
getPresence
Get the presence instance.- Returns:
- The instance of
RtmPresence
-
getHistory
Get the history instance.- Returns:
- The instance of
RtmHistory
-
getErrorReason
Convert error code to error string.- Parameters:
errorCode- Received error code- Returns:
- The error reason
-
renewToken
Renews the token. Once a token is enabled and used, it expires after a certain period of time. You should generate a new token on your server, call this method to renew it.- Parameters:
token- The new tokenresultCallback- AResultCallbackobject. - Success: will receives theResultCallback.onSuccess(Object)callback. - Failure: will receives theResultCallback.onFailure(ErrorInfo)callback.
-
publish
public abstract void publish(String channelName, String message, PublishOptions options, ResultCallback<Void> resultCallback) Publish a string message in the channel.- Parameters:
channelName- The name of the channel.message- The content of the string message.options- The options of the message.resultCallback- AResultCallbackobject. - Success: will receives theResultCallback.onSuccess(Object)callback. - Failure: will receives theResultCallback.onFailure(ErrorInfo)callback.
-
publish
public abstract void publish(String channelName, byte[] message, PublishOptions options, ResultCallback<Void> resultCallback) Publish a binary message in the channel.- Parameters:
channelName- The name of the channel.message- The content of the string message.options- The options of the message.resultCallback- AResultCallbackobject. - Success: will receives theResultCallback.onSuccess(Object)callback. - Failure: will receives theResultCallback.onFailure(ErrorInfo)callback.
-
subscribe
public abstract void subscribe(String channelName, SubscribeOptions options, ResultCallback<Void> resultCallback) Subscribe a channel.- Parameters:
channelName- The name of the channel.options- The options of subscribe the channel.resultCallback- AResultCallbackobject. - Success: will receives theResultCallback.onSuccess(Object)callback. - Failure: will receives theResultCallback.onFailure(ErrorInfo)callback.
-
unsubscribe
Unsubscribe a channel.- Parameters:
channelName- The name of the channel.resultCallback- AResultCallbackobject. - Success: will receives theResultCallback.onSuccess(Object)callback. - Failure: will receives theResultCallback.onFailure(ErrorInfo)callback.
-
setParameters
Set parameters of the sdk or engine- Parameters:
parameters- The parameters in json format- Returns:
RtmErrorCode
-
createStreamChannel
Create a stream channel instance.- Parameters:
channelName- The Name of the channel.- Returns:
- If the method call succeeds, will return
StreamChannelinstance, if the method call fails, will throw an exception. - Throws:
Exception- If error occurs
-