Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict'
- /*
- * Applicaiton-Nofifier
- *
- * (c) Vladyslav Gaysyuk <mikield@icloud.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- const { ServiceProvider } = require('@adonisjs/fold')
- class NotificationServiceProvider extends ServiceProvider {
- /**
- * The register method called by ioc container
- * as a life-cycle method
- *
- * @method register
- *
- * @return {void}
- */
- register () {
- const Broadcaster = this.app.use('Broadcaster')
- this.app.bind('Notification', (app) => {
- return class Notify {
- constructor(){
- this.Broadcaster = Broadcaster
- this.Notification = this.Broadcaster.event('notification')
- }
- to(user){
- this.Notification.into('private-user-state.'+user.id)
- return this
- }
- with(data){
- this.Notification.with(data)
- return this
- }
- withError(error){
- this.Notification.with({error})
- return this
- }
- send(){
- this.Notification.broadcast()
- }
- }
- })
- }
- }
- module.exports = NotificationServiceProvider
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement