28 lines
563 B
Go
28 lines
563 B
Go
package services
|
|
|
|
import "github.com/gofiber/contrib/websocket"
|
|
|
|
type EventsService struct {
|
|
clients map[*websocket.Conn]interface{}
|
|
}
|
|
|
|
func NewEventsService() *EventsService {
|
|
return &EventsService{
|
|
clients: make(map[*websocket.Conn]interface{}),
|
|
}
|
|
}
|
|
|
|
func (es *EventsService) AddConnection(ws *websocket.Conn) {
|
|
es.clients[ws] = nil
|
|
}
|
|
|
|
func (es *EventsService) RemoveConnection(ws *websocket.Conn) {
|
|
delete(es.clients, ws)
|
|
}
|
|
|
|
func (es *EventsService) Broadcast(msg interface{}) {
|
|
for connection := range es.clients {
|
|
go connection.WriteJSON(msg)
|
|
}
|
|
}
|