Tutorial: Get connection state

Tips and Tricks Get connection state

Webcom connection state

By default, Webcom SDK manages a cache of sent and received data in order to manage disconnections. It is possible to force connection/disconnection with methods 'goOnline()' and 'goOffline()'. In order to know the current connection status, you can subscribe to the special path .info/connected using the on() method.

const myNs = new Webcom("<your-app>");
myNs.child(".info/connected").on("value", snapshot => {
  const eventDate = Date.now();
  const connected = snapshot.val();
  if (connected) {
    // Connected to Webcom server (page loaded, goOnline call ...)
  } else {
    // Disconnected from Webcom server (network lost, goOffline called ...)

Coming soon!
In the meanwhile, refer to the Android API reference

let datasyncManager = Webcom.defaultApplication.datasyncService.createManager()
datasyncManager.subscribeToStateChange { state in
    if state.isConnected {
        print("Connected to Webcom server")
    } else {    
        print("Disconnected from Webcom server")

Warning: on application loading, connection may take some time to establish and thus the first call to the callback may pass connected=false. A short time later, as soon as the connection establishment is successfully completed, the callback is called again with connected=true.