diff --git a/index.js b/index.js index 2f1aebe..800a585 100644 --- a/index.js +++ b/index.js @@ -265,12 +265,13 @@ export async function prepareBot() { bot.on('scan', (qrcode) => { // 生成微信登录二维码 qrcodeToTerminal(qrcode); - wss.on('connection', (ws) => { - ws.on('close', () => { - console.log('客户端失去连接'); - }); - console.log("发送二维码") - ws.send(qrcode); + + wss.clients.forEach((client) => { + console.log("发送二维码",client) + + if (client.readyState === WebSocket.OPEN) { // Ensure the client is open + client.send(qrcode); + } }); }) @@ -286,6 +287,9 @@ export async function prepareBot() { return console.error(error); } }); + wss.clients.forEach((client) => { + client.close(); // Important: Close client after login + }); }) bot.on("error", (e) => {