From 3157a392aa9134ed27f7db0995e244fcbe6be6d0 Mon Sep 17 00:00:00 2001 From: moonrailgun Date: Tue, 12 Oct 2021 16:00:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=96=AD=E7=BA=BF?= =?UTF-8?q?=E9=87=8D=E8=BF=9E=E5=90=8E=E6=95=B0=E6=8D=AE=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- shared/api/socket.ts | 9 ++++++++- shared/redux/setup.ts | 6 ++++++ shared/redux/slices/group.ts | 3 +++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/shared/api/socket.ts b/shared/api/socket.ts index 872eb1db..f807950c 100644 --- a/shared/api/socket.ts +++ b/shared/api/socket.ts @@ -23,7 +23,7 @@ type SocketEventRespones = * 封装后的 Socket */ export class AppSocket { - listener: [string, (data: unknown) => void][] = []; + private listener: [string, (data: unknown) => void][] = []; constructor(private socket: Socket) { socket.onAny((eventName: string, data: unknown) => { @@ -70,6 +70,13 @@ export class AppSocket { this.socket.close(); } + /** + * 断线重连后触发 + */ + onReconnect(cb: () => void) { + this.socket.on('reconnect', cb); + } + /** * 初始Socket状态管理提示 */ diff --git a/shared/redux/setup.ts b/shared/redux/setup.ts index bc64bbfe..ce639e7b 100644 --- a/shared/redux/setup.ts +++ b/shared/redux/setup.ts @@ -22,6 +22,12 @@ import { appendUserDMConverse } from '../model/user'; export function setupRedux(socket: AppSocket, store: AppStore) { initial(socket, store); listenNotify(socket, store); + + // 断线重连重新初始化信息 + socket.onReconnect(() => { + console.warn('因为断线重连触发重新同步远程数据'); + initial(socket, store); + }); } /** diff --git a/shared/redux/slices/group.ts b/shared/redux/slices/group.ts index 0c89a9eb..f682049b 100644 --- a/shared/redux/slices/group.ts +++ b/shared/redux/slices/group.ts @@ -13,6 +13,9 @@ const groupSlice = createSlice({ name: 'group', initialState, reducers: { + /** + * 追加或更新群组信息 + */ appendGroups(state, action: PayloadAction) { const groups = action.payload;