The chat client class, which is the entry of the chat SDK. It defines how to log in to and log out of the chat app and how to manage the connection between the SDK and the chat server.

Hierarchy

  • BaseManager
    • ChatClient

Properties

_eventEmitter?: NativeEventEmitter
eventType: number = 2
TAG: string = 'ChatClient'

Accessors

  • get chatManager(): ChatManager
  • Gets the chat manager class.

    This method can be called only after the chat client is initialized.

    Returns ChatManager

    The chat manager class.

  • get contactManager(): ChatContactManager
  • Gets the contact manager class.

    This method can be called only after the chat client is initialized.

    Returns ChatContactManager

    The contact manager class.

  • get currentUserName(): string
  • Gets the current logged-in user ID.

    Note

    The user ID for successful login is valid.

    The user ID is obtained from the memory and updated in the case of login, logout, and reconnection upon disconnection. You can call getCurrentUsername to get the latest data from the server.

    Returns string

    The current logged-in user ID.

  • get groupManager(): ChatGroupManager
  • Gets the chat group manager class.

    This method can be called only after the chat client is initialized.

    Returns ChatGroupManager

    The chat group manager class.

  • get options(): undefined | ChatOptions
  • Gets the SDK configurations.

    Ensure that you set the SDK options during initialization. See ChatOptions.

    Returns undefined | ChatOptions

    The SDK configurations.

  • get presenceManager(): ChatPresenceManager
  • Gets the presence manager class.

    This method can be called only after the chat client is initialized.

    Returns ChatPresenceManager

    The presence manager class.

  • get pushManager(): ChatPushManager
  • Gets the push manager class.

    This method can be called only after the chat client is initialized.

    Returns ChatPushManager

    The push manager class.

  • get roomManager(): ChatRoomManager
  • Gets the chat room manager class.

    This method can be called only after the chat client is initialized.

    Returns ChatRoomManager

    The chat room manager class.

  • get userManager(): ChatUserInfoManager
  • Gets the user information manager class.

    This method can be called only after the chat client is initialized.

    Returns ChatUserInfoManager

    The user information manager class.

  • get version(): string
  • Returns string

