connect method
Connects NCEngine and starts accepting session events on success.
Implementation
Future<int> connect(
ConnectParams params, {
OperationHandler<String>? handler,
}) async {
final generation = ++_connectionGeneration;
_clearSessionState(clearCurrentUser: true);
_acceptingEngineEvents = false;
notifyListeners();
NCEngine.engine.setModuleName("nexconnchatuiflutter", "26.2.8");
final code = await NCEngine.connect(params, (userId, error) {
if (generation != _connectionGeneration) {
return;
}
final errorCode = error?.code ?? 0;
final isConnected = errorCode == 0 || errorCode == 34001;
if (isConnected) {
if (userId != null && userId.isNotEmpty) {
_currentUserId = userId;
}
_acceptingEngineEvents = true;
notifyListeners();
} else {
_acceptingEngineEvents = false;
}
handler?.call(userId, error);
if (isConnected) {
unawaited(refreshAppSettings());
}
});
if (generation == _connectionGeneration) {
final isConnectAccepted = code == 0 || code == 34001;
if (isConnectAccepted && !_acceptingEngineEvents) {
_acceptingEngineEvents = true;
notifyListeners();
} else if (!isConnectAccepted) {
_acceptingEngineEvents = false;
}
}
return code;
}