generated from deepgram/oss-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathconstants.ts
72 lines (61 loc) · 2.03 KB
/
constants.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { convertProtocolToWs, isBrowser, isBun, isNode } from "./helpers";
import { version } from "./version";
import type { DefaultNamespaceOptions, DefaultClientOptions } from "./types";
export const NODE_VERSION =
typeof process !== "undefined" && process.versions && process.versions.node
? process.versions.node
: "unknown";
export const BUN_VERSION =
typeof process !== "undefined" && process.versions && process.versions.bun
? process.versions.bun
: "unknown";
export const BROWSER_AGENT =
typeof window !== "undefined" && window.navigator && window.navigator.userAgent
? window.navigator.userAgent
: "unknown";
const getAgent = () => {
if (isNode()) {
return `node/${NODE_VERSION}`;
} else if (isBun()) {
return `bun/${BUN_VERSION}`;
} else if (isBrowser()) {
return `javascript ${BROWSER_AGENT}`;
} else {
return `unknown`;
}
};
export const DEFAULT_HEADERS = {
"Content-Type": `application/json`,
"X-Client-Info": `@deepgram/sdk; ${isBrowser() ? "browser" : "server"}; v${version}`,
"User-Agent": `@deepgram/sdk/${version} ${getAgent()}`,
};
export const DEFAULT_URL = "https://api.deepgram.com";
export const DEFAULT_AGENT_URL = "wss://agent.deepgram.com";
export const DEFAULT_GLOBAL_OPTIONS: Partial<DefaultNamespaceOptions> = {
fetch: { options: { url: DEFAULT_URL, headers: DEFAULT_HEADERS } },
websocket: {
options: { url: convertProtocolToWs(DEFAULT_URL), _nodeOnlyHeaders: DEFAULT_HEADERS },
},
};
export const DEFAULT_AGENT_OPTIONS: Partial<DefaultNamespaceOptions> = {
fetch: { options: { url: DEFAULT_URL, headers: DEFAULT_HEADERS } },
websocket: {
options: { url: DEFAULT_AGENT_URL, _nodeOnlyHeaders: DEFAULT_HEADERS },
},
};
export const DEFAULT_OPTIONS: DefaultClientOptions = {
global: DEFAULT_GLOBAL_OPTIONS,
agent: DEFAULT_AGENT_OPTIONS,
};
export enum SOCKET_STATES {
connecting = 0,
open = 1,
closing = 2,
closed = 3,
}
export enum CONNECTION_STATE {
Connecting = "connecting",
Open = "open",
Closing = "closing",
Closed = "closed",
}