Websocket Broadcast from ACE Command


#1

I checked this example Broadcast from anywhere but i did not get it to work.

This worked from a normal http Controller.

But if i try to use this in a Command Class (App->Command->MyClass.js)
It does’nt work.

Problem is, that broadcast is every time null!

Does anyone have a tip for me what I’m doing wrong?

Here is my Class:

const _ = require('lodash')
const Ws = use('Ws')


class MyClass extends Command {
  static get signature () {
    return `
    MyClass functions
    { --test: test }
    `
  }

  static get description () {
    return 'MyClass functions'
  }

  async handle (args, options) {
    console.time('testTimer')
    this.info(`  ${this.icon('info')} Command: MyClass...`)

    let value = _.keys(_.pickBy(options, _.isBoolean))
    switch (value[0]) {
      // test arg
      case 'test':
          this.info(`${this.icon('info')} Command with flag: --test`)

          Ws.getChannel('chat').topic('chat').broadcast('message', {
            username: ' - Servernachricht',
            text: 'Auswertung startet'
          })

          break
      default:
          this.info(`  ${this.icon('info')} Command with wrong options.`)
      break
      
    } // of switch
    this.info('----------- ende / finish -----------')

    console.timeEnd('testTimer')
  } // of handle
} // of class


#2

same issue but I found it work in http controller.