1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Add a delay before we start polling the connectivity check endpoint to avoid tightlooping if the conn check succeeds but /sync etc fails.

This commit is contained in:
David Baker
2016-03-14 16:50:00 +00:00
parent fc1d5c86f9
commit 5e18c84e53

View File

@@ -382,7 +382,7 @@ SyncApi.prototype.stop = function() {
*/
SyncApi.prototype.retryImmediately = function() {
if (!this._connectionReturnedDefer) { return false; }
this._startKeepAlives();
this._startKeepAlives(0);
return true;
};
@@ -686,13 +686,25 @@ SyncApi.prototype._processSyncResponse = function(syncToken, data) {
};
/**
* Starts polling the connectivity check endpoint
* @param {number} delay How long to delay until the first poll.
* defaults to a short, randomised interval (to prevent
* tightlooping if /versions succeeds but /sync etc. fail).
* @return {promise}
*/
SyncApi.prototype._startKeepAlives = function() {
SyncApi.prototype._startKeepAlives = function(delay) {
if (delay === undefined) {
delay = 5000 + Math.floor(Math.random() * 5000)
}
if (this._keepAliveTimer !== null) {
clearTimeout(this._keepAliveTimer);
}
this._pokeKeepAlive();
var self = this;
self._keepAliveTimer = setTimeout(
self._pokeKeepAlive.bind(self),
delay
);
if (!this._connectionReturnedDefer) {
this._connectionReturnedDefer = q.defer();
}
@@ -948,7 +960,7 @@ SyncApi.prototype._updateSyncState = function(newState, data) {
*/
SyncApi.prototype._onOnline = function() {
debuglog("Browser thinks we are back online");
this._startKeepAlives();
this._startKeepAlives(0);
};
function createNewUser(client, userId) {