blasphem/pkg/server/websocket.go

28 lines
518 B
Go
Raw Normal View History

2022-09-25 11:42:36 -04:00
package server
import (
2022-12-19 19:24:01 -05:00
"dynatron.me/x/blasphem/pkg/wsapi"
2022-09-25 11:42:36 -04:00
"github.com/gorilla/websocket"
2022-09-30 14:37:40 -04:00
"github.com/labstack/echo/v4"
2022-12-19 19:24:01 -05:00
"github.com/rs/zerolog/log"
2022-09-25 11:42:36 -04:00
)
var upgrader = websocket.Upgrader{
2022-09-26 15:00:21 -04:00
ReadBufferSize: 1024,
2022-09-25 11:42:36 -04:00
WriteBufferSize: 1024,
}
2022-09-30 14:37:40 -04:00
func (s *Server) wsHandler(c echo.Context) error {
2022-12-19 19:24:01 -05:00
conn, err := upgrader.Upgrade(c.Response(), c.Request(), nil)
if err != nil {
return err
}
defer conn.Close()
log.Debug().Str("remote", c.Request().RemoteAddr).Msg("WS")
2022-12-20 19:05:45 -05:00
return wsapi.NewSession(s, c, conn).Go()
2022-09-25 11:42:36 -04:00
}