From 574fdfecaac157884d821264bfaeb991820419d3 Mon Sep 17 00:00:00 2001 From: "Alexander \"PapaTutuWawa" Date: Sat, 11 Mar 2023 18:54:36 +0100 Subject: [PATCH] feat(core): Merge connect and connectAwaitable --- example/lib/main.dart | 10 +++++----- packages/moxxmpp/lib/src/connection.dart | 12 +++++++++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/example/lib/main.dart b/example/lib/main.dart index 3a3bb48..6b304d2 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -117,19 +117,19 @@ class _MyHomePageState extends State { allowPlainAuth: true, ), ); - final result = await connection.connectAwaitable(); + final result = await connection.connect(waitUntilLogin: true); setState(() { - connected = result.success; + connected = result.isType() && result.get(); loading = false; }); - if (result.error != null) { - logger.severe(result.error); + if (result.isType()) { + logger.severe(result.get()); if (context.mounted) { showDialog( context: context, builder: (_) => AlertDialog( title: const Text('Error'), - content: Text(result.error.toString()), + content: Text(result.get().toString()), ), ); } diff --git a/packages/moxxmpp/lib/src/connection.dart b/packages/moxxmpp/lib/src/connection.dart index 2cf828f..bd70256 100644 --- a/packages/moxxmpp/lib/src/connection.dart +++ b/packages/moxxmpp/lib/src/connection.dart @@ -458,7 +458,14 @@ class XmppConnection { // The error is recoverable await _setConnectionState(XmppConnectionState.notConnected); - await _reconnectionPolicy.onFailure(); + + if (await _reconnectionPolicy.getShouldReconnect()) { + await _reconnectionPolicy.onFailure(); + } else { + _log.info( + 'Not passing connection failure to reconnection policy as it indicates that we should not reconnect', + ); + } } /// Called whenever the socket creates an event @@ -1170,6 +1177,8 @@ class XmppConnection { _enableReconnectOnSuccess = enableReconnectOnSuccess; if (shouldReconnect) { await _reconnectionPolicy.setShouldReconnect(true); + } else { + await _reconnectionPolicy.setShouldReconnect(false); } await _reconnectionPolicy.reset(); @@ -1259,6 +1268,7 @@ class XmppConnection { lastResource: lastResource, shouldReconnect: shouldReconnect ?? !waitUntilLogin, waitForConnection: waitForConnection, + waitUntilLogin: waitUntilLogin, enableReconnectOnSuccess: enableReconnectOnSuccess, ); if (waitUntilLogin) {