PDA

View Full Version : Pinger - Sends requests at regular intervals



para
8 Oct 2007, 7:17 AM
Here's a basic class I made to ping an address at regular intervals.
I use this to keep the user's session alive while they are doing static work on the page. Essentially, while they are on a certain section of my page, there is the potential for their session to timeout, which should not occur.

It extends Ext.data.Connection, so all the parameters of that are available. I provide a couple more: autoStart and timer.

It doesn't have too many useful applications, but it does what I need it to.


Example use:


configs:
autoStart: 'true' to automatically start pinging immediately.
timer: time between pings (approximate, depending on request time)

// This will request 'myPage.html' every 5 minutes.
var pinger = new Pinger({url:'myPage.html', timer:300000, autoStart:true});

//or

var pinger = new Pinger({url:'myPage.html', timer:300000});
pinger.start();



EDIT:
Some events are also provided:


pinger.on('beforeping', function() {});

pinger.on('afterping', function(options, success, response) {});

// can override callback (original callback is empty)
pinger.callback = function(options, success, response) {}

para
28 Jan 2008, 10:29 AM
Updated to remove all defered ping calls when stopping. Possible for users to cause irregular pings if turning pinging on/off.