From 7b9c09e2360ed666bbc74d48387dd9c9c1276710 Mon Sep 17 00:00:00 2001 From: Luke Oliff Date: Thu, 16 Nov 2023 15:10:52 +0000 Subject: [PATCH] fix: a wild fix for this has appeared (#200) --- src/lib/helpers.ts | 1 + src/packages/LiveClient.ts | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lib/helpers.ts b/src/lib/helpers.ts index 7e8e65ee..de979566 100644 --- a/src/lib/helpers.ts +++ b/src/lib/helpers.ts @@ -8,6 +8,7 @@ export function stripTrailingSlash(url: string): string { } export const isBrowser = () => typeof window !== "undefined"; +export const isServer = () => typeof process !== "undefined"; export function applySettingDefaults( options: DeepgramClientOptions, diff --git a/src/packages/LiveClient.ts b/src/packages/LiveClient.ts index 12501c15..cda1d241 100644 --- a/src/packages/LiveClient.ts +++ b/src/packages/LiveClient.ts @@ -1,5 +1,5 @@ import { AbstractWsClient } from "./AbstractWsClient"; -import { appendSearchParams, isBrowser } from "../lib/helpers"; +import { appendSearchParams, isServer } from "../lib/helpers"; import { DeepgramError } from "../lib/errors"; import { DEFAULT_OPTIONS } from "../lib/constants"; import { LiveConnectionState, LiveTranscriptionEvents } from "../lib/enums"; @@ -28,19 +28,15 @@ export class LiveClient extends AbstractWsClient { url.protocol = url.protocol.toLowerCase().replace(/(http)(s)?/gi, "ws$2"); appendSearchParams(url.searchParams, this.transcriptionOptions); - try { + if (isServer()) { this._socket = new WebSocket(url.toString(), { headers: { Authorization: `token ${this.key}`, ...this.options?.global?.headers, }, }); - } catch (e) { - if (e instanceof SyntaxError) { - this._socket = new WebSocket(url.toString(), ["token", this.key]); - } else { - throw e; // let others bubble up - } + } else { + this._socket = new WebSocket(url.toString(), ["token", this.key]); } this._socket.onopen = () => {