From 89df01f089e2e00fa6fbcc5fa147074cce4e81a2 Mon Sep 17 00:00:00 2001 From: Iris Lightshard Date: Sun, 19 May 2024 14:56:25 -0600 Subject: [PATCH] hack to make subprotocol work --- server/server.go | 2 ++ ts/index.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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); } }