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(