Not work broadcast using websockets


#1

already perform the whole configuration process of websockets in adonisjs, already work, my problem is when the server perform the broadcast event this does not notify the other users connected.

Channel configuration click on the top of the image and the code on the client side on the bottom of the image, I get the token and connect, then I subscribe to the click channel, and when I click on a button execute emit(“greeting”) but the on(‘message’) never executes

Thanks, I hope your answers


#2

The code looks fine to me. Are you sure that other users are connected and subscribed to this channel?


#3

Yes sure, one cliente be in firefox other in chrome, only the emit works fine, but i need a broadcast :cry:, another thing I did was save the socket id in database for later use emitTo but it does not work


#4

Weird. Just to make sure that you understand how broadcast works.

It will send messages to everyone else except the socket which originated the message.

Finally, if you can share a Github repo, that I can use to reproduce the issue.


#5

Ok thanks, client repository:


Server repository:


#6

Hello again, when add the following code in the file server.js
cluster

The broadcast not work but when remove this code the broadcast work find,I do not understand why adding the cluster does not work


#7

It happens to me the same as @MoisesL27, i need help


#8

This isn’t really an Adonis issue. It’s a result of using clustering.

According to the socket.io docs, you must provide a means of communication between processes if you want to be able to broadcast when clustering.

See: https://socket.io/docs/using-multiple-nodes/#Using-Node-JS-Cluster

if you want to broadcast events to everyone (or even everyone in a certain room) you’ll need some way of passing messages between processes or computers.

Adonis could, perhaps, provide a default adapter that writes to a DB table, but the redis solution they show in those docs is probably a lot better option, and adonis shouldn’t be making assumptions that redis is available, nor creating DB tables for things not everyone is using, etc. So really this should probably just come down to a documentation change, not a code change. As it only applies if using sockets, AND clustering.


#9

Hi, thanks for your help, I will read the link of the documentation, thanks :slight_smile: