添加websocket连接
This commit is contained in:
@@ -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,
|
||||
};
|
||||
Reference in New Issue
Block a user