MWSE/internal/services/session.go

34 lines
1.1 KiB
Go

package services
import (
"git.saqut.com/saqut/mwse/internal/protocol"
"git.saqut.com/saqut/mwse/internal/ws"
)
// registerSession ports the Session service: per-connection feature flags that
// gate notifications and data relay. Defaults are already applied in
// ws.NewClient; the connect hook re-applies them for parity with the original.
//
// The SDK sends these toggles as numbers (value: 1 / value: 0), so Truthy is used
// to match the original `!!msg.value` coercion.
func registerSession(hub *ws.Hub) {
hub.OnConnect(func(c *ws.Client) { c.ResetStore() })
flag := func(name string) handler {
return func(c *ws.Client, m protocol.Message) any {
c.SetStore(name, m.Truthy("value"))
return success()
}
}
hub.Register("connection/pairinfo", flag("notifyPairInfo"))
hub.Register("connection/roominfo", flag("notifyRoomInfo"))
hub.Register("connection/packrecaive", flag("packrecaive"))
hub.Register("connection/packsending", flag("packsending"))
hub.Register("connection/reset", func(c *ws.Client, m protocol.Message) any {
c.ResetStore()
return success()
})
}