Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. 'use strict'
  2.  
  3. /*
  4. * Applicaiton-Nofifier
  5. *
  6. * (c) Vladyslav Gaysyuk <mikield@icloud.com>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11.  
  12. const { ServiceProvider } = require('@adonisjs/fold')
  13.  
  14. class NotificationServiceProvider extends ServiceProvider {
  15. /**
  16. * The register method called by ioc container
  17. * as a life-cycle method
  18. *
  19. * @method register
  20. *
  21. * @return {void}
  22. */
  23. register () {
  24. const Broadcaster = this.app.use('Broadcaster')
  25. this.app.bind('Notification', (app) => {
  26. return class Notify {
  27. constructor(){
  28. this.Broadcaster = Broadcaster
  29. this.Notification = this.Broadcaster.event('notification')
  30. }
  31.  
  32. to(user){
  33. this.Notification.into('private-user-state.'+user.id)
  34. return this
  35. }
  36.  
  37. with(data){
  38. this.Notification.with(data)
  39. return this
  40. }
  41.  
  42. withError(error){
  43. this.Notification.with({error})
  44. return this
  45. }
  46.  
  47. send(){
  48. this.Notification.broadcast()
  49. }
  50. }
  51. })
  52. }
  53. }
  54.  
  55. module.exports = NotificationServiceProvider
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement