Fixed client websocket URL converter TLS
This commit is contained in:
@@ -15,7 +15,7 @@ interface Event {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts an API URL to a WebSocket URL.
|
* Converts an API URL to a WebSocket URL.
|
||||||
* E.g. "https://example.com/api/v1/..." -> "ws://example.com/api/v1/..."
|
* E.g. "https://example.com/api/v1/..." -> "wss://example.com/api/v1/..."
|
||||||
* or "/api/v1/..." -> "ws://example.com/api/v1/..."
|
* or "/api/v1/..." -> "ws://example.com/api/v1/..."
|
||||||
* @param apiUrl The API URL to convert
|
* @param apiUrl The API URL to convert
|
||||||
* @returns The WebSocket URL
|
* @returns The WebSocket URL
|
||||||
@@ -29,10 +29,14 @@ function toWebsocketURL(apiUrl: string) {
|
|||||||
|
|
||||||
// Split the URL to separate the protocol, host, and path
|
// Split the URL to separate the protocol, host, and path
|
||||||
const urlParts = currentURL.split("/");
|
const urlParts = currentURL.split("/");
|
||||||
|
const protocol = urlParts[0];
|
||||||
const host = urlParts[2];
|
const host = urlParts[2];
|
||||||
|
|
||||||
// Create the WebSocket URL by adding "ws://" as the protocol and the relative URL as the path
|
if (protocol === "https:") {
|
||||||
return `ws://${host}${apiUrl}`;
|
return `wss://${host}${apiUrl}`;
|
||||||
|
} else {
|
||||||
|
return `ws://${host}${apiUrl}`;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Absolute URL, e.g. "https://example.com/api/v1/..."
|
// Absolute URL, e.g. "https://example.com/api/v1/..."
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user