hack to make subprotocol work
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE----- iHUEABYKAB0WIQT/foVVmI9pK13hPWFohAcXSWbK8wUCZkpneQAKCRBohAcXSWbK 8w6xAQDXW1/9HyXx0j5q56e2UgfNCcMC8PGI+jEyeGbt8LzwJwD/fzYUgPTxZLqB eL99t0424Zea/6qBgZCILubAmjZzkgQ= =3mvB -----END PGP SIGNATURE-----
2 files changed,
11 insertions(+),
1 deletions(-)
M
server/server.go
→
server/server.go
@@ -13,6 +13,7 @@ "io/ioutil"
"log" "net/http" "nhooyr.io/websocket" + "strings" "sync" "time" )@@ -64,6 +65,7 @@ }
// decode subprotocol data into settings objects data := c.Subprotocol() + data = strings.ReplaceAll(data, ".", "=") // base64 decode decoded, err := base64.StdEncoding.DecodeString(data)
M
ts/index.ts
→
ts/index.ts
@@ -211,11 +211,19 @@ for (let a of settings.adapters) {
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); } }