Skip to content

Commit

Permalink
updated WS protocol to match host document protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
robgruen committed Nov 20, 2024
1 parent 25a720b commit 69e264d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 1 addition & 3 deletions ts/packages/shell/src/renderer/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export function getWebSocketAPI(): ClientAPI {
if (globalThis.webApi === undefined) {
globalThis.webApi = webapi;

// TODO: update ws URI
let url = window.location;
createWebSocket(`ws://${url.hostname}:3000`, true).then(
createWebSocket(true).then(
(ws) => (globalThis.ws = ws),
);
}
Expand Down
10 changes: 7 additions & 3 deletions ts/packages/shell/src/renderer/src/webSocketAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,14 @@ function placeHolder(category: string, callback: any) {
}

export async function createWebSocket(
endpoint: string = "ws://localhost:8080",
autoReconnect: boolean = true,
) {
let url = window.location;
let protocol = url.protocol.toLowerCase() == "https" ? "wss" : "ws";
let port = url.hostname.toLocaleLowerCase() == "localhost" ? ":3000" : "";

const endpoint = `${protocol}://${url.hostname}${port}`

return new Promise<WebSocket | undefined>((resolve) => {
console.log(`opening web socket to ${endpoint} `);
const webSocket = new WebSocket(endpoint);
Expand Down Expand Up @@ -347,8 +352,7 @@ export async function createWebSocket(

// reconnect?
if (autoReconnect) {
let url = window.location;
createWebSocket(`ws://${url.hostname}:3000`, true).then(
createWebSocket().then(
(ws) => (globalThis.ws = ws),
);
}
Expand Down

0 comments on commit 69e264d

Please sign in to comment.