escrcpy/copilot/utils/ws.js
2023-11-22 09:56:18 +08:00

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