1 changed files with 28 additions and 0 deletions
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
const URL = '/api/ping'; |
||||
const INTERVAL = 4000; |
||||
|
||||
function ping() { |
||||
try { |
||||
fetch(URL); |
||||
} catch (e) { |
||||
console.error(e); |
||||
} |
||||
} |
||||
|
||||
class ViewerPing { |
||||
timer: ReturnType<typeof setInterval>; |
||||
|
||||
start() { |
||||
this.stop(); |
||||
|
||||
this.timer = setInterval(() => { |
||||
ping(); |
||||
}, INTERVAL); |
||||
} |
||||
|
||||
stop() { |
||||
clearInterval(this.timer); |
||||
} |
||||
} |
||||
|
||||
export default ViewerPing; |
Loading…
Reference in new issue