hack to make subprotocol work

This commit is contained in:
Iris Lightshard 2024-05-19 14:56:25 -06:00
parent 529c031c41
commit 89df01f089
Signed by: Iris Lightshard
GPG key ID: 688407174966CAF3
2 changed files with 11 additions and 1 deletions

View file

@ -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)

View file

@ -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);
}
}