UNPKG

@cf-platform/cim

Version:

消息队列库

141 lines (134 loc) 3.24 kB
export declare class CIM { /** WebSocket 实例 */ private _socket; /** 链接地址 */ private _url; /** 重启间隔 */ private _restartInterval; /** 手动关闭状态 */ private _manualClose; /** 强制下线常量 */ private readonly _ForceOfflineEnum; /** 鉴权常量 */ private readonly _AuthenticationEnum; /** 登录配置 */ loginConfiguration: LoginConfiguration; /** 消息常量 */ private readonly _MessageEnum; /** 自定义事件 */ customEvents?: CustomEvents; /** * @param options CIM参数 */ constructor(options: CIMOptions); /** * 初始化 * @param options CIM初始化参数 */ initialize(options: CIMOptions): void; /** 连接 */ connect(): void; /** 重新连接 */ reconnect(): void; /** 关闭 */ close(): void; /** * 发送心跳 */ sendPong(): void; /** * 接收消息 * @param message 收到的消息 */ receiveMessage(message: any): void; /** * 接收回复 * @param reply */ receiveReply(reply: any): void; /** * 发送消息 * @param data.key 消息Key */ sendMessage(data: CIMMessage): void; } /** * CIM消息参数 */ export declare interface CIMMessage { key: string; [key: string]: any; } /** * CIM传入参数 */ export declare interface CIMOptions { /** * 地址 */ url: string; /** * 重启间隔 */ restartInterval?: number; /** * 登录参数 */ loginParams: LoginParams; /** * 自定义事件 */ customEvents?: CustomEvents; } /** * 自定义事件 */ export declare interface CustomEvents { /** socket连接成功时触发方法 */ onSocketOpen?: Function; /** socket连接时触发方法 */ onSocketConnect?: Function; /** socket连接关闭时触发方法 */ onSocketClose?: Function; /** socket连接错误时触发方法 */ onSocketError?: Function; /** 发送心跳时触发方法 */ onSendPong?: Function; /** 收到消息时触发方法 */ onMessage?: Function; /** 收到回复时触发方法 */ onReply?: Function; /** 回复登录成功时触发方法 */ onLoginSuccess?: Function; /** 回复登录断开时触发方法 */ onLoginDisconnected?: Function; /** 回复鉴权失败时触发方法 */ onAuthenticationFailed?: Function; } /** * 登录配置 */ export declare interface LoginConfiguration { /** 用户ID */ uid: string; /** 通道 */ channel: string; /** 系统ID */ appVersion: string; /** 设备版本号 */ osVersion: string; /** 包名 */ packageName: string; /** 语言 */ language: string; /** 设备唯一ID */ deviceId: string; /** 设备名称 */ deviceName: string; [key: string]: string; } /** * 登录传入参数 */ export declare type LoginParams = Partial<LoginConfiguration> & Pick<LoginConfiguration, 'uid' | 'appVersion' | 'deviceId'>; export { }