mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
fix UiContext.ws_prefix
This commit is contained in:
2 files changed
+7
-6
No files matched your search
@@ -13,6 +13,7 @@ const ports: Set<MessagePort> = new Set();
|
||||
interface RequestInitSharedConnPayload {
|
||||
type: 'conn';
|
||||
cookie: string;
|
||||
path: string;
|
||||
}
|
||||
interface RequestAckPayload {
|
||||
type: 'ack';
|
||||
@@ -52,12 +53,12 @@ function onMessage(payload: any) {
|
||||
}, 5000);
|
||||
}
|
||||
|
||||
function initConn(port: MessagePort, cookie: any) {
|
||||
function initConn(path: string, port: MessagePort, cookie: any) {
|
||||
ports.add(port);
|
||||
console.log('Init connection');
|
||||
lcookie = cookie.split('sid=')[1].split(';')[0];
|
||||
if (conn) return;
|
||||
const url = new URL('/websocket', location.origin);
|
||||
const url = new URL(path, location.origin);
|
||||
conn = new ReconnectingWebsocket(url.toString().replace('http', 'ws'));
|
||||
conn.onopen = () => {
|
||||
console.log('Connected');
|
||||
@@ -91,7 +92,7 @@ self.onconnect = function (e) {
|
||||
const port = e.ports[0];
|
||||
|
||||
port.addEventListener('message', (msg: { data: RequestPayload }) => {
|
||||
if (msg.data.type === 'conn') initConn(port, msg.data.cookie);
|
||||
if (msg.data.type === 'conn') initConn(msg.data.path, port, msg.data.cookie);
|
||||
if (msg.data.type === 'ack') ack[msg.data.id]?.();
|
||||
if (msg.data.type === 'unload') ports.delete(port);
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user