AjaxMonitor - Voliware/AjaxPlus GitHub Wiki

He Knows When You Are Requesting...

When you need to prove to your user that what they see is the latest-and-greatest, most up-to-date, bleeding-edge, and overly-hyphenated data around, you should fire up an AjaxMonitor in your app. This monitor interacts with all AJAX requests your app makes. All of them.

AjaxMonitor emits a disconnected event when enough requests have failed in some period of time. It then starts its own heartbeat/keepalive, and finally emits a connected event as soon as one is successful. During a period of disconnection, AjaxMonitor by default immediately aborts all application requests.

// allow up to 4 failures every 30 seconds
var ajaxMonitor = new AjaxMontitor({
   heartbeatUrl : '/',
   maxFailures : 4,
   resetTimer : 30000
})
.on('disconnected', function(){
   app.toggleAppDisconnected(true);
})
.on('connected', function(){
   app.toggleAppDisconnected(false);
})
.start();

AjaxMonitor should be initiated before any other modules. It does not need to directly tie into anything as it does all the work in the background. The only additions that should be applied are the listeners for the disconnected and connected events, otherwise, it's not very useful. You will also need to tune the monitor to the frequency of your application's requests.