@asteriskzuo/react-native-easemob
Version:
easemob chat sdk of react-native.
214 lines (213 loc) • 8.15 kB
TypeScript
import { EventEmitter } from 'react-native';
import { ChatConnectionListener, ChatCustomListener, ChatMultiDeviceListener } from './ChatEvents';
import { ChatManager } from './ChatManager';
import { ChatDeviceInfo } from './common/ChatDeviceInfo';
import type { ChatOptions } from './common/ChatOptions';
import { Native } from './_internal/Native';
export declare class ChatClient extends Native {
static eventType: number;
private static TAG;
private static _instance;
private _connectionSubscriptions;
static getInstance(): ChatClient;
private setEventEmitter;
getEventEmitter(): EventEmitter;
private _chatManager;
private _connectionListeners;
private _multiDeviceListeners;
private _customListeners;
private _options?;
private _sdkVersion;
private _isInit;
private _currentUsername;
private constructor();
private setConnectNativeListener;
private setNativeListener;
onConnected(): void;
private onDisconnected;
private onTokenWillExpire;
private onTokenDidExpire;
private onMultiDeviceEvent;
private onCustomEvent;
private reset;
/**
* Get SDK Configurations. Make sure to set the param, see {@link EMOptions}.
*
* @returns The configurations.
*/
get options(): ChatOptions | undefined;
/**
* Get SDK version.
*/
get sdkVersion(): string;
/**
* Get current user name.
*
* The value is valid after successful login.
*/
get currentUserName(): string;
/**
* Get React-native SDK version.
*/
get rnSdkVersion(): string;
/**
* Make sure to initialize the SDK in the main thread. Make sure to set the param, see {@link ChatOptions}.
*
* **note**
*
* **This method must be called before any method can be called.**
*
* @param options The configurations.
*
* @throws Error, see {@link ChatError}
*/
init(options: ChatOptions): Promise<void>;
/**
* Check whether you have successfully connected to the server.
*
* @returns
* - `true`: The server has been connected.
* - `false`: The server is not connected.
*
* @throws Error, see {@link ChatError}
*/
isConnected(): Promise<boolean>;
/**
* Get current user name from native. Get cache see {@link currentUserName}
* @returns The user name.
*
* @throws Error, see {@link ChatError}
*/
getCurrentUsername(): Promise<string>;
/**
* Get login state.
*
* @returns
* - `true`: In automatic login mode, the value is true before successful login and false otherwise.
* - `false`: In non-automatic login mode, the value is false.
*
* @throws Error, see {@link ChatError}
*/
isLoginBefore(): Promise<boolean>;
/**
* Get login access token.
*
* @returns The token value.
*
* @throws Error, see {@link ChatError}
*/
getAccessToken(): Promise<string>;
/**
* Register a new user with your chat network.
*
* @param username The username. The maximum length is 64 characters. Ensure that you set this parameter. Supported characters include the 26 English letters (a-z), the ten numbers (0-9), the underscore (_), the hyphen (-), and the English period (.). This parameter is case insensitive, and upper-case letters are automatically changed to low-case ones. If you want to set this parameter as a regular expression, set it as ^[a-zA-Z0-9_-]+$.
* @param password The password. The maximum length is 64 characters. Ensure that you set this parameter.
*
* @throws Error, see {@link ChatError}
*/
createAccount(username: string, password: string): Promise<void>;
/**
* An app user logs in to the chat server with a password or token.
*
* @param userName The username, see {@link createAccount}.
* @param pwdOrToken The password or token, see {@link createAccount} or {@link getAccessToken}
* @param isPassword The password or token flag. true is the password, otherwise it is the token.
*
* @throws Error, see {@link ChatError}
*/
login(userName: string, pwdOrToken: string, isPassword?: boolean): Promise<void>;
/**
* An app user logs in to the chat server with a agora token.
*
* @param userName The username, see {@link createAccount}.
* @param agoraToken The token from agora api.
*
* @throws Error, see {@link ChatError}
*/
loginWithAgoraToken(userName: string, agoraToken: string): Promise<void>;
/**
* Renew token.
*
* When a user is in the Agora token login state and receives a callback
* notification of the token is to be expired in the {@link ChatConnectionListener}
* implementation class, this API can be called to update the token to
* avoid unknown problems caused by the token invalidation.
*
* @param agoraToken The new token.
*
* @throws Error, see {@link ChatError}
*/
renewAgoraToken(agoraToken: string): Promise<void>;
/**
* An app user logs out and returns the result.
*
* @param unbindDeviceToken Whether to unbind the token.
* - `true`: means to unbind the device token when logout.
* - `false`: means to not unbind the device token when logout.
* @throws Error, see {@link ChatError}
*/
logout(unbindDeviceToken?: boolean): Promise<void>;
/**
* Update the App Key, which is the unique identifier used to access Agora Chat.
*
* You retrieve the new App Key from Agora Console.
*
* As this key controls all access to Agora Chat for your app, you can only update the key when the current user is logged out.
*
* Also, you can set App Key by the following method when logged out {@link ChatOptions#appKey}.
*
* @param newAppKey The App Key, make sure to set the param.
*
* @throws Error, see {@link ChatError}
*/
changeAppKey(newAppKey: string): Promise<void>;
/**
* Compresses the debug log into a gzip archive.
*
* Best practice is to delete this debug archive as soon as it is no longer used.
*
* @returns The path of the compressed gz file.
*
* @throws Error, see {@link ChatError}
*/
compressLogs(): Promise<string | undefined>;
/**
* Gets all the information about the logged in devices under the specified account.
*
* @param username The user ID you want to get the device information.
* @param password The password.
* @returns The list of the online devices.
*
* @throws Error, see {@link ChatError}
*/
getLoggedInDevicesFromServer(username: string, password: string): Promise<Array<ChatDeviceInfo>>;
/**
* Force the specified account to logout from the specified device, to fetch the device ID: {@link ChatDeviceInfo#resource}.
*
* @param username The account you want to force logout.
* @param password The account's password.
* @param resource The device ID, see {@link ChatDeviceInfo#resource}.
*
* @throws Error, see {@link ChatError}
*/
kickDevice(username: string, password: string, resource: string): Promise<void>;
/**
* Kicks out all the devices logged in under the specified account.
*
* @param username The account you want to log out from all the devices.
* @param password The account's password.
*
* @throws Error, see {@link ChatError}
*/
kickAllDevices(username: string, password: string): Promise<void>;
addConnectionListener(listener: ChatConnectionListener): void;
removeConnectionListener(listener: ChatConnectionListener): void;
removeAllConnectionListener(): void;
addMultiDeviceListener(listener: ChatMultiDeviceListener): void;
removeMultiDeviceListener(listener: ChatMultiDeviceListener): void;
removeAllMultiDeviceListener(): void;
addCustomListener(listener: ChatCustomListener): void;
removeCustomListener(listener: ChatCustomListener): void;
removeAllCustomListener(): void;
get chatManager(): ChatManager;
}