@terrajs/mono-push
v0.3.2
Published
Mono Push module
Downloads
22
Readme
MonoPush module for Mono
Installation
npm install --save @terrajs/mono-push
Then, in your configuration file of your Mono application (example: conf/application.js
):
module.exports = {
mono: {
modules: [
'@terrajs/mono-mongodb',
'@terrajs/mono-push'
]
}
}
mono-push requires mono-mongodb, so it must be installed and declared before mono-push because modules are loaded synchronously
Configuration
mono-push will use the push
property of your configuration (example: conf/development.js
):
module.exports = {
mono: {
push: {
io: true
}
}
}
When using io: true
, mono-push requires mono-io, so it must be installed and declared (example: conf/application.js
):
module.exports = {
mono: {
modules: [
'@terrajs/mono-mongodb',
'@terrajs/mono-io',
'@terrajs/mono-push'
]
}
}
Usage
In your modules files, you can access send
helper like this:
send(event: string, query: object = {}, payload: object = {})
Example:
const { send } = require('@terrajs/mono-push')
await send('new-push', { userId: '...' }, { message: 'Welcome!' })
With conf io: true
, mono-push will emit an event to every socket connected that matches the query