kataras / go-websocket

:speaker: Deprecated. Use https://github.com/kataras/neffos instead
MIT License
59 stars 16 forks source link

Expose Emit to channels from the server #14

Closed macnibblet closed 7 years ago

macnibblet commented 7 years ago

Heya,

I have a use-case where I want to broadcast the status of something every second to a channel, but I cannot find a way to access the emitters without having an active connection. Any suggestions on how to do this ?

ghost commented 7 years ago

It's actually very easy, just create a list of WebsocketConnection and append the active connections on the OnConnection event and remove them on client.OnDisconnect. Create a function which will iterate these connections, and call their .To(websocket.Broadcast).Emit .

Be sure that you do that with channels or with locks in order to avoid any issues!