Skip to content
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

User presence #51

Open
ndarilek opened this issue Jul 16, 2014 · 3 comments
Open

User presence #51

ndarilek opened this issue Jul 16, 2014 · 3 comments

Comments

@ndarilek
Copy link

I think that knowing whether a user is online or has been recently active is useful, even for an offline-first framework. I'm currently working on an app which should behave differently if multiple users are online and can chat, interact with each others' data, etc. I can think of two ways to accomplish this:

  • Create an API endpoint that gets pinged on a setTimeout, perhaps with a 1-minute long-poll and a cancellation of user presence after, say, 2 minutes of inactivity. I don't like this very much because it can be killed by over-eager proxies and is noisy, but perhaps the packets are small enough that the noise would be insignificant.
  • Using the CouchDB _sessions database and monitoring its changes feed. I don't know much about _sessions but it looks like the default session timeout is 10 minutes, so I suppose this might introduce a slight delay between a user disconnecting and being reported as offline. I don't know whether _sessions tracks time of last access, and the fact that a user keeps hitting the various changes feeds might make it possible to reduce the session timeout to provide faster feedback. Since Hoodie users hit changes feeds more frequently, it might be possible to have a 2-minute session timeout and react within a minute or so of user disconnect.

I'd like the following functionality:

  • Query for a list of online users, perhaps with pagination once that is implemented.
  • Query whether a specific user is online.
  • Receive events when users connect or disconnect.

Perhaps at some point we'd like mechanisms for filtering users' views of presence when some sort of user groups functionality lands. But I'd be happy if an initial version provided query/list/event functionality.

@davidpfahler
Copy link

@ndarilek I know that most modern browsers have window.navigator.onLine. What you want is something different, though, right? You'd like to know the online status of every user of your hoodie service, so each user can know if another user is online? Do I understand that correctly?

@ndarilek
Copy link
Author

Right. Since Hoodie generally has you connected to CouchDB's changes
feeds while you're online, I'd like a plugin to report whether the user
is actively consuming these feeds or connected to the server.

After further research, I realized that _sessions wasn't a database, but
an API endpoint. I'm perpetually confused by Couch's dropping of
everything administrative into a single bucket, so you have _users which
is a database, but _all_dbs and _sessions which are API endpoints.

I'm thinking about perhaps a socket.io plugin that simply tracks
connections/disconnections and records them in a presence
database--using a database so multiple servers can communicate presence.
I'll probably build that when I reach the stage of my project that needs
presence, assuming someone hasn't beaten me to it.

@davidpfahler
Copy link

That would certainly make for an interesting plugin. I'm working on a plugin myself right now, so keep me posted ad let me know if I can help you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants