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"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"nhooyr.io/websocket"
|
"nhooyr.io/websocket"
|
||||||
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -64,6 +65,7 @@ func (self *BBSServer) subscribeHandler(w http.ResponseWriter, r *http.Request)
|
||||||
|
|
||||||
// decode subprotocol data into settings objects
|
// decode subprotocol data into settings objects
|
||||||
data := c.Subprotocol()
|
data := c.Subprotocol()
|
||||||
|
data = strings.ReplaceAll(data, ".", "=")
|
||||||
|
|
||||||
// base64 decode
|
// base64 decode
|
||||||
decoded, err := base64.StdEncoding.DecodeString(data)
|
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 += JSON.stringify(a) + ",";
|
||||||
}
|
}
|
||||||
subprotocol += "]";
|
subprotocol += "]";
|
||||||
subprotocol = btoa(subprotocol);
|
subprotocol = btoa(subprotocol).replace("=", ".");
|
||||||
|
|
||||||
// open the websocket connection with settings as subprotocol
|
// open the websocket connection with settings as subprotocol
|
||||||
const wsProto = location.protocol == "https:" ? "wss" : "ws";
|
const wsProto = location.protocol == "https:" ? "wss" : "ws";
|
||||||
_conn = new WebSocket(`${wsProto}://${location.host}/subscribe`, subprotocol);
|
_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);
|
_("websocket", _conn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue