@zjw-jszn/shared-imsdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,13 @@
1
+ export declare function loadUnreadCount(): Promise<void>;
2
+ export declare function incrementUnreadCount(): void;
3
+ export declare function setUnreadCount(count: number): void;
4
+ export declare function getUnreadCount(): number;
5
+ export declare function useUnreadStore(): {
6
+ unreadCount: import('vue').Ref<number, number>;
7
+ activeConversationId: import('vue').Ref<string | null, string | null>;
8
+ loadUnreadCount: typeof loadUnreadCount;
9
+ incrementUnreadCount: typeof incrementUnreadCount;
10
+ setUnreadCount: typeof setUnreadCount;
11
+ getUnreadCount: typeof getUnreadCount;
12
+ setActiveConversationId: (id: string | null) => void;
13
+ };
@@ -0,0 +1,132 @@
1
+ export interface IMSDKConfig {
2
+ appId?: string;
3
+ userId?: string;
4
+ phone?: string;
5
+ theme?: {
6
+ primaryColor?: string;
7
+ backgroundColor?: string;
8
+ };
9
+ api?: {
10
+ baseURL?: string;
11
+ prefix?: string;
12
+ uploadURL?: string;
13
+ signKey?: string;
14
+ suffix?: string;
15
+ groupId?: string;
16
+ siteId?: string;
17
+ defaultSignKey?: string;
18
+ userType?: number;
19
+ };
20
+ ws?: {
21
+ controller?: string;
22
+ platform?: string;
23
+ };
24
+ sound?: {
25
+ enabled: boolean;
26
+ url?: string;
27
+ };
28
+ auth?: {
29
+ authorizationPayload?: Record<string, unknown>;
30
+ };
31
+ runtimeApi?: {
32
+ getChatConfig?: () => Promise<{
33
+ quick_receive?: string[] | string;
34
+ default_voice?: string;
35
+ }>;
36
+ closeSession?: (data: {
37
+ uid?: number;
38
+ session_id?: string;
39
+ }) => Promise<boolean>;
40
+ getCustomerChatList?: (data: {
41
+ page: number;
42
+ limit: number;
43
+ phone?: string;
44
+ }) => Promise<{
45
+ list: unknown[];
46
+ count: number;
47
+ }>;
48
+ };
49
+ }
50
+ export interface UserInfo {
51
+ id: number;
52
+ site_id: number;
53
+ sid: number;
54
+ userid: string;
55
+ we_code: string;
56
+ phone: string;
57
+ username: string;
58
+ password: string;
59
+ avatar: string;
60
+ type: number;
61
+ performance_type: number;
62
+ performance: number;
63
+ login_time: number;
64
+ login_ip: string;
65
+ is_deleted: number;
66
+ create_time: number;
67
+ update_time: number;
68
+ token: string;
69
+ name?: string;
70
+ email?: string;
71
+ cover?: string;
72
+ referee?: number;
73
+ remark?: string;
74
+ }
75
+ export interface ConversationPeer {
76
+ id?: number | string;
77
+ userid?: string;
78
+ username?: string;
79
+ name?: string;
80
+ phone?: string;
81
+ avatar?: string;
82
+ level?: number;
83
+ [key: string]: unknown;
84
+ }
85
+ export interface ConversationData {
86
+ id: string;
87
+ name: string;
88
+ avatar: string;
89
+ avatarText: string;
90
+ lastMessage: string;
91
+ lastTime: string;
92
+ unreadCount: number;
93
+ sessionId: string;
94
+ fid?: number | string;
95
+ uid?: number | string;
96
+ msg_type?: number;
97
+ friend_type?: number;
98
+ friend?: ConversationPeer;
99
+ messageId?: number;
100
+ msgData?: unknown;
101
+ sessionData?: unknown;
102
+ }
103
+ export interface ChatMessageData {
104
+ id: number | string;
105
+ type: 'sent' | 'received';
106
+ content: string;
107
+ time: string;
108
+ sender: string;
109
+ avatar: string;
110
+ senderId?: number | string;
111
+ receiverId?: number | string | null;
112
+ msgType: number;
113
+ msgData: unknown;
114
+ isTemp?: boolean;
115
+ }
116
+ export interface Message {
117
+ id: string;
118
+ userId: string;
119
+ content: string;
120
+ timestamp: number;
121
+ type: 'text' | 'image' | 'file';
122
+ read?: boolean;
123
+ }
124
+ export interface Conversation {
125
+ id: string;
126
+ userId: string;
127
+ userName: string;
128
+ avatar?: string;
129
+ lastMessage?: string;
130
+ lastTime?: number;
131
+ unreadCount?: number;
132
+ }
@@ -0,0 +1,32 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ interface RequestConfig {
3
+ baseURL?: string;
4
+ timeout?: number;
5
+ headers?: Record<string, string>;
6
+ }
7
+ interface ResponseData<T = unknown> {
8
+ code: number;
9
+ msg?: string;
10
+ message?: string;
11
+ result?: T;
12
+ data?: T;
13
+ }
14
+ declare class HttpClient {
15
+ private instance;
16
+ private token;
17
+ private userSignKey;
18
+ constructor(config?: RequestConfig);
19
+ setAuth(token: string, signKey?: string): void;
20
+ setBaseURL(baseURL: string): void;
21
+ getAuth(): string;
22
+ setupInterceptors(): void;
23
+ get<T = unknown>(url: string, params?: unknown, config?: AxiosRequestConfig): Promise<ResponseData<T>>;
24
+ post<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<ResponseData<T>>;
25
+ put<T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig): Promise<ResponseData<T>>;
26
+ delete<T = unknown>(url: string, config?: AxiosRequestConfig): Promise<ResponseData<T>>;
27
+ upload<T = unknown>(url: string, formData: FormData, config?: AxiosRequestConfig): Promise<ResponseData<T>>;
28
+ }
29
+ declare const httpClient: HttpClient;
30
+ export default httpClient;
31
+ export { httpClient as http, HttpClient };
32
+ export type { RequestConfig, ResponseData };
@@ -0,0 +1,7 @@
1
+ export { default as http, HttpClient } from './http';
2
+ export type { RequestConfig, ResponseData } from './http';
3
+ export { WebSocketClient, default as wsClient } from './websocket';
4
+ export type { WebSocketMessage } from './websocket';
5
+ export { WS_STATUS } from './websocket';
6
+ export { normalizeComparableId, normalizeWSMessage } from './ws-message';
7
+ export type { NormalizedWSMessage } from './ws-message';
@@ -0,0 +1,4 @@
1
+ export interface StableMessageDedupe {
2
+ shouldProcess: (messageId: string, hasStableId: boolean) => boolean;
3
+ }
4
+ export declare function createStableMessageDedupe(maxSize?: number): StableMessageDedupe;
@@ -0,0 +1,116 @@
1
+ export declare const WS_STATUS: {
2
+ CONNECTING: number;
3
+ OPEN: number;
4
+ CLOSING: number;
5
+ CLOSED: number;
6
+ };
7
+ interface WebSocketConfig {
8
+ wsUrl?: string;
9
+ siteId?: string;
10
+ }
11
+ interface WebSocketMessage {
12
+ controller: string;
13
+ action: string;
14
+ param?: Record<string, unknown>;
15
+ }
16
+ declare class WebSocketClient {
17
+ private ws;
18
+ private status;
19
+ private heartbeatTimer;
20
+ private reconnectTimer;
21
+ private reconnectCount;
22
+ private messageQueue;
23
+ private listeners;
24
+ private userId;
25
+ private phone;
26
+ private siteId;
27
+ private presenceAction;
28
+ private isConnected;
29
+ private wsUrl;
30
+ private readonly logPrefix;
31
+ constructor(config?: WebSocketConfig);
32
+ /**
33
+ * 连接 WebSocket
34
+ * @param {string} token - 用户token
35
+ * @param {number} userId - 用户ID
36
+ * @param {string} phone - 用户手机号
37
+ * @param {string} siteId - 站点ID
38
+ */
39
+ connect(token: string, userId?: number | null, phone?: string | null, siteId?: string): Promise<WebSocket>;
40
+ /**
41
+ * 发送消息
42
+ * @param {object|string} data - 要发送的数据对象或字符串
43
+ */
44
+ send(data: WebSocketMessage | string): boolean;
45
+ /**
46
+ * 发送控制器动作消息(使用当前配置的 controller)
47
+ */
48
+ sendControllerMessage(action: string, param?: Record<string, unknown>): boolean;
49
+ /**
50
+ * 使用当前配置 controller 发送业务消息
51
+ */
52
+ sendBusinessMessage(action: string, param?: Record<string, unknown>): boolean;
53
+ /**
54
+ * 启动心跳
55
+ */
56
+ private startHeartbeat;
57
+ /**
58
+ * 发送连接/状态消息
59
+ */
60
+ private sendConnectMessage;
61
+ /**
62
+ * 停止心跳
63
+ */
64
+ private stopHeartbeat;
65
+ /**
66
+ * 计划重连
67
+ * @param {string} token - 用户token
68
+ * @param {number} userId - 用户ID
69
+ * @param {string} phone - 用户手机号
70
+ */
71
+ private scheduleReconnect;
72
+ /**
73
+ * 发送消息队列中的消息
74
+ */
75
+ private flushMessageQueue;
76
+ /**
77
+ * 销毁连接(用于重连前清理)
78
+ */
79
+ private destroyConnection;
80
+ /**
81
+ * 断开连接
82
+ */
83
+ disconnect(): void;
84
+ /**
85
+ * 添加事件监听器
86
+ * @param {string} event - 事件名称
87
+ * @param {function} callback - 回调函数
88
+ */
89
+ on(event: string, callback: (...args: unknown[]) => void): void;
90
+ /**
91
+ * 移除事件监听器
92
+ * @param {string} event - 事件名称
93
+ * @param {function} callback - 回调函数
94
+ */
95
+ off(event: string, callback: (...args: unknown[]) => void): void;
96
+ /**
97
+ * 触发事件
98
+ * @param {string} event - 事件名称
99
+ * @param {*} data - 事件数据
100
+ */
101
+ private emit;
102
+ /**
103
+ * 获取连接状态
104
+ * @returns {number} - 返回当前的连接状态枚举值
105
+ */
106
+ getStatus(): number;
107
+ /**
108
+ * 检查是否已连接
109
+ * @returns {boolean} - 返回是否处于已连接并可用的状态
110
+ */
111
+ checkConnected(): boolean;
112
+ }
113
+ declare const wsClient: WebSocketClient;
114
+ export default wsClient;
115
+ export { WebSocketClient };
116
+ export type { WebSocketConfig, WebSocketMessage };
@@ -0,0 +1,18 @@
1
+ export interface NormalizedWSMessage {
2
+ id: string;
3
+ hasStableId: boolean;
4
+ content: string;
5
+ sessionId: string;
6
+ senderId: string;
7
+ receiverId: string;
8
+ msgType: number;
9
+ raw: Record<string, unknown>;
10
+ }
11
+ /**
12
+ * 统一 ID 对比格式,避免 number/string 混用导致比较失败
13
+ */
14
+ export declare function normalizeComparableId(value: unknown): string;
15
+ /**
16
+ * 统一 WebSocket 消息结构(按当前接口实际字段)
17
+ */
18
+ export declare function normalizeWSMessage(data: unknown): NormalizedWSMessage | null;
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@zjw-jszn/shared-imsdk",
3
+ "type": "module",
4
+ "version": "1.0.0",
5
+ "exports": {
6
+ ".": {
7
+ "types": {
8
+ "development": "./src/index.ts",
9
+ "default": "./dist/index.d.ts"
10
+ },
11
+ "import": {
12
+ "development": "./src/index.ts",
13
+ "default": "./dist/shared-imsdk.es.js"
14
+ }
15
+ },
16
+ "./style.css": "./dist/shared-imsdk.css"
17
+ },
18
+ "types": "./dist/index.d.ts",
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "publishConfig": {
23
+ "access": "public",
24
+ "registry": "https://registry.npmjs.org/"
25
+ },
26
+ "dependencies": {
27
+ "axios": "^1.13.6",
28
+ "ts-md5": "^2.0.1",
29
+ "vue": "^3.5.30",
30
+ "vue3-emoji-picker": "^1.1.8"
31
+ },
32
+ "devDependencies": {
33
+ "@vitejs/plugin-vue": "^6.0.5",
34
+ "typescript": "~5.9.3",
35
+ "vite": "^8.0.0",
36
+ "vite-plugin-dts": "^4.5.4",
37
+ "vue-tsc": "^3.2.5"
38
+ },
39
+ "scripts": {
40
+ "typecheck": "vue-tsc --noEmit",
41
+ "build": "vue-tsc && vite build"
42
+ }
43
+ }