Merge branch 'client-enhance-add-timeout-factor' into 'master'
[Client] Add timeout factor See merge request famedly/famedlysdk!193
This commit is contained in:
commit
b7dea7c6a5
|
@ -142,6 +142,8 @@ class Client {
|
||||||
/// Presences of users by a given matrix ID
|
/// Presences of users by a given matrix ID
|
||||||
Map<String, Presence> presences = {};
|
Map<String, Presence> presences = {};
|
||||||
|
|
||||||
|
int _timeoutFactor = 1;
|
||||||
|
|
||||||
Room getRoomByAlias(String alias) {
|
Room getRoomByAlias(String alias) {
|
||||||
for (int i = 0; i < rooms.length; i++) {
|
for (int i = 0; i < rooms.length; i++) {
|
||||||
if (rooms[i].canonicalAlias == alias) return rooms[i];
|
if (rooms[i].canonicalAlias == alias) return rooms[i];
|
||||||
|
@ -777,7 +779,7 @@ class Client {
|
||||||
if (this.isLogged() == false && this.homeserver == null) {
|
if (this.isLogged() == false && this.homeserver == null) {
|
||||||
throw ("No homeserver specified.");
|
throw ("No homeserver specified.");
|
||||||
}
|
}
|
||||||
if (timeout == null) timeout = syncTimeoutSec + 5;
|
if (timeout == null) timeout = (_timeoutFactor * syncTimeoutSec) + 5;
|
||||||
dynamic json;
|
dynamic json;
|
||||||
if (data is Map) data.removeWhere((k, v) => v == null);
|
if (data is Map) data.removeWhere((k, v) => v == null);
|
||||||
(!(data is String)) ? json = jsonEncode(data) : json = data;
|
(!(data is String)) ? json = jsonEncode(data) : json = data;
|
||||||
|
@ -842,6 +844,9 @@ class Client {
|
||||||
} on ArgumentError catch (exception) {
|
} on ArgumentError catch (exception) {
|
||||||
print(exception);
|
print(exception);
|
||||||
// Ignore this error
|
// Ignore this error
|
||||||
|
} on TimeoutException catch (_) {
|
||||||
|
_timeoutFactor *= 2;
|
||||||
|
rethrow;
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
print(_);
|
print(_);
|
||||||
rethrow;
|
rethrow;
|
||||||
|
@ -892,6 +897,7 @@ class Client {
|
||||||
final int hash = _syncRequest.hashCode;
|
final int hash = _syncRequest.hashCode;
|
||||||
final syncResp = await _syncRequest;
|
final syncResp = await _syncRequest;
|
||||||
if (hash != _syncRequest.hashCode) return;
|
if (hash != _syncRequest.hashCode) return;
|
||||||
|
_timeoutFactor = 1;
|
||||||
if (this.store != null) {
|
if (this.store != null) {
|
||||||
await this.store.transaction(() {
|
await this.store.transaction(() {
|
||||||
handleSync(syncResp);
|
handleSync(syncResp);
|
||||||
|
|
|
@ -114,7 +114,6 @@ class Room {
|
||||||
setSessionKey(rawSession["session_id"], rawSession);
|
setSessionKey(rawSession["session_id"], rawSession);
|
||||||
List<DeviceKeys> deviceKeys = await getUserDeviceKeys();
|
List<DeviceKeys> deviceKeys = await getUserDeviceKeys();
|
||||||
try {
|
try {
|
||||||
// TODO: Fix type '_InternalLinkedHashMap<String, dynamic>' is not a subtype of type 'Iterable<dynamic>'
|
|
||||||
await client.sendToDevice(deviceKeys, "m.room_key", rawSession);
|
await client.sendToDevice(deviceKeys, "m.room_key", rawSession);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(
|
print(
|
||||||
|
|
Loading…
Reference in a new issue