From f79a2b2f661199f819bf14c3f52833a38ec082d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A7=89?= Date: Sun, 22 Oct 2023 18:30:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E5=BF=83=E8=B7=B3=E6=B5=8B?= =?UTF-8?q?=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.js | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main.js b/src/main.js index cdb16bc..70f7cfe 100644 --- a/src/main.js +++ b/src/main.js @@ -166,28 +166,28 @@ const chat = new Chat({ } }) -// 与每个客户端保持心跳 -clientList.setChannel('ping', { - onopen: async (event, client) => { - console.log('打开信道', event.target.label) - clientList.sendto(client.id, 'ping', JSON.stringify({ type: 'ping' })) - }, - onmessage: async (event, client) => { - const data = JSON.parse(event.data) - if (data.type === 'ping') { - console.log(client.name, '心跳:', data) - clientList.sendto(client.id, 'ping', JSON.stringify({ type: 'pong' })) - return - } - if (data.type === 'pong') { - console.log(client.name, '心跳:', data) - await new Promise((resolve) => setTimeout(resolve, 5000)) - clientList.sendto(client.id, 'ping', JSON.stringify({ type: 'ping' })) - return - } - console.log('未知类型:', data.type) - } -}) +//// 与每个客户端保持心跳 +//clientList.setChannel('ping', { +// onopen: async (event, client) => { +// console.log('打开信道', event.target.label) +// clientList.sendto(client.id, 'ping', JSON.stringify({ type: 'ping' })) +// }, +// onmessage: async (event, client) => { +// const data = JSON.parse(event.data) +// if (data.type === 'ping') { +// console.log(client.name, '心跳:', data) +// clientList.sendto(client.id, 'ping', JSON.stringify({ type: 'pong' })) +// return +// } +// if (data.type === 'pong') { +// console.log(client.name, '心跳:', data) +// await new Promise((resolve) => setTimeout(resolve, 5000)) +// clientList.sendto(client.id, 'ping', JSON.stringify({ type: 'ping' })) +// return +// } +// console.log('未知类型:', data.type) +// } +//}) // 与每个客户端都建立聊天信道 clientList.setChannel('chat', {