Check if a user is currently online to meteor server -
i'd determine if user "online" or connected meteor server. need information before send user message, if user not connected i'd send message via email.
i know traditional web applications totally state-less definition of "online" use bit not clear since modern web frameworks rely on websocket, user supposed online if websocket open.
the question meteor include method determine if user connected or not?
summarized: yes, there such mechanism.
there example package, store active login connections of users meteor server , make them available either via own collection or part of user profile.
see: https://github.com/dburles/meteor-presence
(creates new collection, called presences)
or https://github.com/dan335/meteor-user-presence/
(creates user's profile entry, called presence. however, has collection store , update information in background)
or https://github.com/mizzao/meteor-user-status
(thanks blueren in comments)
code example (from first listed package)
meteor.onconnection(function(connection) { // console.log('connectionid: ' + connection.id); presences.insert({ _id: connection.id }); connections[connection.id] = {}; tick(connection.id); connection.onclose(function() { // console.log('connection closed: ' + connection.id); expire(connection.id); }); }); if don't want rely on packages may make use of mechanism yourself.
see: https://docs.meteor.com/api/connections.html#meteor-onconnection
Comments
Post a Comment