fix ping 2
This commit is contained in:
@@ -30,6 +30,7 @@ wss.on('connection', function connection(ws: WebSocket & { isAlive: boolean }, r
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
ws.onmessage = function (msg) {
|
ws.onmessage = function (msg) {
|
||||||
|
console.log(msg.data)
|
||||||
if (msg.data === "pong") {
|
if (msg.data === "pong") {
|
||||||
ws.isAlive = true
|
ws.isAlive = true
|
||||||
}
|
}
|
||||||
@@ -39,6 +40,7 @@ wss.on('connection', function connection(ws: WebSocket & { isAlive: boolean }, r
|
|||||||
|
|
||||||
const interval = setInterval(function ping() {
|
const interval = setInterval(function ping() {
|
||||||
wss.clients.forEach(function each(ws) {
|
wss.clients.forEach(function each(ws) {
|
||||||
|
console.log("isAlive :" + (ws as WebSocket & { isAlive: boolean }).isAlive)
|
||||||
if ((ws as WebSocket & { isAlive: boolean }).isAlive === false) return ws.terminate();
|
if ((ws as WebSocket & { isAlive: boolean }).isAlive === false) return ws.terminate();
|
||||||
|
|
||||||
(ws as WebSocket & { isAlive: boolean }).isAlive = false;
|
(ws as WebSocket & { isAlive: boolean }).isAlive = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user