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.connect()
and client.disconnect()
.
The connection parameters used in the client constructor can be updated by using the Sessions API. Read more about it in the auth guide
Connection status
The connection status is available at client.connectionStatus
.
You may also listen to changes in the connection status by adding a listener to client.onConnectionStatusChange(callback, runImmediately)
. If the optional parameter runImmediately
is set to true
, the callback will be run immediately with the current connection status.
client.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.