diff --git a/server/server.go b/server/server.go index 2f2bd17..4c4b0d2 100644 --- a/server/server.go +++ b/server/server.go @@ -13,6 +13,7 @@ import ( "log" "net/http" "nhooyr.io/websocket" + "strings" "sync" "time" ) @@ -64,6 +65,7 @@ func (self *BBSServer) subscribeHandler(w http.ResponseWriter, r *http.Request) // decode subprotocol data into settings objects data := c.Subprotocol() + data = strings.ReplaceAll(data, ".", "=") // base64 decode decoded, err := base64.StdEncoding.DecodeString(data) diff --git a/ts/index.ts b/ts/index.ts index 62650f0..a720c95 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -211,11 +211,19 @@ function connect() { subprotocol += JSON.stringify(a) + ","; } subprotocol += "]"; - subprotocol = btoa(subprotocol); + subprotocol = btoa(subprotocol).replace("=", "."); // open the websocket connection with settings as subprotocol const wsProto = location.protocol == "https:" ? "wss" : "ws"; _conn = new WebSocket(`${wsProto}://${location.host}/subscribe`, subprotocol); + _conn.addEventListener("open", (e: any) => { + console.log("websocket connection opened"); + console.log(JSON.stringify(e)); + }); + _conn.addEventListener("error", (e: any) => { + console.log("websocket connection error"); + console.log(JSON.stringify(e)); + }); _("websocket", _conn); } }