app.factory('serverWarning', function(noty, socket) {
  var SECONDS = 30;
  var timeoutWarning;

  function reset() {
    if (timeoutWarning !== undefined) {
      noty.clear();
      clearTimeout(timeoutWarning);
    }
    timeoutWarning = setTimeout(function() {
      noty.update('warning',
        'The server has not sent updates in the last ' +
        SECONDS + ' seconds.');
    }, 1000 * SECONDS);
  }

  socket.on('update', reset);
  socket.on('error', function(data) {
    reset();
    noty.update('warning', 'Error communicating with PagerDuty: ' + data);
  });

  return {
    reset: reset
  };
});

app.factory('serverWarning', function(noty, socket) {
  var SECONDS = 30;
  var timeoutWarning;

  function resetTimeout() {
    if (timeoutWarning !== undefined) {
      clearTimeout(timeoutWarning);
    }
    timeoutWarning = setTimeout(function() {
      noty.update('warning',
        'The server has not sent updates in the last ' +
        SECONDS + ' seconds.');
    }, 1000 * SECONDS);
  }

  function reset() {
    noty.clear();
    resetTimeout();
  }

  socket.on('update', reset);
  socket.on('error', function(data) {
    resetTimeout();
    noty.update('warning', 'Error communicating with PagerDuty: ' + data);
  });

  return {
    reset: reset
  };
});

Fix for server warning flipping on/off on connection problems