1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-18 05:42:00 +03:00

Use a small timeout when trying to poll when having previously failed. This makes re-connects propagate more quickly.

This commit is contained in:
Kegan Dougal
2015-11-09 15:55:09 +00:00
parent d7874315c3
commit 6eb896e7a3

View File

@@ -2150,16 +2150,23 @@ function _pollForEvents(client, attempt) {
if (!client.clientRunning) {
return;
}
var timeoutMs = client._config.pollTimeout;
if (attempt > 1) {
// we think the connection is dead. If it comes back up, we won't know
// about it till /events returns. If the timeout= is high, this could
// be a long time. Set it to 1 when doing retries.
timeoutMs = 1;
}
var discardResult = false;
var timeoutObj = setTimeout(function() {
discardResult = true;
console.error("/events request timed out.");
_pollForEvents(client);
}, client._config.pollTimeout + (20 * 1000)); // 20s buffer
}, timeoutMs + (20 * 1000)); // 20s buffer
client._http.authedRequest(undefined, "GET", "/events", {
from: client.store.getSyncToken(),
timeout: client._config.pollTimeout
timeout: timeoutMs
}).done(function(data) {
if (discardResult) {
return;