feat(core): Merge connect and connectAwaitable

This commit is contained in:
PapaTutuWawa 2023-03-11 18:54:36 +01:00
parent 25c778965c
commit 574fdfecaa
2 changed files with 16 additions and 6 deletions

View File

@ -117,19 +117,19 @@ class _MyHomePageState extends State<MyHomePage> {
allowPlainAuth: true,
),
);
final result = await connection.connectAwaitable();
final result = await connection.connect(waitUntilLogin: true);
setState(() {
connected = result.success;
connected = result.isType<bool>() && result.get<bool>();
loading = false;
});
if (result.error != null) {
logger.severe(result.error);
if (result.isType<XmppConnectionError>()) {
logger.severe(result.get<XmppConnectionError>());
if (context.mounted) {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: const Text('Error'),
content: Text(result.error.toString()),
content: Text(result.get<XmppConnectionError>().toString()),
),
);
}

View File

@ -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) {