wildfire-im-sdk
Version:
野火IM SDK for Vue3 projects
143 lines (129 loc) • 3.39 kB
text/typescript
// 导出配置
import Config from './config';
// 导出客户端
import wfc from './wfc/client/wfc';
// 导出impl
import impl from './wfc/proto/proto.min.js';
// 导出模型类
import Conversation from './wfc/model/conversation';
import ConversationType from './wfc/model/conversationType';
import GroupInfo from './wfc/model/groupInfo';
import GroupMember from './wfc/model/groupMember';
import MessageContent from './wfc/messages/messageContent';
import MessageContentType from './wfc/messages/messageContentType';
import UserInfo from './wfc/model/userInfo';
// 导出工具类
import EventType from './wfc/client/wfcEvent';
import ConnectionStatus from './wfc/client/connectionStatus';
// 导出常用消息类型
import TextMessageContent from './wfc/messages/textMessageContent';
import ImageMessageContent from './wfc/messages/imageMessageContent';
import VideoMessageContent from './wfc/messages/videoMessageContent';
import FileMessageContent from './wfc/messages/fileMessageContent';
import StickerMessageContent from './wfc/messages/stickerMessageContent';
/**
* SDK配置类型定义
*/
export interface SDKConfig {
// IM服务器地址
APP_SERVER?: string;
// 默认端口
ROUTE_PORT?: number;
// 默认用户ID和token
DEFAULT_USER_ID?: string;
DEFAULT_TOKEN?: string;
// 是否自动连接
AUTO_CONNECT?: boolean;
// 客户端ID存储策略
CLIENT_ID_STRATEGY?: number;
// IM服务平台类型
PLATFORM?: number;
// 心跳间隔(毫秒)
KEEP_ALIVE_INTERVAL?: number;
// 多久没收到消息重连(毫秒)
KEEP_ALIVE_TIMEOUT?: number;
// 请求超时时间(毫秒)
REQUEST_TIMEOUT?: number;
// 最大重试次数
MAX_RETRY_COUNT?: number;
// 功能开关
ENABLE_LOG?: boolean;
ENABLE_SYNC_DRAFT?: boolean;
ENABLE_OFFLINE_MESSAGE?: boolean;
ENABLE_MESSAGE_RECEIPT?: boolean;
ENABLE_NOTIFICATION?: boolean;
// UI相关配置
UI?: {
DEFAULT_AVATAR_URL?: string;
DEFAULT_GROUP_AVATAR_URL?: string;
MESSAGE_RECALL_TIME_LIMIT?: number;
};
// 其他自定义配置可扩展
[key: string]: any;
}
/**
* 初始化SDK
* @param config 可选的配置参数,覆盖默认配置
*/
export function init(config?: SDKConfig) {
if (config) {
// 合并其他顶层配置
Object.assign(Config, config)
}
// 初始化客户端
wfc.init()
// 返回配置结果,方便调试
return {
config: { ...Config },
initialized: true
}
}
/**
* 连接到服务器
* @param userId 用户ID
* @param token 用户token
* @returns 是否成功连接
*/
export function connect(userId: string, token: string): any {
return wfc.connect(userId, token);
}
/**
* 断开连接
*/
export function disconnect(): void {
wfc.disconnect();
}
/**
* 获取连接状态
* @returns 当前连接状态
*/
export function getConnectionStatus(): number {
return wfc.getConnectionStatus();
}
/**
* 获取当前SDK配置
* @returns 当前配置对象的副本
*/
export function getConfig(): any {
return { ...Config };
}
// 导出所有内容
export {
Config,
wfc,
impl, // 导出impl对象
Conversation,
ConversationType,
GroupInfo,
GroupMember,
MessageContent,
MessageContentType,
UserInfo,
EventType,
ConnectionStatus,
TextMessageContent,
ImageMessageContent,
VideoMessageContent,
FileMessageContent,
StickerMessageContent
};