hack to make subprotocol work
This commit is contained in:
parent
529c031c41
commit
89df01f089
2 changed files with 11 additions and 1 deletions
|
@ -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)
|
||||
|
|
10
ts/index.ts
10
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue