Skip to content

Commit

Permalink
fix: a wild fix for this has appeared (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeocodes authored Nov 16, 2023
1 parent 3760848 commit 7b9c09e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/lib/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 4 additions & 8 deletions src/packages/LiveClient.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 = () => {
Expand Down

0 comments on commit 7b9c09e

Please sign in to comment.