Search code examples
google-drive-realtime-api

Detecting connectivity with the Drive Realtime API


I want to display a message when my user is offline and disable all editing features, then reenable them when the user comes back online. Right now I'm using navigator.onLine which doesn't actually detect connectivity very well in some cases.

What's the best way to determine whether the Drive Realtime API is connected?


Solution

  • We've had success with using the Save State Change event on the realtime document to determine the offline/online status of the connection. This means that you wont know you're offline until you try to make a change to the doc, but you could add a heartbeat doc change if knowing the status is critical.

    See https://developers.google.com/drive/realtime/reference/gapi.drive.realtime.DocumentSaveStateChangedEvent for the event info.