zsl-im-sdk 1.0.0 → 1.0.1
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.
- package/dist/api/common/common.api.d.ts +1 -0
- package/dist/api/common/common.api.js +13 -0
- package/dist/api/conversation/conversation.api.d.ts +54 -0
- package/dist/api/conversation/conversation.api.js +88 -0
- package/dist/api/im-login.d.ts +11 -0
- package/dist/api/im-login.js +16 -0
- package/dist/api/message/message.api.d.ts +23 -0
- package/dist/api/message/message.api.js +36 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +76 -0
- package/dist/store.d.ts +61 -0
- package/dist/store.js +493 -0
- package/dist/types/conversation.type.d.ts +42 -0
- package/dist/types/conversation.type.js +8 -0
- package/dist/types/im-user.type.d.ts +22 -0
- package/dist/types/im-user.type.js +2 -0
- package/{types/index.ts → dist/types/index.d.ts} +4 -5
- package/dist/types/index.js +21 -0
- package/dist/types/message-type.type.d.ts +76 -0
- package/dist/types/message-type.type.js +48 -0
- package/dist/types/socket-data.type.d.ts +38 -0
- package/dist/types/socket-data.type.js +19 -0
- package/dist/types.d.ts +62 -0
- package/dist/types.js +5 -0
- package/dist/utils/http.d.ts +41 -0
- package/dist/utils/http.js +159 -0
- package/dist/websocket.d.ts +46 -0
- package/dist/websocket.js +302 -0
- package/package.json +16 -5
- package/api/common/common.api.ts +0 -7
- package/api/conversation/conversation.api.ts +0 -93
- package/api/im-login.ts +0 -18
- package/api/message/message.api.ts +0 -51
- package/index.ts +0 -36
- package/jsconfig.json +0 -14
- package/store.ts +0 -692
- package/types/conversation.type.ts +0 -60
- package/types/im-user.type.ts +0 -31
- package/types/message-type.type.ts +0 -94
- package/types/socket-data.type.ts +0 -55
- package/types.ts +0 -66
- package/utils/http.ts +0 -195
- package/websocket.ts +0 -367
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
// 从types目录导入所有类型定义
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
const index_1 = require("./types/index");
|
|
20
|
+
// WebSocket实例类型,使用any类型兼容uni-app的SocketTask
|
|
21
|
+
class IM {
|
|
22
|
+
constructor(options) {
|
|
23
|
+
this.ws = null;
|
|
24
|
+
this.isConnected = false;
|
|
25
|
+
this.reconnectTimer = null;
|
|
26
|
+
this.reconnectCount = 0;
|
|
27
|
+
this.messageQueue = [];
|
|
28
|
+
this.listeners = {
|
|
29
|
+
message: [],
|
|
30
|
+
connect: [],
|
|
31
|
+
disconnect: [],
|
|
32
|
+
error: [],
|
|
33
|
+
reconnect: [],
|
|
34
|
+
recalled: [],
|
|
35
|
+
};
|
|
36
|
+
// 心跳相关
|
|
37
|
+
this.heartbeatTimer = null;
|
|
38
|
+
this.url = options.url;
|
|
39
|
+
this.token = options.token;
|
|
40
|
+
this.userId = options.userId;
|
|
41
|
+
this.maxReconnectCount = options.maxReconnectCount || 5;
|
|
42
|
+
this.reconnectInterval = options.reconnectInterval || 3000;
|
|
43
|
+
this.heartbeatInterval = options.heartbeatInterval || 30000;
|
|
44
|
+
}
|
|
45
|
+
// 获取完整的WebSocket连接URL
|
|
46
|
+
getWsUrl() {
|
|
47
|
+
return `${this.url}?userId=${this.userId}`;
|
|
48
|
+
}
|
|
49
|
+
// 连接websocket
|
|
50
|
+
connect() {
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
try {
|
|
53
|
+
this.ws = uni.connectSocket({
|
|
54
|
+
url: this.getWsUrl(),
|
|
55
|
+
header: {
|
|
56
|
+
token: this.token,
|
|
57
|
+
},
|
|
58
|
+
success: () => {
|
|
59
|
+
console.log("WebSocket连接请求已发送");
|
|
60
|
+
},
|
|
61
|
+
fail: (err) => {
|
|
62
|
+
console.error("WebSocket连接失败", err);
|
|
63
|
+
reject(err);
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
this.ws.onOpen(() => {
|
|
67
|
+
console.log("WebSocket连接已打开");
|
|
68
|
+
this.isConnected = true;
|
|
69
|
+
this.reconnectCount = 0;
|
|
70
|
+
this.flushMessageQueue();
|
|
71
|
+
this.startHeartbeat();
|
|
72
|
+
this.emit("connect");
|
|
73
|
+
resolve();
|
|
74
|
+
});
|
|
75
|
+
this.ws.onMessage((res) => {
|
|
76
|
+
try {
|
|
77
|
+
const data = JSON.parse(res.data);
|
|
78
|
+
this.handleMessage(data);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
console.error("解析WebSocket消息失败", err);
|
|
82
|
+
this.emit("error", err);
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
this.ws.onClose(() => {
|
|
86
|
+
console.log("WebSocket连接已关闭");
|
|
87
|
+
this.isConnected = false;
|
|
88
|
+
this.stopHeartbeat();
|
|
89
|
+
this.emit("disconnect");
|
|
90
|
+
this.handleReconnect();
|
|
91
|
+
});
|
|
92
|
+
this.ws.onError((err) => {
|
|
93
|
+
console.error("WebSocket错误", err);
|
|
94
|
+
this.isConnected = false;
|
|
95
|
+
this.stopHeartbeat();
|
|
96
|
+
this.emit("error", err);
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
catch (err) {
|
|
100
|
+
console.error("WebSocket连接异常", err);
|
|
101
|
+
reject(err);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
// 断开连接
|
|
106
|
+
disconnect() {
|
|
107
|
+
if (this.ws) {
|
|
108
|
+
this.ws.close();
|
|
109
|
+
this.ws = null;
|
|
110
|
+
}
|
|
111
|
+
this.isConnected = false;
|
|
112
|
+
this.stopHeartbeat();
|
|
113
|
+
if (this.reconnectTimer) {
|
|
114
|
+
clearTimeout(this.reconnectTimer);
|
|
115
|
+
this.reconnectTimer = null;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
// 重连机制
|
|
119
|
+
handleReconnect() {
|
|
120
|
+
if (this.reconnectCount < this.maxReconnectCount) {
|
|
121
|
+
this.reconnectCount++;
|
|
122
|
+
console.log(`正在尝试第${this.reconnectCount}次重连...`);
|
|
123
|
+
this.reconnectTimer = setTimeout(() => {
|
|
124
|
+
this.emit("reconnect", this.reconnectCount);
|
|
125
|
+
this.connect();
|
|
126
|
+
}, this.reconnectInterval);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
console.error("重连次数已达上限,停止重连");
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
// 处理收到的消息
|
|
133
|
+
handleMessage(data) {
|
|
134
|
+
const { action, payload } = data;
|
|
135
|
+
// 处理心跳消息
|
|
136
|
+
if (action === index_1.SocketAction.PING) {
|
|
137
|
+
this.sendPingPong(index_1.SocketAction.PONG);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// 处理新消息
|
|
141
|
+
// DELIVERED - 已送达
|
|
142
|
+
// MESSAGE - 收到其他人的消息
|
|
143
|
+
if (action === index_1.SocketAction.MESSAGE || action === index_1.SocketAction.DELIVERED) {
|
|
144
|
+
const payloadData = payload;
|
|
145
|
+
const message = {
|
|
146
|
+
id: payloadData.id || Date.now(),
|
|
147
|
+
conversationId: payloadData.conversationId || "",
|
|
148
|
+
senderId: payloadData.senderId || "",
|
|
149
|
+
recipientId: payloadData.recipientId,
|
|
150
|
+
messageType: payloadData.messageType,
|
|
151
|
+
content: payloadData.content || "",
|
|
152
|
+
mediaUrl: payloadData.mediaUrl || "",
|
|
153
|
+
metadata: payloadData.metadata || "",
|
|
154
|
+
createdAt: payloadData.time || this.getCurrentTime(),
|
|
155
|
+
status: index_1.MessageStatus.SENT,
|
|
156
|
+
};
|
|
157
|
+
this.emit("message", message);
|
|
158
|
+
}
|
|
159
|
+
// 处理消息撤回
|
|
160
|
+
if (action === index_1.SocketAction.RECALLED) {
|
|
161
|
+
console.log("========SocketAction.RECALLED==", payload);
|
|
162
|
+
this.emit("recalled", payload);
|
|
163
|
+
}
|
|
164
|
+
// 处理错误消息
|
|
165
|
+
if (action === index_1.SocketAction.ERROR) {
|
|
166
|
+
this.emit("error", payload);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
// 发送消息
|
|
170
|
+
send(data) {
|
|
171
|
+
return new Promise((resolve, reject) => {
|
|
172
|
+
if (this.isConnected && this.ws) {
|
|
173
|
+
try {
|
|
174
|
+
const message = JSON.stringify(data);
|
|
175
|
+
this.ws.send({
|
|
176
|
+
data: message,
|
|
177
|
+
success: () => {
|
|
178
|
+
console.log("消息发送成功", data);
|
|
179
|
+
resolve();
|
|
180
|
+
},
|
|
181
|
+
fail: (err) => {
|
|
182
|
+
console.error("消息发送失败", err);
|
|
183
|
+
reject(err);
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
catch (err) {
|
|
188
|
+
console.error("消息发送异常", err);
|
|
189
|
+
reject(err);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
console.log("WebSocket未连接,将消息加入队列");
|
|
194
|
+
this.messageQueue.push({ data, resolve, reject });
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
// 发送文本消息
|
|
199
|
+
sendText(conversationId, recipientId, content, messageType = index_1.MessageType.TEXT, mediaUrl) {
|
|
200
|
+
const payload = {
|
|
201
|
+
conversationId: conversationId,
|
|
202
|
+
senderId: this.userId,
|
|
203
|
+
recipientId: recipientId,
|
|
204
|
+
messageType: messageType,
|
|
205
|
+
content: content,
|
|
206
|
+
mediaUrl,
|
|
207
|
+
time: this.getCurrentTime(),
|
|
208
|
+
};
|
|
209
|
+
return this.send({
|
|
210
|
+
action: index_1.SocketAction.SEND_MESSAGE,
|
|
211
|
+
payload: payload,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
// 发送已读回执
|
|
215
|
+
sendReadReceipt(conversationId, lastReadMessageId) {
|
|
216
|
+
const payload = {
|
|
217
|
+
conversationId: conversationId,
|
|
218
|
+
lastReadMessageId: lastReadMessageId,
|
|
219
|
+
};
|
|
220
|
+
return this.send({
|
|
221
|
+
action: index_1.SocketAction.READ_RECEIPT,
|
|
222
|
+
payload: payload,
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
// 发送消息撤回
|
|
226
|
+
sendRecallMessage(messageId) {
|
|
227
|
+
const payload = {
|
|
228
|
+
messageId,
|
|
229
|
+
};
|
|
230
|
+
return this.send({
|
|
231
|
+
action: index_1.SocketAction.RECALL_MESSAGE,
|
|
232
|
+
payload: payload,
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
// 发送心跳消息
|
|
236
|
+
sendPingPong(action) {
|
|
237
|
+
return this.send({
|
|
238
|
+
action: action,
|
|
239
|
+
payload: {},
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
// 开始心跳
|
|
243
|
+
startHeartbeat() {
|
|
244
|
+
this.stopHeartbeat();
|
|
245
|
+
this.heartbeatTimer = setInterval(() => {
|
|
246
|
+
if (this.isConnected) {
|
|
247
|
+
this.sendPingPong(index_1.SocketAction.PING);
|
|
248
|
+
}
|
|
249
|
+
}, this.heartbeatInterval);
|
|
250
|
+
}
|
|
251
|
+
// 停止心跳
|
|
252
|
+
stopHeartbeat() {
|
|
253
|
+
if (this.heartbeatTimer) {
|
|
254
|
+
clearInterval(this.heartbeatTimer);
|
|
255
|
+
this.heartbeatTimer = null;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
// 刷新消息队列
|
|
259
|
+
flushMessageQueue() {
|
|
260
|
+
if (this.isConnected && this.ws && this.messageQueue.length > 0) {
|
|
261
|
+
const queue = [...this.messageQueue];
|
|
262
|
+
this.messageQueue = [];
|
|
263
|
+
queue.forEach((item) => {
|
|
264
|
+
this.send(item.data).then(item.resolve).catch(item.reject);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
// 获取当前时间 (ISO格式)
|
|
269
|
+
getCurrentTime() {
|
|
270
|
+
return new Date().toISOString();
|
|
271
|
+
}
|
|
272
|
+
// 事件监听
|
|
273
|
+
on(event, callback) {
|
|
274
|
+
if (this.listeners[event]) {
|
|
275
|
+
this.listeners[event].push(callback);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
// 移除事件监听
|
|
279
|
+
off(event, callback) {
|
|
280
|
+
if (this.listeners[event]) {
|
|
281
|
+
this.listeners[event] = this.listeners[event].filter((cb) => cb !== callback);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
// 触发事件
|
|
285
|
+
emit(event, data) {
|
|
286
|
+
if (this.listeners[event]) {
|
|
287
|
+
this.listeners[event].forEach((callback) => {
|
|
288
|
+
try {
|
|
289
|
+
callback(data);
|
|
290
|
+
}
|
|
291
|
+
catch (err) {
|
|
292
|
+
console.error(`事件${event}回调执行失败`, err);
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
// 获取连接状态
|
|
298
|
+
getConnectionStatus() {
|
|
299
|
+
return this.isConnected;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
exports.default = IM;
|
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zsl-im-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "IM 即时通讯 SDK 核心包",
|
|
5
|
-
"main": "index.
|
|
6
|
-
"types": "
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "npm run build"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
7
14
|
"keywords": [
|
|
8
15
|
"im",
|
|
9
16
|
"websocket",
|
|
@@ -14,8 +21,12 @@
|
|
|
14
21
|
"author": "ZSL",
|
|
15
22
|
"license": "MIT",
|
|
16
23
|
"peerDependencies": {
|
|
24
|
+
"ali-oss": "^6.23.0",
|
|
17
25
|
"vue": "^2.6.0",
|
|
18
|
-
"vuex": "^3.0.0"
|
|
19
|
-
|
|
26
|
+
"vuex": "^3.0.0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@dcloudio/types": "^3.4.29",
|
|
30
|
+
"typescript": "^5.9.3"
|
|
20
31
|
}
|
|
21
32
|
}
|
package/api/common/common.api.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import http from '../../utils/http';
|
|
2
|
-
import { IConversation } from '../../types/conversation.type';
|
|
3
|
-
|
|
4
|
-
// *
|
|
5
|
-
// * 获取会话列表
|
|
6
|
-
// * @param userId 查询参数
|
|
7
|
-
// * @returns 会话列表
|
|
8
|
-
//
|
|
9
|
-
export function getConversationsBuUserId(userId: string): Promise<Array<IConversation>> {
|
|
10
|
-
return http.request<Array<IConversation>>('POST','/conversations/byUserId', {
|
|
11
|
-
userId
|
|
12
|
-
})
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 获取会话详情
|
|
18
|
-
* @param conversationId 会话ID
|
|
19
|
-
* @returns 会话详情
|
|
20
|
-
*/
|
|
21
|
-
export const getConversationDetail = (conversationId: string) => {
|
|
22
|
-
return http.request<IConversation>('GET', `/conversation/${conversationId}`);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 删除会话
|
|
27
|
-
* @param conversationId 会话ID
|
|
28
|
-
* @returns 删除结果
|
|
29
|
-
*/
|
|
30
|
-
export const deleteConversation = (conversationId: string) => {
|
|
31
|
-
return http.request('DELETE', `/conversation/${conversationId}`);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 标记会话已读
|
|
36
|
-
* @param conversationId 会话ID
|
|
37
|
-
* @returns 标记结果
|
|
38
|
-
*/
|
|
39
|
-
export const markConversationRead = (conversationId: string) => {
|
|
40
|
-
return http.request('POST', `/conversation/${conversationId}/read`);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 清空会话未读计数
|
|
45
|
-
* @param conversationId 会话ID
|
|
46
|
-
* @returns 清空结果
|
|
47
|
-
*/
|
|
48
|
-
export const clearConversationUnread = (conversationId: string) => {
|
|
49
|
-
return http.request('POST', `/conversation/${conversationId}/clear-unread`);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* 创建单聊会话
|
|
54
|
-
* @param recipientId 接收者ID
|
|
55
|
-
* @returns 会话信息
|
|
56
|
-
*/
|
|
57
|
-
export const createPrivateConversation = (recipientId: string) => {
|
|
58
|
-
return http.request<IConversation>('POST', '/conversation/private', {
|
|
59
|
-
data: { recipientId }
|
|
60
|
-
});
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 创建群聊会话
|
|
65
|
-
* @param params 群聊参数
|
|
66
|
-
* @returns 会话信息
|
|
67
|
-
*/
|
|
68
|
-
export const createGroupConversation = (params: {
|
|
69
|
-
name: string;
|
|
70
|
-
avatar?: string;
|
|
71
|
-
memberIds: Array<string | number>;
|
|
72
|
-
description?: string;
|
|
73
|
-
}) => {
|
|
74
|
-
return http.request<IConversation>('POST', '/conversation/group', {
|
|
75
|
-
data: params
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 更新会话信息
|
|
81
|
-
* @param conversationId 会话ID
|
|
82
|
-
* @param params 更新参数
|
|
83
|
-
* @returns 更新结果
|
|
84
|
-
*/
|
|
85
|
-
export const updateConversation = (conversationId: string, params: {
|
|
86
|
-
name?: string;
|
|
87
|
-
avatar?: string;
|
|
88
|
-
description?: string;
|
|
89
|
-
}) => {
|
|
90
|
-
return http.request<IConversation>('PUT', `/conversation/${conversationId}`, {
|
|
91
|
-
data: params
|
|
92
|
-
});
|
|
93
|
-
};
|
package/api/im-login.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import http from '../utils/http';
|
|
2
|
-
import { IIMUserInfo } from '../types/im-user.type';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 消息已读
|
|
8
|
-
* @param conversationId 会话id
|
|
9
|
-
* @param lastReadMessageId 最后一条已读消息id
|
|
10
|
-
* @returns
|
|
11
|
-
*/
|
|
12
|
-
export function userAuth(data: {
|
|
13
|
-
account: string,
|
|
14
|
-
token: string,
|
|
15
|
-
}): Promise<IIMUserInfo> {
|
|
16
|
-
return http.request<IIMUserInfo>('POST','/users/auth', data)
|
|
17
|
-
}
|
|
18
|
-
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import http from "../../utils/http";
|
|
2
|
-
import type {
|
|
3
|
-
IMessage,
|
|
4
|
-
ISearchMessageRes,
|
|
5
|
-
} from "../../types/message-type.type";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 获取历史消息列表
|
|
9
|
-
* @param conversationId 会话id
|
|
10
|
-
* @param pageSize 每页数量
|
|
11
|
-
* @param lastMessageId 最后一条消息id
|
|
12
|
-
* @returns 历史消息列表
|
|
13
|
-
*/
|
|
14
|
-
export async function getHistoryList(
|
|
15
|
-
conversationId: string,
|
|
16
|
-
pageSize: number,
|
|
17
|
-
lastMessageId: string,
|
|
18
|
-
): Promise<Array<IMessage>> {
|
|
19
|
-
const res = await http.request<Array<IMessage>>("POST", "/messages/history", {
|
|
20
|
-
conversationId,
|
|
21
|
-
pageSize,
|
|
22
|
-
lastMessageId,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
// return res || []
|
|
26
|
-
|
|
27
|
-
return res.sort((a: any, b: any) => Number(BigInt(b.id) - BigInt(a.id)));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 搜索消息
|
|
32
|
-
* @param userId 用户id
|
|
33
|
-
* @param keyword 搜索关键词
|
|
34
|
-
* @param page 页码
|
|
35
|
-
* @param size 每页数量
|
|
36
|
-
* @returns 搜索到的消息列表
|
|
37
|
-
*/
|
|
38
|
-
export function searchMessage(data: {
|
|
39
|
-
conversationId: string;
|
|
40
|
-
keyword: string;
|
|
41
|
-
page: number;
|
|
42
|
-
size: number;
|
|
43
|
-
}): Promise<Array<ISearchMessageRes>> {
|
|
44
|
-
// return http.Post<Array<ISearchMessageRes>>('/messages/search', data)
|
|
45
|
-
|
|
46
|
-
return http.request<Array<ISearchMessageRes>>(
|
|
47
|
-
"POST",
|
|
48
|
-
"/messages/search",
|
|
49
|
-
data,
|
|
50
|
-
);
|
|
51
|
-
}
|
package/index.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ZSL IM SDK 核心入口
|
|
3
|
-
* 提供 IM 功能的核心能力:状态管理、WebSocket 连接、消息收发等
|
|
4
|
-
*
|
|
5
|
-
* @example
|
|
6
|
-
* // 在 main.js 中安装
|
|
7
|
-
* import { install } from '@zsl-im/sdk'
|
|
8
|
-
* Vue.use(install)
|
|
9
|
-
*
|
|
10
|
-
* // 在组件中使用
|
|
11
|
-
* this.$store.dispatch('login', { user, wsUrl, token })
|
|
12
|
-
* this.$store.dispatch('sendMessage', messageData)
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
import store, { install } from './store'
|
|
16
|
-
import { setBaseURL } from './utils/http'
|
|
17
|
-
|
|
18
|
-
// 增强 install 方法,支持配置
|
|
19
|
-
const originalInstall = install
|
|
20
|
-
export const installWithConfig = (vue: any, options: { baseURL?: string } = {}) => {
|
|
21
|
-
if (options.baseURL) {
|
|
22
|
-
setBaseURL(options.baseURL)
|
|
23
|
-
}
|
|
24
|
-
originalInstall(vue)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type { IMessage, IUser, IState } from './store'
|
|
28
|
-
export { default as IM } from './websocket'
|
|
29
|
-
export * from './types'
|
|
30
|
-
export * from './api/common/common.api'
|
|
31
|
-
export * from './api/conversation/conversation.api'
|
|
32
|
-
export * from './api/message/message.api'
|
|
33
|
-
export * from './api/im-login'
|
|
34
|
-
|
|
35
|
-
export { store, installWithConfig as install }
|
|
36
|
-
export default store
|
package/jsconfig.json
DELETED