mirror of
https://github.com/viarotel-org/escrcpy.git
synced 2025-02-01 03:55:47 +01:00
20 lines
395 B
JavaScript
20 lines
395 B
JavaScript
|
const ws = new WebSocket('wss://websocket-echo.com/')
|
||
|
|
||
|
let timeout = null
|
||
|
function heartbeat() {
|
||
|
clearTimeout(timeout)
|
||
|
|
||
|
timeout = setTimeout(() => {
|
||
|
ws.close()
|
||
|
}, 30000 + 1000)
|
||
|
}
|
||
|
|
||
|
ws.addEventListener('error', console.error)
|
||
|
ws.addEventListener('open', heartbeat)
|
||
|
ws.addEventListener('ping', heartbeat)
|
||
|
ws.addEventListener('close', () => {
|
||
|
clearTimeout(timeout)
|
||
|
})
|
||
|
|
||
|
export default ws
|