ai生成设计书文档,并解决文档中指出的部分bug
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
const WebSocket = require("ws");
|
||||
|
||||
const onlineUsers = new Map();
|
||||
|
||||
// 保存用户连接
|
||||
@@ -30,9 +32,13 @@ function getOnlineUsers() {
|
||||
function broadcast(data) {
|
||||
const message = JSON.stringify(data);
|
||||
|
||||
for (const ws of onlineUsers.values()) {
|
||||
for (const [username, ws] of onlineUsers) {
|
||||
if (ws.readyState === WebSocket.OPEN) {
|
||||
ws.send(message);
|
||||
ws.send(message, (error) => {
|
||||
if (error) {
|
||||
console.error(`向用户 ${username} 广播失败:`, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user