mirror of
https://github.com/abhinavxd/libredesk.git
synced 2026-09-22 18:43:33 +00:00
caf8e7d34d
- csat - SLA - email notification templates
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
amodels "github.com/abhinavxd/artemis/internal/auth/models"
|
|
"github.com/abhinavxd/artemis/internal/ws"
|
|
wsmodels "github.com/abhinavxd/artemis/internal/ws/models"
|
|
"github.com/fasthttp/websocket"
|
|
"github.com/valyala/fasthttp"
|
|
"github.com/zerodha/fastglue"
|
|
)
|
|
|
|
func ErrHandler(ctx *fasthttp.RequestCtx, status int, reason error) {
|
|
fmt.Printf("error status %d: %s", status, reason)
|
|
}
|
|
|
|
var upgrader = websocket.FastHTTPUpgrader{
|
|
ReadBufferSize: 1024,
|
|
WriteBufferSize: 1024,
|
|
CheckOrigin: func(ctx *fasthttp.RequestCtx) bool {
|
|
return true
|
|
},
|
|
Error: ErrHandler,
|
|
}
|
|
|
|
func handleWS(r *fastglue.Request, hub *ws.Hub) error {
|
|
var (
|
|
auser = r.RequestCtx.UserValue("user").(amodels.User)
|
|
app = r.Context.(*App)
|
|
)
|
|
user, err := app.user.Get(auser.ID)
|
|
if err != nil {
|
|
return sendErrorEnvelope(r, err)
|
|
}
|
|
err = upgrader.Upgrade(r.RequestCtx, func(conn *websocket.Conn) {
|
|
c := ws.Client{
|
|
ID: user.ID,
|
|
Hub: hub,
|
|
Conn: conn,
|
|
Send: make(chan wsmodels.WSMessage, 1000),
|
|
}
|
|
hub.AddClient(&c)
|
|
go c.Listen()
|
|
c.Serve()
|
|
})
|
|
if err != nil {
|
|
app.lo.Error("error upgrading tcp connection", "error", err)
|
|
}
|
|
return nil
|
|
}
|