Pavan Kumar
Pavan Kumar

Reputation: 1891

In FireStore how to know if client is listening to particular document

I have the following scenario.

  1. Sensor generates data every 30 seconds.
  2. Update sensor data on FireStore document.
  3. Mobile app shows the sensor data in realtime.

One problem with above steps is that lot of data writes takes place, which increases billing. I want to optimize it by changing step 2.

  1. Update sensor data on FireStore document only if mobile app is listening to realtime updates

To do this optimisation I need a way to know if app is listening to realtime update. So is there a FireStore event/callback fired when app starts/stops to listen to realtime update.

Upvotes: 0

Views: 249

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598901

There's nothing built into Firestore for this.

Two options that come to mind:

  • Use the presence solution that is documented for Firestore, which uses Firebase's Realtime Database under the hood. This gives you a way to track what users are connect to the database.
  • Build something yourself based on Firestore alone, for example by having each mobile app periodically writing a server timestamp into a known document, and then reading the most recent timestamp from the sensors and determining if that was recent enough to send updates.

Upvotes: 1

Related Questions