From fbcdee790f629967d30c2c1272f5d82f1205e04a Mon Sep 17 00:00:00 2001 From: "M.R. Sopacua" <144725145+msopacua@users.noreply.github.com> Date: Thu, 2 May 2024 11:31:09 +0200 Subject: [PATCH] chore: simplify regex - We already do toLowerCase(), so don't need i flag. - We're not using the http bit, so no need to capture it. - If there's an s, append it, if not don't. This is the same as just replacing http with ws: [http]:// -> [ws]:// [http]s:// -> [ws]s:// [http]x:// -> [ws]x:// -> error. Is ok. [http]sx:// -> [ws]sx:// -> error in both. Is ok. - We don't want to replace protocols that do not start with http, such as git+https, so we can anchor at string start and leave out the g flag. Much simpler -:) --- src/packages/LiveClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/packages/LiveClient.ts b/src/packages/LiveClient.ts index d1353cb1..675699d7 100644 --- a/src/packages/LiveClient.ts +++ b/src/packages/LiveClient.ts @@ -27,7 +27,7 @@ export class LiveClient extends AbstractWsClient { super(key, options); const url = new URL(endpoint, this.baseUrl); - url.protocol = url.protocol.toLowerCase().replace(/(http)(s)?/gi, "ws$2"); + url.protocol = url.protocol.toLowerCase().replace(/^http/, "ws"); appendSearchParams(url.searchParams, this.transcriptionOptions); this._socket = new w3cwebsocket(url.toString(), ["token", this.key]);