Skip to content

Commit 69e264d

Browse files
committed
updated WS protocol to match host document protocol
1 parent 25a720b commit 69e264d

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

ts/packages/shell/src/renderer/src/main.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ export function getWebSocketAPI(): ClientAPI {
2929
if (globalThis.webApi === undefined) {
3030
globalThis.webApi = webapi;
3131

32-
// TODO: update ws URI
33-
let url = window.location;
34-
createWebSocket(`ws://${url.hostname}:3000`, true).then(
32+
createWebSocket(true).then(
3533
(ws) => (globalThis.ws = ws),
3634
);
3735
}

ts/packages/shell/src/renderer/src/webSocketAPI.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,14 @@ function placeHolder(category: string, callback: any) {
230230
}
231231

232232
export async function createWebSocket(
233-
endpoint: string = "ws://localhost:8080",
234233
autoReconnect: boolean = true,
235234
) {
235+
let url = window.location;
236+
let protocol = url.protocol.toLowerCase() == "https" ? "wss" : "ws";
237+
let port = url.hostname.toLocaleLowerCase() == "localhost" ? ":3000" : "";
238+
239+
const endpoint = `${protocol}://${url.hostname}${port}`
240+
236241
return new Promise<WebSocket | undefined>((resolve) => {
237242
console.log(`opening web socket to ${endpoint} `);
238243
const webSocket = new WebSocket(endpoint);
@@ -347,8 +352,7 @@ export async function createWebSocket(
347352

348353
// reconnect?
349354
if (autoReconnect) {
350-
let url = window.location;
351-
createWebSocket(`ws://${url.hostname}:3000`, true).then(
355+
createWebSocket().then(
352356
(ws) => (globalThis.ws = ws),
353357
);
354358
}

0 commit comments

Comments
 (0)