Websocket + Http controller

I can’t broadcast my http controller :

const Ws = use('Ws')

class AppController {

	async index({ view }){
		const alert = Ws.getChannel('alert')
		const topic = alert.topic('alert')
		if(topic){
			let ok = topic.broadcastToAll('message', 'ok')
			console.log(ok)
		}
		return view.render('app.index')
	}

}

Console.log(ok) is undefined

AlertController.js :

class AlertController {
  constructor ({ socket, request }) {
    this.socket = socket
    this.request = request
  }
  onMessage (message) {
    this.socket.emit('message', message)
  }
}

Start/Socket.js :

Ws.channel('alert', 'AlertController').middleware(['auth'])

Start/wsKernel.js :

const globalMiddleware = [
	'Adonis/Middleware/Session',
	'Adonis/Middleware/AuthInit'
]

const namedMiddleware = {
	auth: 'Adonis/Middleware/Auth'
}

Ws
  .registerGlobal(globalMiddleware)
  .registerNamed(namedMiddleware)

Thanks

1 Like

broadcastToAll() is not returning anything :slight_smile:
It’s just broadcasting to everywhere

You have server to server setup?