Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: a wild fix for this has appeared #200

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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