From 26bf204bd53f1c836550f4ba88c83a5d380aaf12 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Mon, 17 Feb 2020 08:15:32 +0000 Subject: [PATCH] [Client] Add timeout factor --- lib/src/client.dart | 8 +++++++- lib/src/room.dart | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index f515e54..279611e 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -142,6 +142,8 @@ class Client { /// Presences of users by a given matrix ID Map presences = {}; + int _timeoutFactor = 1; + Room getRoomByAlias(String alias) { for (int i = 0; i < rooms.length; i++) { if (rooms[i].canonicalAlias == alias) return rooms[i]; @@ -777,7 +779,7 @@ class Client { if (this.isLogged() == false && this.homeserver == null) { throw ("No homeserver specified."); } - if (timeout == null) timeout = syncTimeoutSec + 5; + if (timeout == null) timeout = (_timeoutFactor * syncTimeoutSec) + 5; dynamic json; if (data is Map) data.removeWhere((k, v) => v == null); (!(data is String)) ? json = jsonEncode(data) : json = data; @@ -842,6 +844,9 @@ class Client { } on ArgumentError catch (exception) { print(exception); // Ignore this error + } on TimeoutException catch (_) { + _timeoutFactor *= 2; + rethrow; } catch (_) { print(_); rethrow; @@ -892,6 +897,7 @@ class Client { final int hash = _syncRequest.hashCode; final syncResp = await _syncRequest; if (hash != _syncRequest.hashCode) return; + _timeoutFactor = 1; if (this.store != null) { await this.store.transaction(() { handleSync(syncResp); diff --git a/lib/src/room.dart b/lib/src/room.dart index a0c379e..debadb3 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -114,7 +114,6 @@ class Room { setSessionKey(rawSession["session_id"], rawSession); List deviceKeys = await getUserDeviceKeys(); try { - // TODO: Fix type '_InternalLinkedHashMap' is not a subtype of type 'Iterable' await client.sendToDevice(deviceKeys, "m.room_key", rawSession); } catch (e) { print(