-
Notifications
You must be signed in to change notification settings - Fork 10
Add presence detection using the firebase realtime database websocket #507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add presence detection using the firebase realtime database websocket #507
Conversation
…allow importing firebase-functions-test
FYI, I have tested this on the emulator, where it works well and is quite fast. However, if we find in production that it's too slow to respond when someone connects, we should be able to add an endpoint so the client can update the status proactively, rather than waiting for the trigger to fire. |
"$experimentId": { | ||
"$publicId": { | ||
".read": "true", | ||
".write": "true" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this make the db open to the public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes this key open to the public, but you can only access records for known IDs. Since research participants are anonymous (from an auth perspective) there is no other way.
However, I notice that I misnamed that ID. So lemme go fix that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
…nstitute/deliberate-lab-clean into raindrift/presence-detection
utils/src/participant.ts
Outdated
@@ -36,6 +36,7 @@ export interface ParticipantProfile extends ParticipantProfileBase { | |||
currentStatus: ParticipantStatus; | |||
timestamps: ProgressTimestamps; | |||
anonymousProfiles: Record<string, AnonymousProfileMetadata>; | |||
connected: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this field is added, can we make the ParticipantProfile backwards compatible on the frontend (i.e., if reading in previously stored experiments) by adjusting the snapshot listeners in ParticipantService, ExperimentManager, and CohortService (if field is meant to be included in ParticipantProfile, not just ParticipantProfileExtended - see other comment)? You'll notice we did this already with agentConfig
field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh good point! I wasn't considering backward compatibility at all.
utils/src/participant.ts
Outdated
@@ -36,6 +36,7 @@ export interface ParticipantProfile extends ParticipantProfileBase { | |||
currentStatus: ParticipantStatus; | |||
timestamps: ProgressTimestamps; | |||
anonymousProfiles: Record<string, AnonymousProfileMetadata>; | |||
connected: boolean; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this new field intentionally under ParticipantProfile (all participants have access to other participants' connected status), or should it be under ParticipantProfileExtended (only experimenters or the current participant has access to the participant's status)? My understanding is that it might be more appropriate under the latter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't intentionally there, but I think it needs to be there. With this change, isActiveParticipant
depends on the connected
property, and it's used in a bunch of the participant views.
…rticipants are now always online
Ok, updated to make the connected property optional. Also now makes sense for agent participants. Previously it would show them as always offline. I guess this is technically true in a way, but not useful. Now it will show them as always online instead. |
Fixes #506
With this PR, whether a user has their browser window open and connected is reflected in the UI, and the
connected
property on their participant record. It allows the experimenter to know if the participant is still present, which is important for experiments that involve participants interacting with one another.This works by using the firebase rtdb's existing presence functionality, and a cloud function that mirrors the user's state into firestore.