添加websocket连接

This commit is contained in:
2026-09-22 16:27:22 +08:00
parent 991993e0c2
commit d02a2c7d5a
25 changed files with 5829 additions and 3 deletions
+28
View File
@@ -0,0 +1,28 @@
const connections = new Map();
// 保存用户连接
function addConnection(username, ws) {
connections.set(username, ws);
console.log(`用户 ${username} 已连接`);
console.log("当前在线用户:", [...connections.keys()]);
}
// 获取用户连接
function getConnection(username) {
return connections.get(username);
}
// 删除用户连接
function removeConnection(username) {
connections.delete(username);
console.log(`用户 ${username} 已断开`);
console.log("当前在线用户:", [...connections.keys()]);
}
module.exports = {
addConnection,
getConnection,
removeConnection,
};