Skip to content

Commit

Permalink
Faster reconnects. Fixes #696
Browse files Browse the repository at this point in the history
- Lower reconnect timeout to 5m
- Respond to the 'online' event to reconnect immediately
  eg. in case you switched from 3G to Wi-Fi
  • Loading branch information
avital committed May 10, 2013
1 parent 0893b82 commit 7f97051
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 10 additions & 2 deletions packages/livedata/stream_client_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,10 @@ _.extend(Meteor._DdpClientStream.prototype, {
self.RETRY_BASE_TIMEOUT = 1000;
// exponential factor to increase timeout each attempt.
self.RETRY_EXPONENT = 2.2;
// maximum time between reconnects.
self.RETRY_MAX_TIMEOUT = 1800000; // 30min.
// maximum time between reconnects. keep this intentionally
// high-ish to ensure a server can recover from a failure caused
// by load
self.RETRY_MAX_TIMEOUT = 5 * 60000; // 5 minutes
// time to wait for the first 2 retries. this helps page reload
// speed during dev mode restarts, but doesn't hurt prod too
// much (due to CONNECT_TIMEOUT)
Expand Down Expand Up @@ -191,6 +193,12 @@ _.extend(Meteor._DdpClientStream.prototype, {
return timeout;
},

// fired when we detect that we've gone online. try to reconnect
// immediately.
_online: function () {
this.reconnect();
},

_retryLater: function () {
var self = this;

Expand Down
4 changes: 4 additions & 0 deletions packages/livedata/stream_client_sockjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Meteor._DdpClientStream = function (url) {

self.heartbeatTimer = null;

//// Listen to global 'online' event
if (typeof window !== 'undefined') // if we are running in a browser
window.addEventListener("online", _.bind(self._online, self));

//// Kickoff!
self._launchConnection();
};
Expand Down

0 comments on commit 7f97051

Please sign in to comment.