0

I wanted to ask about the Firebase Detecting Connection State, specifically the Sample Presence App code on that page. What happens if the same user signs in/out from multiple devices?

I could not see any explanation about the below quote in the documentation:

"since I can connect from multiple devices, we store each connection instance separately"

In the sample code on that page it really never explains the situation where the same user is signed in/out from multiple devices.

The docs seem to assume the reader could figure this out by themselves.

I'm looking for an additional explanation about this "make-believe" scenario, where a user's presence is handled in a chat app, for example the user is signed in/out on multiple devices, and how in the chat app to detect the correct user's presence

JNYRanger
  • 6,829
  • 12
  • 53
  • 81
Tord Larsen
  • 2,670
  • 8
  • 33
  • 76
  • 1
    The documentation you link contains a [sample presence app](https://firebase.google.com/docs/database/android/offline-capabilities#section-sample) that handles multiple connections per user. It tracks the potential multiple connections for each user by keeping a "connection ID" (really just a push ID) as long as the connection exists. This has been used by many Firebase developers to implement a connection system. If you're having problems getting it to work for you, post the [minimal code that reproduces where you are stuck](http://stackoverflow.com/help/mcve). – Frank van Puffelen Jul 06 '17 at 17:03
  • +1 for "really just a push ID" . Still even do Firebase doc and the Codelabs are awesome I always want more examples, dunno why!? :) – Tord Larsen Jul 06 '17 at 17:42
  • In this case there is an example at the bottom of the same documentation page. – Frank van Puffelen Jul 06 '17 at 17:50

1 Answers1

0

The connection state tracked by the .info/connected node indicates whether or not the app has an open connection to the database. It doesn't know anything about the authenticated user that might be using the app, nor does it know anything about that user with respect to multiple devices. It's just the connection state of the local device that it's tracking.

If you want to track the same authenticated user across multiple devices, you'll need to find a way to manage that yourself. The SDK isn't going to give you an easy solution.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441