Methods

  • Adds the connection status listener.

    Parameters

    Returns void

  • Adds a custom listener to receive data that the iOS or Android devices send to the React Native layer.

    Parameters

    Returns void

  • Add error listener.

    Monitor SDK internal errors.

    Parameters

    Returns void

  • Adds the multi-device listener.

    Parameters

    Returns void

  • Updates the App Key, which is the unique identifier used to access the chat service.

    Note

    • As this key controls access to the chat service for your app, you can only update the key when the current user is logged out.

    • Updating the App Key means to switch to a new App Key.

    • You can retrieve the new App Key from the Console.

    • You can also set an App Key by using the ChatOptions.appKey method when logged out.

    Parameters

    • newAppKey: string

      The new App Key. Ensure that you set this parameter.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Compresses the debug log file into a gzip archive.

    We strongly recommend that you delete this debug archive once it is no longer used.

    Returns Promise<undefined | string>

    The path of the compressed gzip file.

    A description of the exception. See ChatError.

  • Creates a new user (open registration).

    Note

    There are two registration modes:

    • Open registration: This mode is for testing use, but not recommended in a formal environment; If a call failure occurs, you can contact our business manager.

    • Authorized registration: You can create a new user through a REST API, and then save it to your server or return it to the client.

    Parameters

    • userId: string

      The user ID. Ensure that you set this parameter. The user ID can be a maximum of 64 characters of the following types: - 26 English letters (a-z) - 10 numbers (0-9), - "", "-", "." The user ID is case-insensitive, so Aa and aa are the same user ID. The email address or the UUID of the user cannot be used as the user ID. You can also set this parameter with the regular expression ^[a-zA-Z0-9-]+$.

    • password: string

      The password. Ensure that you set this parameter. The password can contain a maximum of 64 characters.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Gets the token for login.

    Returns Promise<string>

    The token for login.

    A description of the exception. See ChatError.

  • Gets the current logged-in user ID from the server.

    Note

    To get the current logged-in user ID from the memory, see currentUserName.

    Returns Promise<string>

    The logged-in user ID.

    A description of the exception. See ChatError.

  • Returns NativeEventEmitter

  • Gets the list of online devices to which you have logged in with a specified account.

    Parameters

    • userId: string

      The user ID.

    • pwdOrToken: string

      The password or token.

    • OptionalisPassword: boolean

      If true, use password, otherwise use token. Default is true. See pwdOrToken

    Returns Promise<ChatDeviceInfo[]>

    The list of the online logged-in devices.

    A description of the exception. See ChatError.

  • Initializes the SDK.

    Note

    • Make sure to initialize the SDK in the main thread.
    • This method must be called before any other methods are called.

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Checks whether the SDK is connected to the chat server.

    Returns Promise<boolean>

    Whether the SDK is connected to the chat server. - true: Yes. - false: No.

    A description of the exception. See ChatError.

  • Checks whether the current user is logged in to the app.

    Note

    This method needs to be called after initialization and before login.

    Returns Promise<boolean>

    Whether the user is logged in to the app: - true: The user is logged in to the app. In automatic login mode, the SDK returns true before successful login and false otherwise. - false: The user is not logged in to the app. In non-automatic login mode, the SDK returns false.

    A description of the exception. See ChatError.

  • Logs out from a specified account on all devices.

    Parameters

    • userId: string

      The user ID.

    • pwdOrToken: string

      The password or token.

    • OptionalisPassword: boolean

      Whether the password or user token is used. See pwdOrToken.

      • (Default)true:The password is used.
      • false: The user token is used.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Logs out from a specified account on a device.

    For how to get the device ID, see ChatDeviceInfo.resource.

    Parameters

    • userId: string

      The user ID.

    • pwdOrToken: string

      The password or token.

    • resource: string

      The device ID. See ChatDeviceInfo.resource.

    • OptionalisPassword: boolean

      Whether the password or user token is used. See pwdOrToken.

      • (Default)true:The password is used.
      • false: The user token is used.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Logs in to the chat server with a password or an Easemob token. An exception message is thrown if the login fails.

    Note

    If you use an Easemob token to log in to the server, you can get the token in either of the following ways:

    The token expiration reminder is returned by the two callback methods: ChatConnectEventListener.onTokenWillExpire and ChatConnectEventListener.onTokenDidExpire.

    Parameters

    • userId: string

      The user ID. See createAccount.

    • pwdOrToken: string

      The password or token. See createAccount or getAccessToken

    • isPassword: boolean = true

      Whether to log in with a password or a token. - true: A password is used. - (Default) false: A token is used.

    Returns Promise<void>

    A description of the exception. See ChatError.

    Please use with loginWithToken instead.

  • Parameters

    • userId: string

      The user ID. See createAccount.

    • agoraToken: string

      The Agora token.

    Returns Promise<void>

    2023-11-17 Use login instead.

    Logs in to the chat server with the user ID and an Agora token. An exception message is thrown if the login fails.

    Note

    The Agora token is different from token login.token provided by Easemob.

    This method supports automatic login.

    A description of the exception. See ChatError.

  • Logs in to the chat server with a token. An exception message is thrown if the login fails.

    Note

    If you use a token to log in to the server, you can get the token in either of the following ways:

    • Through the console.

    The token expiration reminder is returned by the two callback methods: ChatConnectEventListener.onTokenWillExpire and ChatConnectEventListener.onTokenDidExpire.

    Parameters

    • userId: string

      The user ID.

    • token: string

      The token.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Logs out of the chat app. An exception message is thrown if the logout fails.

    Parameters

    • unbindDeviceToken: boolean = true

      Whether to unbind the token upon logout. This parameter is available only to mobile platforms.

      • (Default) true: Yes.
      • false: No.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Removes all the connection status listeners for the chat server.

    Returns void

  • Removes all the custom listeners.

    Returns void

  • Remove all error listener.

    Returns void

  • Removes all the multi-device listeners.

    Returns void

  • Removes the connection status listener.

    Parameters

    Returns void

  • Removes a custom listener to stop receiving data that the iOS or Android devices send to the React Native layer.

    Parameters

    Returns void

  • Removes the specified multi-device listener.

    Parameters

    Returns void

  • Renews the Agora token.

    Note

    If you log in with an Agora token and are notified by the callback method ChatConnectEventListener that the token is to expire, you can call this method to update the token to avoid unknown issues caused by an invalid token.

    Parameters

    • agoraToken: string

      The new Agora token.

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Parameters

    • event: NativeEventEmitter

    Returns void

  • Update push configurations.

    Note For the iOS platform, you need to pass the device ID during initialization. Otherwise, the push function cannot be used properly. See ChatClient.init

    Parameters

    Returns Promise<void>

    A description of the exception. See ChatError.

  • Type Parameters

    • T

    Parameters

    • method: string
    • Optionalargs: {}

      Returns Promise<T>

    • Parameters

      • result: any

      Returns void

    • Parameters

      Returns void

    • Parameters

      Returns void