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

Expose timeout= on /events to clients

This commit is contained in:
Kegan Dougal
2015-11-03 10:18:56 +00:00
parent 0fb307d09b
commit 3b21998d96

View File

@@ -1999,6 +1999,8 @@ function doInitialSync(client, historyLen, includeArchived) {
* @param {Boolean} opts.resolveInvitesToProfiles True to do /profile requests * @param {Boolean} opts.resolveInvitesToProfiles True to do /profile requests
* on every invite event if the displayname/avatar_url is not known for this user ID. * on every invite event if the displayname/avatar_url is not known for this user ID.
* Default: false. * Default: false.
* @param {Number} opts.pollTimeout The number of milliseconds to wait on /events.
* Default: 30000 (30 seconds).
*/ */
MatrixClient.prototype.startClient = function(opts) { MatrixClient.prototype.startClient = function(opts) {
if (this.clientRunning) { if (this.clientRunning) {
@@ -2016,6 +2018,7 @@ MatrixClient.prototype.startClient = function(opts) {
opts.initialSyncLimit = opts.initialSyncLimit || 8; opts.initialSyncLimit = opts.initialSyncLimit || 8;
opts.includeArchivedRooms = opts.includeArchivedRooms || false; opts.includeArchivedRooms = opts.includeArchivedRooms || false;
opts.resolveInvitesToProfiles = opts.resolveInvitesToProfiles || false; opts.resolveInvitesToProfiles = opts.resolveInvitesToProfiles || false;
opts.pollTimeout = opts.pollTimeout || (30 * 1000);
this._config = opts; this._config = opts;
if (CRYPTO_ENABLED && this.sessionStore !== null) { if (CRYPTO_ENABLED && this.sessionStore !== null) {
@@ -2054,11 +2057,11 @@ function _pollForEvents(client) {
discardResult = true; discardResult = true;
console.error("/events request timed out."); console.error("/events request timed out.");
_pollForEvents(client); _pollForEvents(client);
}, 40000); }, client._config.pollTimeout + (20 * 1000)); // 20s buffer
client._http.authedRequest(undefined, "GET", "/events", { client._http.authedRequest(undefined, "GET", "/events", {
from: client.store.getSyncToken(), from: client.store.getSyncToken(),
timeout: 30000 timeout: client._config.pollTimeout
}).done(function(data) { }).done(function(data) {
if (discardResult) { if (discardResult) {
return; return;