core: websocket: use ping frame rather than ping message (#717)

This commit is contained in:
Yang Gao authored and GitHub committed 2024-01-25 11:26:08 +08:00
1 parent ac24564212
commit bdbce10ecd
1 file changed
+4 -1
+4 -1
View File
@@ -438,8 +438,11 @@ export function Connection(
clean(); clean();
conn.terminate(); conn.terminate();
} }
if (Date.now() - lastHeartbeat > 30000) conn.send('ping'); if (Date.now() - lastHeartbeat > 30000) conn.ping();
}, 40000); }, 40000);
conn.on('pong', () => {
lastHeartbeat = Date.now();
});
conn.onmessage = (e) => { conn.onmessage = (e) => {
lastHeartbeat = Date.now(); lastHeartbeat = Date.now();
if (e.data === 'pong') return; if (e.data === 'pong') return;