Skip to content

Commit

Permalink
WS retry mechanism to handle early messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed May 23, 2015
1 parent 5a62323 commit c4ef6e5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions public/javascripts/big.js
Expand Up @@ -118,7 +118,7 @@ lichess.StrongSocket.prototype = {
}
self.scheduleConnect(self.options.pingMaxLag);
},
send: function(t, d, o) {
send: function(t, d, o, again) {
var self = this;
var data = d || {},
options = o || {};
Expand All @@ -135,7 +135,12 @@ lichess.StrongSocket.prototype = {
try {
self.ws.send(message);
} catch (e) {
self.debug(e);
// maybe sent before socket opens,
// try again a second later,once.
if (!again) setTimeout(function() {
this.send(t, d, o, true);
}.bind(this), 1000);
else console.log(e, 'again');
}
},
sendAckable: function(t, d) {
Expand Down

0 comments on commit c4ef6e5

Please sign in to comment.