You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the documentation is writed that with getWss() we can get all clients. But it is not explained how. From the method i get a long object, and i don't know how can i make broadcasting, so messege is send to all clients that are connected to my websocket.
Also in the documentation for -- wsInstance.getWss() --is written:
Note that this list will include all clients, not just those for a specific route - this means that it's often not a good idea to use this for broadcasts, for example.
But the getWss() method is the only one that is pointed to some broadcasting. If it is not good idea then what should we use ?
The text was updated successfully, but these errors were encountered:
When a connection is made, I'd suggest storing the ws parameter in an array. To broadcast, just forEach through them and use ws.send to give each client the data you want to broadcast.
varconnections=[]app.ws("/your/ws/path/here",(ws,res)=>{connections.push(ws)//whatever other stuff here, you could also have it be an object storing stuff about the ws that contains it.})functionbroadcast(message){connections.forEach((ws)=>{//if the connections are objects with info use something like ws.ws.send()ws.send(message)})}
In the documentation is writed that with getWss() we can get all clients. But it is not explained how. From the method i get a long object, and i don't know how can i make broadcasting, so messege is send to all clients that are connected to my websocket.
Also in the documentation for -- wsInstance.getWss() --is written:
Note that this list will include all clients, not just those for a specific route - this means that it's often not a good idea to use this for broadcasts, for example.
But the getWss() method is the only one that is pointed to some broadcasting. If it is not good idea then what should we use ?
The text was updated successfully, but these errors were encountered: