ping as soon as the websoket is open, and then more often

This commit is contained in:
Thibault Duplessis 2012-06-01 21:05:03 +02:00
parent bae4fe2d68
commit 62e87b962e
2 changed files with 26 additions and 29 deletions

View file

@ -14,7 +14,7 @@ $.websocket = function(url, version, settings) {
offlineTag: false,
pingData: JSON.stringify({t: "p"}),
pingTimeout: 5000,
pingDelay: 2500
pingDelay: 1500
}
};
$.extend(true, this.settings, settings);
@ -45,6 +45,7 @@ $.websocket.prototype = {
self._debug("connected to " + self.fullUrl);
if (self.offlineTimeout) clearTimeout(self.offlineTimeout);
if (self.options.offlineTag) self.options.offlineTag.hide();
self._keepAlive();
self.settings.open();
})
.bind('close', function() {
@ -57,7 +58,7 @@ $.websocket.prototype = {
.bind('message', function(e){
var m = JSON.parse(e.originalEvent.data);
if (m.t == "n") {
self.keepAlive();
setTimeout(function() { self._keepAlive(); }, self.options.pingDelay);
}
self._debug(m);
if (m.t == "batch") {
@ -66,12 +67,10 @@ $.websocket.prototype = {
self._handle(m);
}
});
self.keepAlive();
},
keepAlive: function() {
_keepAlive: function() {
var self = this;
clearTimeout(self.pingTimeout);
setTimeout(function() {
try {
self.ws.send(self.options.pingData);
self.pingTimeout = setTimeout(function() {
@ -79,10 +78,10 @@ $.websocket.prototype = {
self.connect();
}, self.options.pingTimeout);
} catch (e) {
throw e;
self._debug(e);
self.connect();
}
}, self.options.pingDelay);
},
send: function(t, d) {
var data = d || {};

2
todo
View file

@ -33,8 +33,6 @@ new elo system http://en.wikipedia.org/wiki/Glicko_rating_system
spectator chat!
guess friend list
star people and games (and forum threads?)
opening not recognized http://fr.lichess.org/forum/lichess-feedback/big-deploy-29-may-2012?page=7#70
websocket ping asap (to get nb players)
new translations:
-rematchOfferCanceled=Rematch offer canceled