meteor-event-hooks
meteor-event-hooks copied to clipboard
Provides hooks for various user-triggered events.
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 theupdateFocusoptionHooks.onGainFocus = function ([server: userId]) { ... }( anywhere )* - Provide a callback to run when the window gains focus * Opt-in through theupdateFocusoptionHooks.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 anObjectto 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, theonLoseFocusandonGainFocusmethods won't be availabletreatCloseAsLogout( Boolean ) - If true, treat closing the browser window as logging off (meaning that theonLoggedOutcallback is triggered in addition to theonCloseSession). Default isfalse
How to use?
- Install meteorite
mrt add event-hooks- Add
Hooks.init()to yourMeteor.startupinside 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!
