123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- import { ImEventType } from "./im/events";
- import { ConversationType } from "./im/conversations";
- export interface GoEasyOptions {
- host: string;
- appkey: string;
- modules: Array<string>;
- forceTLS?: boolean;
- supportOldBrowser?: boolean;
- allowNotification?: boolean;
- }
- export interface CallBackOptions {
- onSuccess?(result?: any): void;
- onFailed?(errInfo?: any): void;
- }
- export interface ConnectOptions extends CallBackOptions {
- id?: string | number;
- data: string | any;
- otp?: string;
- onProgress?(progress: number): void;
- }
- export interface PresenceEvent<T> {
- action: string;
- time: number;
- data: T;
- id: string;
- }
- export interface PresenceEvents<T> {
- channel: string;
- clientAmount: number;
- events: PresenceEvent<T>[];
- userAmount: number;
- }
- export declare type IMEvent = keyof typeof ImEventType;
- export declare type MessageCallback = (message: any) => void;
- export interface PublishOptions extends CallBackOptions {
- channel: string;
- message: string;
- notification?: {
- title: string;
- body: string;
- };
- }
- export interface SubscribeOptions extends CallBackOptions {
- channel: string;
- onMessage(message: {
- channel: string;
- content: string;
- }): void;
- }
- export interface UnsubscribeOptions extends CallBackOptions {
- channel: string;
- }
- export interface SubscribePresenceOptions extends CallBackOptions {
- channel: string;
- onPresence<T = any>(presenceEvents: PresenceEvents<T>): void;
- }
- export interface UnsubscribePresenceOptions extends CallBackOptions {
- channel: string;
- }
- export interface HistoryOptions extends CallBackOptions {
- channel: string;
- limit: number;
- onSuccess(results: {
- code: number;
- content: {
- messages: Array<{
- time: number;
- content: string;
- }>;
- };
- }): void;
- }
- export interface HereNowOptions extends CallBackOptions {
- channels: string[];
- includeUsers?: boolean;
- distinct?: boolean;
- onSuccess(results: {
- code: number;
- content: {
- channels: {
- [key: string]: {
- channel: string;
- clientAmount: number;
- userAmount: number;
- users: any[];
- };
- };
- };
- }): void;
- }
- export interface HereNowByUserIdsOptions extends CallBackOptions {
- userIds: string[];
- distinct?: boolean;
- onSuccess(results: {
- code: number;
- content: Array<{
- id: string;
- data: any;
- }>;
- }): void;
- }
- export interface MessageTo {
- type: string;
- id: string;
- data: any;
- }
- export interface MessageOptions {
- to: MessageTo;
- notification?: {
- title: string;
- body: string;
- };
- onProgress?(progress: ProgressEvent<EventTarget>): void;
- }
- export interface TextMessageOptions extends MessageOptions {
- text: string;
- }
- export interface FileMessageOptions extends MessageOptions {
- file: File;
- }
- export interface CustomMessageOptions<T> extends MessageOptions {
- type: string;
- payload: T;
- }
- export interface LatestConversationsOptions extends CallBackOptions {
- onSuccess(result: {
- code: number;
- content: {
- unreadTotal: number;
- conversations: Conversation[];
- };
- }): void;
- }
- export interface RemovePrivateConversationOptions extends CallBackOptions {
- userId: string;
- }
- export interface RemoveGroupConversationOptions extends CallBackOptions {
- groupId: string;
- }
- export interface IMHistoryOptions extends CallBackOptions {
- userId?: string;
- groupId?: string;
- lastTimestamp?: number;
- limit?: number;
- }
- export interface UploadOptions extends CallBackOptions {
- file: File;
- name: string;
- onProgress(progress: ProgressEvent<EventTarget>): void;
- }
- export interface SendMessageOptions extends CallBackOptions {
- message: IMMessage;
- }
- export interface MarkGroupMessageAsReadOptions extends CallBackOptions {
- groupId: string;
- timestamp: number;
- }
- export interface MarkPrivateMessageAsReadOptions extends CallBackOptions {
- userId: string;
- timestamp: number;
- }
- export interface TopPrivateConversationOptions extends CallBackOptions {
- userId: string;
- top: boolean;
- }
- export interface TopGroupConversationOptions extends CallBackOptions {
- groupId: string;
- top: boolean;
- }
- export interface SubscribeUserPresenceOptions extends CallBackOptions {
- userIds: string[];
- }
- export interface UnsubscribeUserPresenceOptions extends CallBackOptions {
- userId: string;
- }
- export interface IMHereNowOptions extends CallBackOptions {
- userIds: string[];
- onSuccess(result: {
- code: number;
- content: Array<{
- userId: string;
- userData: string;
- }>;
- }): void;
- }
- export interface SubscribeGroupOptions extends CallBackOptions {
- groupIds: string;
- }
- export interface UnsubscribeGroupOptions extends CallBackOptions {
- groupId: string;
- }
- export interface SubscribeGroupPresenceOptions extends CallBackOptions {
- groupIds: string[];
- }
- export interface UnsubscribeGroupPresenceOptions extends CallBackOptions {
- groupId: string;
- }
- export interface GroupHereNowOptions extends CallBackOptions {
- groupId: string;
- onSuccess(result: {
- code: number;
- content: Array<{
- groupId: string;
- userData: string;
- }>;
- }): void;
- }
- export interface GroupOnlineCountOptions extends CallBackOptions {
- groupId: string;
- onSuccess(result: {
- code: number;
- content: {
- onlineCount: number;
- };
- }): void;
- }
- export declare enum MessageStatus {
- new = "new",
- sending = "sending",
- success = "success",
- fail = "fail"
- }
- export interface IMMessage<T = any> {
- type: string;
- senderData?: string;
- to?: MessageTo;
- timestamp?: number;
- senderId: string;
- payload: T;
- messageId: string;
- status: MessageStatus;
- }
- export interface Conversation {
- type: string;
- groupId: string;
- userId: string;
- data: string;
- unread: number;
- lastMessage: IMMessage<any>;
- }
- /**
- * @description PubSub 类
- */
- export declare class PubSub {
- static instance: any;
- private options;
- private goEasySocket;
- private publisher;
- private subscriber;
- private presence;
- private histories;
- private hereNows;
- private neverConnect;
- constructor(options: GoEasyOptions);
- initialGoEasySocket(goEasySocket: any): void;
- initialBeforeConnect(): void;
- private validateOptions;
- publish(options: PublishOptions): void;
- subscribe(options: SubscribeOptions): void;
- unsubscribe(options: UnsubscribeOptions): void;
- subscribePresence(options: SubscribePresenceOptions): void;
- unsubscribePresence(options: UnsubscribePresenceOptions): void;
- history(options: HistoryOptions): void;
- hereNow(options: HereNowOptions): void;
- hereNowByUserIds(options: HereNowByUserIdsOptions): void;
- }
- /**
- * @description IM 聊天类
- *
- * todo:要和IM。js合并,这边应该保持简单,复杂的应该在那边。
- */
- export declare class GoEasyIM {
- options: GoEasyOptions;
- constructor(options: GoEasyOptions);
- initialBeforeConnect(user: any): void;
- initialAfterConnect(): void;
- initialGoEasySocket(goEasySocket: any): void;
- private validateOptions;
- private validateMessageToData;
- on(event: IMEvent, fn: MessageCallback): void;
- createTextMessage(options: TextMessageOptions): IMMessage<string>;
- createImageMessage(options: FileMessageOptions): IMMessage<File>;
- createFileMessage(options: FileMessageOptions): IMMessage<File>;
- createAudioMessage(options: FileMessageOptions): IMMessage<File>;
- createVideoMessage(options: FileMessageOptions): IMMessage<File>;
- createCustomMessage<T = any>(options: CustomMessageOptions<T>): IMMessage<T>;
- latestConversations(options: LatestConversationsOptions): void;
- removePrivateConversation(options: RemovePrivateConversationOptions): void;
- removeGroupConversation(options: RemoveGroupConversationOptions): void;
- history(options: IMHistoryOptions): void;
- upload(options: UploadOptions): void;
- sendMessage(message: SendMessageOptions): void;
- markGroupMessageAsRead(options: MarkGroupMessageAsReadOptions): void;
- markPrivateMessageAsRead(options: MarkPrivateMessageAsReadOptions): void;
- topPrivateConversation(options: TopPrivateConversationOptions): void;
- topGroupConversation(options: TopGroupConversationOptions): void;
- subscribeUserPresence(options: SubscribeUserPresenceOptions): void;
- unsubscribeUserPresence(options: UnsubscribeUserPresenceOptions): void;
- hereNow(options: IMHereNowOptions): void;
- subscribeGroup(options: SubscribeGroupOptions): void;
- unsubscribeGroup(options: UnsubscribeGroupOptions): void;
- subscribeGroupPresence(options: SubscribeGroupPresenceOptions): void;
- unsubscribeGroupPresence(options: UnsubscribeGroupPresenceOptions): void;
- groupHereNow(options: GroupHereNowOptions): void;
- groupOnlineCount(options: GroupOnlineCountOptions): void;
- }
- /**
- * @description GoEasy 对外接口核心类
- */
- export default class GoEasy {
- static instance: GoEasy;
- static readonly version: string;
- static readonly IM_EVENT: typeof ImEventType;
- static readonly IM_SCENE: typeof ConversationType;
- readonly im: GoEasyIM;
- readonly pubsub: PubSub;
- private goEasySocket;
- private options;
- private notification;
- private constructor();
- static getInstance(options: GoEasyOptions): GoEasy;
- connect(options: ConnectOptions): void;
- disconnect(options: CallBackOptions): void;
- getConnectionStatus(): string;
- private validateOptions;
- onClickNotification(clickHandler: MessageCallback): void;
- private confirmUserId;
- }
|