Skip to main content

Monitor connection status

Register a connection status handler

Monitor changes in the connection status between the SDK and the server by registering a handler with NCEngine.addConnectionStatusHandler.

Method

Dart
static void addConnectionStatusHandler(String identifier, OnConnectionStatusChanged handler)

Parameters

ParameterTypeDescription
identifierStringA unique ID for this handler. Used to remove it later.
handlerOnConnectionStatusChangedCallback receiving a ConnectionStatusChangedEvent.

Code example

Dart
NCEngine.addConnectionStatusHandler('conn-listener', (event) {
print('Connection status changed: ${event.status}');
});

Remove the handler when it is no longer needed:

Dart
NCEngine.removeConnectionStatusHandler('conn-listener');

ConnectionStatus values

ValueDescription
ConnectionStatus.connectedConnected to the server
ConnectionStatus.connectingConnecting
ConnectionStatus.unconnectedNot connected to the server
ConnectionStatus.kickedOfflineByOtherClientKicked offline by another device
ConnectionStatus.tokenIncorrectToken is invalid or expired
ConnectionStatus.networkUnavailableNo network available
ConnectionStatus.connUserBlockedThe user has been blocked by the server
ConnectionStatus.signOutThe user has signed out
ConnectionStatus.suspendThe connection is suspended, for example when the app goes to the background
ConnectionStatus.timeoutThe connection attempt timed out
ConnectionStatus.unknownAn unknown connection status
tip

Register the connection status handler before calling NCEngine.connect() to avoid missing the initial connected event.