code: function monitor(interval, timeoutCb, pingTimeout) {
    pingTimeout = pingTimeout || interval;
    let currentTimeout;
    let currentInterval;
    let closed = false;
  
    const onTimeoutExpired = () => {
      if (closed) return;
      closed = true;
  
      clearTimeout(currentTimeout);
      clearInterval(currentInterval);
      timeoutCb();
    };
  
  
    const ping = () => {
      this.ping(undefined, undefined, true);
  
      if (currentTimeout) return;
      currentTimeout = setTimeout(onTimeoutExpired, pingTimeout);
    };
  
    this.on('pong', () => {
      clearTimeout(currentTimeout);
      currentTimeout = undefined;
    });
  
    this.on('close', () => onTimeoutExpired());
    this.on('error', () => onTimeoutExpired());
    currentInterval = setInterval(() => ping(), interval);
  }
docs: Constantly monitors if the connection is still open using ping/pong every
  `interval` milliseconds. `timeoutCb` is called when the ping/pong doesn't
  answer for `pingTimeout` milliseconds. If `pingTimeout` is not set, it
  will equal `interval`