Cloud Firestore Equivalent to Realtime Database “.

2020-04-10 03:29发布

I have started migrating over from Firebase Realtime Database to Cloud Firestore. I need a way for the app to be alerted to when Firestore's connection state changes, online to offline and vice versa. For clarity, I do not need this written into the Database for other instances of the App to see. This is purely for providing an Indicator to the User that their connection has dropped. In Realtime database I could achieve this by attaching a value listener to the ".info/connected" reference. But It doesn't seem that I can do this in Firestore.

Alternatively, if there is "Pending Updates" value I could listen to in the Firestore Module, that responds to there being data held Offline pending Database sync that would also work.

1条回答
冷血范
2楼-- · 2020-04-10 04:05

There is no equivalent to Firebase Realtime Database's .info/connected in Cloud Firestore. It's in fact one of the use-cases that is explicitly called on in the blog post comparing Realtime Database and Firestore:

The Realtime Database has native support for presence -- that is, being able to tell when a user has come online or gone offline. While we do have a solution for Cloud Firestore, it's not quite as elegant.

The Firestore documentation describes a possible implementation of a presence system by combining Realtime Database and Firestore.

查看更多
登录 后发表回答