39 lines
758 B
Go
39 lines
758 B
Go
package server
|
|
|
|
import (
|
|
"playback-device-server/data"
|
|
|
|
"github.com/labstack/echo/v4"
|
|
"golang.org/x/net/websocket"
|
|
)
|
|
|
|
type WebSocketConnection struct {
|
|
connection *websocket.Conn
|
|
integration data.Integration
|
|
}
|
|
|
|
type WebSocket struct {
|
|
router *echo.Echo
|
|
connections []WebSocketConnection
|
|
}
|
|
|
|
func (s *WebSocket) Initializer() {
|
|
s.router.GET("/ws", s.handle)
|
|
}
|
|
|
|
func (s *WebSocket) handle(context echo.Context) error {
|
|
websocket.Handler(func(ws *websocket.Conn) {
|
|
defer ws.Close()
|
|
s.connections = append(s.connections, WebSocketConnection{
|
|
connection: ws,
|
|
integration: data.Integration{},
|
|
})
|
|
}).ServeHTTP(context.Response(), context.Request())
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *WebSocket) SetRouter(router *echo.Echo) {
|
|
s.router = router
|
|
}
|