connect method
Implementation
@nonVirtual
Future<void> connect() async {
if (protocolState == KuzzleProtocolState.offline) {
abortConnection = false;
protocolState = KuzzleProtocolState.connecting;
}
var attempt = 0;
do {
if (abortConnection) {
protocolState = KuzzleProtocolState.offline;
throw KuzzleError(
'Unable to connect to kuzzle server at ${uri.toString()}: Connection aborted.');
}
try {
await protocolConnect();
_clientConnected();
return;
// ignore: avoid_catches_without_on_clauses
} catch (e) {
attempt += reconnectionAttempts > -1 ? 1 : 0;
if (!autoReconnect ||
reconnectionAttempts > -1 && attempt >= reconnectionAttempts) {
protocolState = KuzzleProtocolState.offline;
rethrow;
}
await Future.delayed(reconnectionDelay);
}
} while (autoReconnect &&
(reconnectionAttempts == -1 || attempt < reconnectionAttempts));
}