From bf436f05e3434e7e72dac3b29a283d016bf7affe Mon Sep 17 00:00:00 2001 From: abearxiong Date: Thu, 5 Feb 2026 13:38:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=20WebSocket=20=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E7=AE=A1=E7=90=86=EF=BC=8C=E7=A1=AE=E4=BF=9D=E5=9C=A8?= =?UTF-8?q?=E6=B3=A8=E5=86=8C=E6=96=B0=E8=BF=9E=E6=8E=A5=E6=97=B6=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E6=97=A7=E8=BF=9E=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/modules/ws-proxy/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/modules/ws-proxy/index.ts b/src/modules/ws-proxy/index.ts index 5c5a5be..4b886e8 100644 --- a/src/modules/ws-proxy/index.ts +++ b/src/modules/ws-proxy/index.ts @@ -22,6 +22,12 @@ export const wssFun: WebSocketListenerFun = async (req, res) => { const user = loginUser?.tokenUser?.username; const userApp = user + '-' + id; logger.debug('注册 ws 连接', userApp); + const wsMessage = wsProxyManager.get(userApp); + if (wsMessage) { + logger.debug('ws 连接已存在,关闭旧连接', userApp); + wsMessage.ws.close(); + wsProxyManager.unregister(userApp); + } // @ts-ignore wsProxyManager.register(userApp, { user, ws }); ws.send(