实现IM聊天群聊功能,包括群聊列表和创建群聊接口,优化消息处理和未读消息统计,增强用户体验。
This commit is contained in:
@@ -10,6 +10,15 @@ import { useUserStore } from '/@/store/modules/user';
|
||||
let result: WebSocketResult<any>;
|
||||
const listeners = new Map();
|
||||
let connectedUrl = '';
|
||||
//update-begin---author:xsl ---date:20260528 for:【IM聊天】WS 重连后通知监听方重新拉取消息-----------
|
||||
let wsConnectionCount = 0;
|
||||
const reconnectListeners = new Set<() => void>();
|
||||
|
||||
export function onWebSocketReconnect(callback: () => void) {
|
||||
reconnectListeners.add(callback);
|
||||
return () => reconnectListeners.delete(callback);
|
||||
}
|
||||
//update-end---author:xsl ---date:20260528 for:【IM聊天】WS 重连后通知监听方重新拉取消息-----------
|
||||
|
||||
/**
|
||||
* 构建系统 WebSocket 地址(含 context-path,如 /jeecg-boot)
|
||||
@@ -67,7 +76,15 @@ export function connectWebSocket(url: string) {
|
||||
protocols: [token],
|
||||
// 代码逻辑说明: [issues/6662] 演示系统socket总断,换一个写法
|
||||
onConnected: function (ws) {
|
||||
wsConnectionCount++;
|
||||
console.log('[WebSocket] 连接成功', ws);
|
||||
//update-begin---author:xsl ---date:20260528 for:【IM聊天】WS 重连后通知监听方重新拉取消息-----------
|
||||
if (wsConnectionCount > 1) {
|
||||
reconnectListeners.forEach((cb) => {
|
||||
try { cb(); } catch (err) { console.error(err); }
|
||||
});
|
||||
}
|
||||
//update-end---author:xsl ---date:20260528 for:【IM聊天】WS 重连后通知监听方重新拉取消息-----------
|
||||
},
|
||||
onDisconnected: function (ws, event) {
|
||||
console.log('[WebSocket] 连接断开:', ws, event);
|
||||
|
||||
Reference in New Issue
Block a user