blasphem/pkg/server/websocket.go

31 lines
560 B
Go
Raw Permalink Normal View History

2022-09-25 11:42:36 -04:00
package server
import (
2022-12-21 13:22:18 -05:00
"context"
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()
2022-12-20 19:31:46 -05:00
_ = log.Debug
2022-12-21 13:22:18 -05:00
ctx, cancel := context.WithCancel(c.Request().Context())
defer cancel()
2022-12-19 19:24:01 -05:00
2022-12-21 13:22:18 -05:00
return wsapi.NewSession(s, c, conn).Go(ctx)
2022-09-25 11:42:36 -04:00
}