import { action, IReactionDisposer, observable, observe, reaction } from "mobx"; import { Networking } from "../Network"; export class PingManager { // create static instance and getter for global use @observable static _instance: PingManager; static get Instance(): PingManager { return PingManager._instance; } @observable isBeating: boolean = true; private setIsBeating = action((status: boolean) => this.isBeating = status); ping = async (): Promise => { try { const response = await Networking.PostToServer('/ping', { date: new Date() }); // console.log('ping response', response, this.interval); !this.isBeating && this.setIsBeating(true); } catch { console.error('ping error'); this.isBeating && this.setIsBeating(false); } } // not used now, but may need to clear interval private interval: NodeJS.Timeout | null = null; INTERVAL_SECONDS = 1; constructor() { PingManager._instance = this; this.interval = setInterval(this.ping, this.INTERVAL_SECONDS * 1000); } }