X-Git-Url: https://code.octet-stream.net/broadcaster/blobdiff_plain/7423c6c97eb5d6dc063e7185c50137bbb5e25a23..7b615b3c71825b5b229b78509a16db37e1d3f38d:/broadcaster-server/command.go?ds=sidebyside diff --git a/broadcaster-server/command.go b/broadcaster-server/command.go deleted file mode 100644 index 346e842..0000000 --- a/broadcaster-server/command.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -import ( - "code.octet-stream.net/broadcaster/internal/protocol" - "encoding/json" - "golang.org/x/net/websocket" - "sync" -) - -type CommandRouter struct { - connsMutex sync.Mutex - conns map[int]*websocket.Conn -} - -var commandRouter CommandRouter - -func InitCommandRouter() { - commandRouter.conns = make(map[int]*websocket.Conn) -} - -func (c *CommandRouter) AddWebsocket(radioId int, ws *websocket.Conn) { - c.connsMutex.Lock() - defer c.connsMutex.Unlock() - c.conns[radioId] = ws -} - -func (c *CommandRouter) RemoveWebsocket(ws *websocket.Conn) { - c.connsMutex.Lock() - defer c.connsMutex.Unlock() - key := -1 - for k, v := range c.conns { - if v == ws { - key = k - } - } - if key != -1 { - delete(c.conns, key) - } - -} - -func (c *CommandRouter) Stop(radioId int) { - c.connsMutex.Lock() - defer c.connsMutex.Unlock() - ws := c.conns[radioId] - if ws != nil { - stop := protocol.StopMessage{ - T: protocol.StopType, - } - msg, _ := json.Marshal(stop) - ws.Write(msg) - } -}