From 877ea338ad75731f96b51810d10dd1aa81553791 Mon Sep 17 00:00:00 2001 From: wisplite Date: Wed, 8 Apr 2026 09:26:30 -0500 Subject: [PATCH] add new client handler to isolate websockets from engine --- reactivity/client.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 reactivity/client.go diff --git a/reactivity/client.go b/reactivity/client.go new file mode 100644 index 0000000..662b353 --- /dev/null +++ b/reactivity/client.go @@ -0,0 +1,30 @@ +package reactivity + +import ( + "log/slog" + + "github.com/google/uuid" + "github.com/gorilla/websocket" +) + +type Client struct { + ID string + Conn *websocket.Conn + Send chan []byte +} + +func NewClient(conn *websocket.Conn) *Client { + return &Client{ID: uuid.NewString(), Conn: conn, Send: make(chan []byte, 256)} +} + +func (c *Client) WritePump() { + defer c.Conn.Close() + + for message := range c.Send { + err := c.Conn.WriteMessage(websocket.TextMessage, message) + if err != nil { + slog.Error("Client write pump failed", "error", err, "client", c.ID) + return + } + } +}