优化 WebSocket 连接管理,确保在注册新连接时关闭旧连接
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user