Awesome
Event Hooks - Meteor Smart Package
Provides hooks for various user-triggered events.
API
Currently, all API methods on the server take a userId
argument.
Hooks.onLoggedIn = function ([server: userId]) { ... }
( anywhere ) - Provide a callback to run when a user has logged inHooks.onLoggedOut = function (userId) { ... }
( anywhere ) - Provide a callback to run when a user has logged outHooks.onCreateUser = function (userId) { ... }
( server ) - Provide a callback to run when a user is createdHooks.onDeleteUser = function (userId) { ... }
( server ) - Provide a callback to run when a user is deletedHooks.onLoseFocus = function ([server: userId]) { ... }
( anywhere )* - Provide a callback to run when the window loses focus. * Opt-in through theupdateFocus
optionHooks.onGainFocus = function ([server: userId]) { ... }
( anywhere )* - Provide a callback to run when the window gains focus * Opt-in through theupdateFocus
optionHooks.onCloseSession = function ([server: userId]) { ... }
( server ) - Provide a callback to run when the window/tab is closed
Initialization
Hooks.init([options])
( client ) - Initialize the event system. Optionally provide anObject
to set the options. Put this in yourMeteor.startup
Options
Options are specified on the client side as an argument (object) in the init
method.
updateFocus
( Integer ) - Number of milliseconds to wait before checking whether the window is focused. Default is0
, meaning unless you change this, theonLoseFocus
andonGainFocus
methods won't be availabletreatCloseAsLogout
( Boolean ) - If true, treat closing the browser window as logging off (meaning that theonLoggedOut
callback is triggered in addition to theonCloseSession
). Default isfalse
How to use?
- Install meteorite
mrt add event-hooks
- Add
Hooks.init()
to yourMeteor.startup
inside of a file inside your client/ directory or inside of an if(Meteor.isClient) block.
if(Meteor.isClient){
Meteor.startup(function(){
Hooks.init();
});
}
That's it!