class TimeInterval {
  timer: any = null;
  send() {
    postMessage("");
  }
  isActive = false;

  pause() {
    if (this.timer) {
      clearInterval(this.timer);
      this.timer = null;
    }
    this.isActive = false;
    postMessage(false);
  }
  resume() {
    const func = this.send;
    this.timer = setInterval(func, 1000);
    this.isActive = true;
    postMessage(true);
  }
}

const onlineInterval = new TimeInterval();

addEventListener("message", (e: any) => {
  const data = e.data as boolean;
  if (data) {
    onlineInterval.resume();
  } else {
    onlineInterval.pause();
  }
});
