移除心跳测试
This commit is contained in:
parent
f85316b86c
commit
f79a2b2f66
44
src/main.js
44
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', {
|
||||
|
Loading…
Reference in New Issue
Block a user