Client
Sync engine

Sync Engine

Connecting and disconnecting

Instantiating a client will automatically connect to the server. If the connection is unexpectedly lost, the client will automatically reconnect.

You may also manually manage the state connection to the server by calling client.syncEngine.connect() and client.syncEngine.disconnect().

The connection parameters used in the client constructor can be updated by calling client.updateOptions(params). If necessary, this will disconnect and reconnect to the server with the new parameters.

Connection status

The connection status is available at client.syncEngine.connectionStatus.

You may also listen to changes in the connection status by adding a listener to client.syncEngine.onConnectionStatusChange(callback, runImmediately). If the optional parameter runImmediately is set to true, the callback will be run immediately with the current connection status.

client.syncEngine.onConnectionStatusChange((status) => {
  if (status === 'OPEN') console.log('Connected to server');
  if (status === 'CLOSED') console.log('Disconnected from server');
}, true);

Handling errors

See error and success handling for more information.