# #@ = window @addEventListener "mousemove", _.throttle(goActive, 777), false @addEventListener "mousedown", _.throttle(goActive, 777), false @addEventListener "keypress", _.throttle(goActive, 777), false @addEventListener "DOMMouseScroll", _.throttle(goActive, 777), false @addEventListener "mouse wheel", _.throttle(goActive, 777), false @addEventListener "touchmove", _.throttle(goActive, 777), false @addEventListener "MSPointerMove", _.throttle(goActive, 777), false
throttle
built-in underscore function reduces the number of calls to the goActive
function, the function will be called no more than once per # setVisibilitychange = -> if document.hidden # "" goInactive() else # " " goActive() document.addEventListener "visibilitychange", setVisibilitychange, false
# Meteor.setTimeout goInactive, 60000
goInactive
function sets the user status "Away". # Meteor.onConnection (connection) -> connectionId = connection.id connection.onClose () -> Meteor.users.update connection: connectionId , '$set': 'profile.online': false 'profile.idle': false
connectionId
used above: # Accounts.validateLoginAttempt (attempt) -> if !attempt.error and attempt.user Meteor.users.update _id: attempt.user._id , '$set': connection: attempt.connection.id 'profile.online': true 'profile.idle': false 'profile.location.ip': attempt.connection.clientAddress 'profile.lastLogin': new Date() return if !attempt.error and attempt.user then true else false
Source: https://habr.com/ru/post/254031/
All Articles