You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Merge branch 'develop' into kegan/indexeddb
This commit is contained in:
41
src/sync.js
41
src/sync.js
@@ -77,6 +77,7 @@ function SyncApi(client, opts) {
|
||||
this._peekRoomId = null;
|
||||
this._currentSyncRequest = null;
|
||||
this._syncState = null;
|
||||
this._catchingUp = false;
|
||||
this._running = false;
|
||||
this._keepAliveTimer = null;
|
||||
this._connectionReturnedDefer = null;
|
||||
@@ -487,9 +488,30 @@ SyncApi.prototype._sync = function(syncOptions) {
|
||||
|
||||
const syncToken = client.store.getSyncToken();
|
||||
|
||||
let pollTimeout = this.opts.pollTimeout;
|
||||
|
||||
if (this.getSyncState() !== 'SYNCING' || this._catchingUp) {
|
||||
// unless we are happily syncing already, we want the server to return
|
||||
// as quickly as possible, even if there are no events queued. This
|
||||
// serves two purposes:
|
||||
//
|
||||
// * When the connection dies, we want to know asap when it comes back,
|
||||
// so that we can hide the error from the user. (We don't want to
|
||||
// have to wait for an event or a timeout).
|
||||
//
|
||||
// * We want to know if the server has any to_device messages queued up
|
||||
// for us. We do that by calling it with a zero timeout until it
|
||||
// doesn't give us any more to_device messages.
|
||||
this._catchingUp = true;
|
||||
pollTimeout = 0;
|
||||
}
|
||||
|
||||
// normal timeout= plus buffer time
|
||||
const clientSideTimeoutMs = pollTimeout + BUFFER_PERIOD_MS;
|
||||
|
||||
const qps = {
|
||||
filter: filterId,
|
||||
timeout: this.opts.pollTimeout,
|
||||
timeout: pollTimeout,
|
||||
};
|
||||
|
||||
if (syncToken) {
|
||||
@@ -527,9 +549,6 @@ SyncApi.prototype._sync = function(syncOptions) {
|
||||
}
|
||||
}
|
||||
|
||||
// normal timeout= plus buffer time
|
||||
const clientSideTimeoutMs = this.opts.pollTimeout + BUFFER_PERIOD_MS;
|
||||
|
||||
if (!isCachedResponse) {
|
||||
debuglog('Starting sync since=' + syncToken);
|
||||
this._currentSyncRequest = client._http.authedRequest(
|
||||
@@ -564,6 +583,7 @@ SyncApi.prototype._sync = function(syncOptions) {
|
||||
const syncEventData = {
|
||||
oldSyncToken: syncToken,
|
||||
nextSyncToken: data.next_batch,
|
||||
catchingUp: self._catchingUp,
|
||||
};
|
||||
|
||||
if (!syncOptions.hasSyncedBefore) {
|
||||
@@ -691,7 +711,9 @@ SyncApi.prototype._processSyncResponse = function(syncToken, data) {
|
||||
}
|
||||
|
||||
// handle to-device events
|
||||
if (data.to_device && utils.isArray(data.to_device.events)) {
|
||||
if (data.to_device && utils.isArray(data.to_device.events) &&
|
||||
data.to_device.events.length > 0
|
||||
) {
|
||||
data.to_device.events
|
||||
.map(client.getEventMapper())
|
||||
.forEach(
|
||||
@@ -712,6 +734,9 @@ SyncApi.prototype._processSyncResponse = function(syncToken, data) {
|
||||
client.emit("toDeviceEvent", toDeviceEvent);
|
||||
},
|
||||
);
|
||||
} else {
|
||||
// no more to-device events: we can stop polling with a short timeout.
|
||||
this._catchingUp = false;
|
||||
}
|
||||
|
||||
// the returned json structure is a bit crap, so make it into a
|
||||
@@ -917,7 +942,7 @@ SyncApi.prototype._processSyncResponse = function(syncToken, data) {
|
||||
* @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}
|
||||
* @return {promise} which resolves once the connection returns
|
||||
*/
|
||||
SyncApi.prototype._startKeepAlives = function(delay) {
|
||||
if (delay === undefined) {
|
||||
@@ -943,7 +968,11 @@ SyncApi.prototype._startKeepAlives = function(delay) {
|
||||
};
|
||||
|
||||
/**
|
||||
* Make a dummy call to /_matrix/client/versions, to see if the HS is
|
||||
* reachable.
|
||||
*
|
||||
* On failure, schedules a call back to itself. On success, resolves
|
||||
* this._connectionReturnedDefer.
|
||||
*/
|
||||
SyncApi.prototype._pokeKeepAlive = function() {
|
||||
const self = this;
|
||||
|
||||
Reference in New Issue
Block a user