UNPKG

@asteriskzuo/react-native-easemob

Version:
624 lines (623 loc) 16.7 kB
import type { ChatError } from './ChatError'; /** * The conversation types. */ export declare enum ChatMessageChatType { /** * One-to-one chat. */ PeerChat = 0, /** * Group chat. */ GroupChat = 1, /** * Chat room. */ ChatRoom = 2 } /** * The enumeration of the message MessageDirection. */ export declare enum ChatMessageDirection { /** * This message is sent from the local client. */ SEND = "send", /** * The message is received by the local client. */ RECEIVE = "rec" } /** * The enumeration of the message sending/reception status. * * The states include success, failure, being sent/being received, and created to be sent. */ export declare enum ChatMessageStatus { /** * The message is created to be sent. */ CREATE = 0, /** * The message is being delivered/receiving. */ PROGRESS = 1, /** * The message is successfully delivered/received. */ SUCCESS = 2, /** * The message fails to be delivered/received. */ FAIL = 3 } /** * The download status of the attachment file . */ export declare enum ChatDownloadStatus { /** * File message download is pending. */ PENDING = -1, /** * The SDK is downloading the file message. */ DOWNLOADING = 0, /** * The SDK successfully downloads the file message. */ SUCCESS = 1, /** * The SDK fails to download the file message. */ FAILED = 2 } /** * The enumeration of the message type. */ export declare enum ChatMessageBodyType { /** * Text message. */ TXT = "txt", /** * Image message. */ IMAGE = "img", /** * Video message. */ VIDEO = "video", /** * Location message. */ LOCATION = "loc", /** * Voice message. */ VOICE = "voice", /** * File message. */ FILE = "file", /** * Command message. */ CMD = "cmd", /** * Customized message. */ CUSTOM = "custom" } export declare function ChatMessageChatTypeFromNumber(params: number): ChatMessageChatType; export declare function ChatGroupPermissionTypeToString(params: ChatMessageChatType): string; export declare function ChatMessageDirectionFromString(params: string): ChatMessageDirection; export declare function ChatMessageStatusFromNumber(params: number): ChatMessageStatus; export declare function ChatMessageStatusToString(params: ChatMessageStatus): string; export declare function ChatDownloadStatusFromNumber(params: number): ChatDownloadStatus; export declare function ChatDownloadStatusToString(params: ChatDownloadStatus): string; export declare function ChatMessageBodyTypeFromString(params: string): ChatMessageBodyType; /** * Message status listener. */ export interface ChatMessageStatusCallback { /** * The progress of sending or receiving messages. * * @param progress Progress of the value. */ onProgress(localMsgId: string, progress: number): void; /** * Error message sending or receiving. * * @param error Error, see {@link ChatError} */ onError(localMsgId: string, error: ChatError): void; /** * The message is sent or received. * @param message The message. */ onSuccess(message: ChatMessage): void; } /** * The message instance, which represents a sent/received message. * * For example: * * Constructs a text message to send: * * ```typescript * let msg = ChatMessage.createTextMessage( * 'asteriskhx2', * Date.now().toString(), * ChatMessageChatType.PeerChat * ); * ``` */ export declare class ChatMessage { static TAG: string; /** * Gets the message ID. */ msgId: string; /** * Gets the local message ID. */ localMsgId: string; /** * The conversation ID. */ conversationId: string; /** * The user ID of the message sender. */ from: string; /** * The user ID of the message recipient. */ to: string; /** * The local timestamp of the message. */ localTime: number; /** * The server timestamp of the message. */ serverTime: number; /** * The delivery receipt, which is to check whether the other party has received the message. * * Whether the other party has received the message. * `true`:the message has been delivered to the other party. */ hasDeliverAck: boolean; /** * Whether the message has been read. * * Whether the other party has read the message. * `true`: The message has been read by the other party. */ hasReadAck: boolean; /** * Sets whether read receipts are required for group messages. * * `true`: Read receipts are required; * `false`: Read receipts are NOT required. */ needGroupAck: boolean; /** * Gets the number of members that have read the group message. */ groupAckCount: number; /** * Checks whether the message is read. * * `true`: The message is read. * `false`: The message is unread. */ hasRead: boolean; /** * The enumeration of the chat type. * * There are three chat types: one-to-one chat, group chat, and chat room. */ chatType: ChatMessageChatType; /** * The message direction. see {@link ChatMessageDirection} */ direction: ChatMessageDirection; /** * Gets the message sending/reception status. see {@link ChatMessageStatus} */ status: ChatMessageStatus; /** * Message's extension attribute. */ attributes: Object; /** * Message body. We recommend you use {@link ChatMessageBody)}. */ body: ChatMessageBody; constructor(params: { msgId?: string; localMsgId?: string; conversationId?: string; from?: string; to?: string; localTime?: number; serverTime?: number; hasDeliverAck?: boolean; hasReadAck?: boolean; needGroupAck?: boolean; groupAckCount?: number; hasRead?: boolean; chatType?: number; direction?: string; status?: number; attributes?: Object; body: Object; }); private static getBody; private static createSendMessage; /** * Creates a text message for sending. * * @param targetId The ID of the message recipient(user or group). * @param content The text content. * @param chatType The Conversation type. * @returns The message instance. */ static createTextMessage(targetId: string, content: string, chatType?: ChatMessageChatType): ChatMessage; /** * Creates a file message for sending. * * @param targetId The ID of the message recipient(user or group). * @param filePath The file path. * @param chatType The Conversation type. * @param opt The file name. like 'readme.doc' * @returns The message instance. */ static createFileMessage(targetId: string, filePath: string, chatType?: ChatMessageChatType, opt?: { displayName: string; }): ChatMessage; /** * Creates a image message for sending. * * @param targetId The ID of the message recipient(user or group). * @param filePath The image path. * @param chatType The Conversation type. * @param opt * @{#displayName} The image name. like 'image.jpeg' * @{#thumbnailLocalPath} The image thumbnail path. * @{#sendOriginalImage} Whether to send the original image. * `true`: Send the original image. * `false`: (default) For an image greater than 100 KB, the SDK will compress it. * @{#width} The image width. * @{#height} The image height. * @returns The message instance. */ static createImageMessage(targetId: string, filePath: string, chatType?: ChatMessageChatType, opt?: { displayName: string; thumbnailLocalPath?: string; sendOriginalImage?: boolean; width: number; height: number; }): ChatMessage; /** * Creates a video message for sending. * * @param targetId The ID of the message recipient(user or group). * @param filePath The path of the video file. * @param chatType The Conversation type. * @param opt * @{#displayName} The video name. like 'video.mp4' * @{#thumbnailLocalPath} The path of the thumbnail of the first frame of video. * @{#duration} The video duration in seconds. * @{#width} The video thumbnail image width. * @{#height} The video thumbnail image height. * @returns The message instance. */ static createVideoMessage(targetId: string, filePath: string, chatType?: ChatMessageChatType, opt?: { displayName: string; thumbnailLocalPath: string; duration: number; width: number; height: number; }): ChatMessage; /** * Creates a video message for sending. * * @param targetId The ID of the message recipient(user or group). * @param filePath The path of the voice file. * @param chatType The Conversation type. * @param opt * @{#displayName} The voice name. like 'voice.mp3' * @{#duration} The voice duration in seconds. * @returns The message instance. */ static createVoiceMessage(targetId: string, filePath: string, chatType?: ChatMessageChatType, opt?: { displayName: string; duration: number; }): ChatMessage; /** * Creates a location message for sending. * * @param targetId The ID of the message recipient(user or group). * @param latitude The latitude. * @param longitude The longitude. * @param chatType The Conversation type. * @param opt * @{#address} Place names. like `beijing`. * @returns The message instance. */ static createLocationMessage(targetId: string, latitude: string, longitude: string, chatType?: ChatMessageChatType, opt?: { address: string; }): ChatMessage; /** * Creates a cmd message for sending. * * @param targetId The ID of the message recipient(user or group). * @param action Action behavior. * @param chatType The Conversation type. * @returns The message instance. */ static createCmdMessage(targetId: string, action: string, chatType?: ChatMessageChatType): ChatMessage; /** * Creates a custom message for sending. * * @param targetId The ID of the message recipient(user or group). * @param event * @param chatType The Conversation type. * @param opt * @{#params} Custom parameters. Key/value pair. It can be nested. * @returns The message instance. */ static createCustomMessage(targetId: string, event: string, chatType?: ChatMessageChatType, opt?: { params: Map<string, any>; }): ChatMessage; static createReceiveMessage(params: any): ChatMessage; } /** * The content part of the message. * * The base class for the concrete message type. */ export declare class ChatMessageBody { /** * Message type. see {@link ChatMessageBodyType} */ type: ChatMessageBodyType; constructor(type: string); } /** * Text message body. */ export declare class ChatTextMessageBody extends ChatMessageBody { /** * Text message content. */ content: string; constructor(params: { type: string; content: string; }); } /** * The location message body. */ export declare class ChatLocationMessageBody extends ChatMessageBody { /** * The address. */ address: string; /** * The latitude. */ latitude: string; /** * The longitude. */ longitude: string; constructor(params: { type: string; address: string; latitude: string; longitude: string; }); } /** * File message body. */ export declare class ChatFileMessageBody extends ChatMessageBody { /** * The path of the image file. */ localPath: string; /** * The file's token. */ secret: string; /** * The path of the attachment file in the server. */ remotePath: string; /** * The download status of the attachment file . see {@link ChatDownloadStatus} */ fileStatus: ChatDownloadStatus; /** * The size of the file in bytes. */ fileSize: number; /** * The file name. like "file.doc" */ displayName: string; constructor(params: { type: string; localPath: string; secret?: string; remotePath?: string; fileStatus?: number; fileSize?: number; displayName: string; }); } /** * The image message body class. */ export declare class ChatImageMessageBody extends ChatFileMessageBody { /** * Sets whether to send the original image when sending an image. * * false`: (default) Send the thumbnail(image with size larger than 100k will be compressed); * `true`: Send the original image. */ sendOriginalImage: boolean; /** * The local path or the URI of the thumbnail as a string. */ thumbnailLocalPath: string; /** * The URL of the thumbnail on the server. */ thumbnailRemotePath: string; /** * The secret to access the thumbnail. A secret is required for verification for thumbnail download. */ thumbnailSecret: string; /** * The download status of the thumbnail. see {@link ChatDownloadStatus} */ thumbnailStatus: ChatDownloadStatus; /** * The image width. */ width: number; /** * The image height. */ height: number; constructor(params: { type: string; localPath: string; secret?: string; remotePath?: string; fileStatus?: number; fileSize?: number; displayName: string; sendOriginalImage?: boolean; thumbnailLocalPath?: string; thumbnailRemotePath?: string; thumbnailSecret?: string; thumbnailStatus?: number; width?: number; height?: number; }); } /** * The video message body. */ export declare class ChatVideoMessageBody extends ChatFileMessageBody { /** * The video duration in seconds. */ duration: number; /** * The local path of the video thumbnail. */ thumbnailLocalPath: string; /** * The URL of the thumbnail on the server. */ thumbnailRemotePath: string; /** * The secret key of the video thumbnail. */ thumbnailSecret: string; /** * The download status of the video thumbnail. see {@link ChatDownloadStatus} */ thumbnailStatus: ChatDownloadStatus; /** * The video width. */ width: number; /** * The video height. */ height: number; constructor(params: { type: string; localPath: string; secret?: string; remotePath?: string; fileStatus?: number; fileSize?: number; displayName: string; duration?: number; thumbnailLocalPath?: string; thumbnailRemotePath?: string; thumbnailSecret?: string; thumbnailStatus?: ChatDownloadStatus; width?: number; height?: number; }); } /** * The voice message body. */ export declare class ChatVoiceMessageBody extends ChatFileMessageBody { /** * The voice duration in seconds. */ duration: number; constructor(params: { type: string; localPath: string; secret?: string; remotePath?: string; fileStatus?: number; fileSize?: number; displayName: string; duration?: number; }); } /** * The command message body. */ export declare class ChatCmdMessageBody extends ChatMessageBody { /** * The command action content. */ action: string; /** * Checks whether this cmd message is only delivered to online users. * * `true`: Only delivers to online users. * `false`: Delivers to all users. */ deliverOnlineOnly: boolean; constructor(params: { action: string; deliverOnlineOnly?: boolean; }); } /** * The custom message body. */ export declare class ChatCustomMessageBody extends ChatMessageBody { /** * The event. */ event: string; /** * The params map. */ params: any; constructor(params: { event: string; params?: any; }); }