How to Emit from Http controller?


Hi @virk
On Legacy version I can make socket emit from http controller like this

const chatChannel ='chat')
chatChannel.inRoom('lobby').emit('message', 'Hello world')

Does the new version support emit from http controller?
Thanks for your hard work!


I search too this…


I believe it’s in the docs


In Adonis v4.1? No I don’t think…

Just this:

const Ws = use('Ws')

class UserController {
  async register () {

But I have this error:

TypeError: Cannot read property ‘broadcast’ of null


Yup that’s the code, what else you looking for?

Regarding the null thing. If there are no subscriptions, then this returns null, so you’ll have to handle this


I had this problem and corrected it as follows:

const subscriptions = Ws.getChannel('subscriptions').topic('subscriptions')

if (subscriptions) {