Package io.agora.rtm

Class RtmClient

java.lang.Object
io.agora.rtm.RtmClient

public abstract class RtmClient extends Object
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 Details

    • RtmClient

      public RtmClient()
  • Method Details

    • create

      public static RtmClient create(RtmConfig config) throws Exception
      Create rtm client instance.
      Returns:
      If the method call succeeds, will return RtmClient instance, if the method call fails, will throw an exception.
      Throws:
      Exception - If error occurs
    • getInstance

      public static RtmClient getInstance()
      Get rtm client instance.
      Returns:
      The instance of RtmClient RtmClient.
    • release

      public static void release()
      Release the rtm client instance.
    • getVersion

      public static String getVersion()
      Get the version info of the Agora RTM SDK.
      Returns:
      The version info of the Agora RTM SDK.
    • addEventListener

      public abstract void addEventListener(RtmEventListener listener)
      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

      public abstract void removeEventListener(RtmEventListener listener)
      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

      public abstract void login(String token, ResultCallback<Void> resultCallback)
      Login the Agora RTM service.
      Parameters:
      token - Token used to login RTM service.
      resultCallback - A ResultCallback object. - Success: will receives the ResultCallback.onSuccess(Object) callback. - Failure: will receives the ResultCallback.onFailure(ErrorInfo) callback.
    • logout

      public abstract void logout(ResultCallback<Void> resultCallback)
      Logout the Agora RTM service.
      Parameters:
      resultCallback - A ResultCallback object. - Success: will receives the ResultCallback.onSuccess(Object) callback. - Failure: will receives the ResultCallback.onFailure(ErrorInfo) callback.
    • getStorage

      public abstract RtmStorage getStorage()
      Get the storage instance.
      Returns:
      The instance of RtmStorage
    • getLock

      public abstract RtmLock getLock()
      Get the lock instance.
      Returns:
      The instance of RtmLock
    • getPresence

      public abstract RtmPresence getPresence()
      Get the presence instance.
      Returns:
      The instance of RtmPresence
    • getHistory

      public abstract RtmHistory getHistory()
      Get the history instance.
      Returns:
      The instance of RtmHistory
    • getErrorReason

      public abstract String getErrorReason(RtmConstants.RtmErrorCode errorCode)
      Convert error code to error string.
      Parameters:
      errorCode - Received error code
      Returns:
      The error reason
    • renewToken

      public abstract void renewToken(String token, ResultCallback<Void> resultCallback)
      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 token
      resultCallback - A ResultCallback object. - Success: will receives the ResultCallback.onSuccess(Object) callback. - Failure: will receives the ResultCallback.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 - A ResultCallback object. - Success: will receives the ResultCallback.onSuccess(Object) callback. - Failure: will receives the ResultCallback.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 - A ResultCallback object. - Success: will receives the ResultCallback.onSuccess(Object) callback. - Failure: will receives the ResultCallback.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 - A ResultCallback object. - Success: will receives the ResultCallback.onSuccess(Object) callback. - Failure: will receives the ResultCallback.onFailure(ErrorInfo) callback.
    • unsubscribe

      public abstract void unsubscribe(String channelName, ResultCallback<Void> resultCallback)
      Unsubscribe a channel.
      Parameters:
      channelName - The name of the channel.
      resultCallback - A ResultCallback object. - Success: will receives the ResultCallback.onSuccess(Object) callback. - Failure: will receives the ResultCallback.onFailure(ErrorInfo) callback.
    • setParameters

      public abstract RtmConstants.RtmErrorCode setParameters(String parameters)
      Set parameters of the sdk or engine
      Parameters:
      parameters - The parameters in json format
      Returns:
      RtmErrorCode
    • createStreamChannel

      public abstract StreamChannel createStreamChannel(String channelName) throws Exception
      Create a stream channel instance.
      Parameters:
      channelName - The Name of the channel.
      Returns:
      If the method call succeeds, will return StreamChannel instance, if the method call fails, will throw an exception.
      Throws:
      Exception - If error occurs