Closed gultyayev closed 5 years ago
Did you figure out how to iterate the clients and send a message? When I traverse the clients with forEach as seen in the docs, the individual client entries have no send property. Not sure where to look for the client spec.
For anyone who end up here, the object is a Set.
let clientsSet = wsInstance.getWss().clients
let clientsValues = clientsSet.values()
for(let i=0; i < clientsSet.size; i++) {
console.log(clientsValues.next().value)
}
run wsInstance.getWss().clients ,you will get a set,not object, so you should do : for (let client of wsInstance.getWss().clients){ // handle your job code //like this: client.send('this is a global message') }
I wanted to look at all the clients at the moment on my WebSocket, but instead of some adequate array I've received some object which even cannot fit in terminal.
Here is my code
Here is what I've got instead of my "clients"