ultimatepos/Modules/Communication/Resources/js/composables/usePresence.js

24 lines
568 B
JavaScript
Vendored

import { getConfig } from '../utils/config';
import { sendHeartbeat } from '../api/chat';
export function usePresence() {
const config = getConfig();
const intervalMs = (config.presenceHeartbeatSeconds || 60) * 1000;
let timer = null;
function start() {
if (timer) return;
const tick = () => sendHeartbeat().catch(() => {});
tick();
timer = setInterval(tick, intervalMs);
}
function stop() {
if (!timer) return;
clearInterval(timer);
timer = null;
}
return { start, stop };
}