owncast/web/components/video/viewer-ping.ts

29 lines
377 B
TypeScript
Raw Permalink Normal View History

2022-05-09 23:06:17 +03:00
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;