updated docs, minor changes

This commit is contained in:
2025-12-08 09:36:40 +01:00
parent 0c7909a701
commit 709abb30fa
5 changed files with 30 additions and 46 deletions

View File

@@ -68,7 +68,7 @@ func (wsg *WebsocketGateway) handleSync(w http.ResponseWriter, r *http.Request)
_ = wsg.sendWebsocketResponse(conn, GatewayAck{Status: "connected", Type: "mod"})
wsg.registry.FlushChannelWithSender(mhs.ChannelID, wsg.flush)
wsg.logger.Info("Mod connected via Websocket.", "remote", conn.RemoteAddr().String())
wsg.logger.Info("Mod connected via Websocket.", "remote", conn.RemoteAddr().String(), "id", mhs.ServerID)
go wsg.read(conn, "mod", mhs.ChannelID)
case "bot":
@@ -78,12 +78,12 @@ func (wsg *WebsocketGateway) handleSync(w http.ResponseWriter, r *http.Request)
return
}
if bhs.ChannelId == "" {
if bhs.BotID == "" {
wsg.sendWebsocketError(conn, "Malformed bot handshake.", 400, true)
return
}
if !wsg.registerConn(conn, "bot", bhs.ChannelId, "") {
if !wsg.registerConn(conn, "bot", "", "") {
wsg.sendWebsocketError(conn, "Bot already connected.", 409, true)
return
}
@@ -91,8 +91,8 @@ func (wsg *WebsocketGateway) handleSync(w http.ResponseWriter, r *http.Request)
_ = wsg.sendWebsocketResponse(conn, GatewayAck{Status: "connected", Type: "bot"})
wsg.registry.FlushAllToBotWithSender(wsg.flush)
wsg.logger.Info("Bot connected via Websocket.", "remote", conn.RemoteAddr().String())
go wsg.read(conn, "bot", bhs.ChannelId)
wsg.logger.Info("Bot connected via Websocket.", "remote", conn.RemoteAddr().String(), "id", bhs.BotID)
go wsg.read(conn, "bot", "")
default:
wsg.sendWebsocketError(conn, "Unknown handshake.", 400, true)

View File

@@ -106,5 +106,5 @@ type ModHandshake struct {
}
type BotHandshake struct {
ChannelId string `json:"channel_id"`
BotID string `json:"bot_id"`
}

View File

@@ -128,13 +128,10 @@ func (wsg *WebsocketGateway) read(conn *websocket.Conn, _type, channelId string)
ForwardedAt: time.Now().UTC(),
}
delivered, queued, err := wsg.registry.Send(out.ID, out, func(c *websocket.Conn, m GatewayMessageOut) error {
_ = c.SetWriteDeadline(time.Now().Add(5 * time.Second))
return c.WriteJSON(m)
})
delivered, queued, err := wsg.registry.Send(outID, out, wsg.flush)
if err != nil {
wsg.logger.Error("registry send error", "err", err)
wsg.logger.Error("Registry queue/delivery error.", "remote", conn.RemoteAddr().String(), "err", err)
_ = wsg.sendWebsocketResponse(conn, GatewayAck{Status: "failed", Type: message.Type})
continue
}