livekit-server-sdk 2.12.0 → 2.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/EgressClient.cjs +4 -1
- package/dist/EgressClient.cjs.map +1 -1
- package/dist/EgressClient.d.cts +6 -2
- package/dist/EgressClient.d.ts +6 -2
- package/dist/EgressClient.d.ts.map +1 -1
- package/dist/EgressClient.js +5 -1
- package/dist/EgressClient.js.map +1 -1
- package/dist/RoomServiceClient.cjs +19 -0
- package/dist/RoomServiceClient.cjs.map +1 -1
- package/dist/RoomServiceClient.d.cts +12 -0
- package/dist/RoomServiceClient.d.ts +12 -0
- package/dist/RoomServiceClient.d.ts.map +1 -1
- package/dist/RoomServiceClient.js +20 -0
- package/dist/RoomServiceClient.js.map +1 -1
- package/dist/SipClient.cjs +196 -14
- package/dist/SipClient.cjs.map +1 -1
- package/dist/SipClient.d.cts +150 -9
- package/dist/SipClient.d.ts +150 -9
- package/dist/SipClient.d.ts.map +1 -1
- package/dist/SipClient.js +200 -15
- package/dist/SipClient.js.map +1 -1
- package/dist/TwirpRPC.cjs +14 -6
- package/dist/TwirpRPC.cjs.map +1 -1
- package/dist/TwirpRPC.d.cts +7 -3
- package/dist/TwirpRPC.d.ts +7 -3
- package/dist/TwirpRPC.d.ts.map +1 -1
- package/dist/TwirpRPC.js +14 -6
- package/dist/TwirpRPC.js.map +1 -1
- package/dist/index.d.cts +1 -1
- package/package.json +2 -2
- package/src/EgressClient.ts +10 -0
- package/src/RoomServiceClient.ts +21 -0
- package/src/SipClient.ts +298 -26
- package/src/TwirpRPC.ts +37 -9
package/src/TwirpRPC.ts
CHANGED
|
@@ -9,19 +9,32 @@ const defaultPrefix = '/twirp';
|
|
|
9
9
|
|
|
10
10
|
export const livekitPackage = 'livekit';
|
|
11
11
|
export interface Rpc {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
request(
|
|
13
|
+
service: string,
|
|
14
|
+
method: string,
|
|
15
|
+
data: JsonValue,
|
|
16
|
+
headers: any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
17
|
+
timeout?: number,
|
|
18
|
+
): Promise<string>;
|
|
14
19
|
}
|
|
15
20
|
|
|
16
21
|
export class TwirpError extends Error {
|
|
17
22
|
status: number;
|
|
18
23
|
code?: string;
|
|
24
|
+
metadata?: Record<string, string>;
|
|
19
25
|
|
|
20
|
-
constructor(
|
|
26
|
+
constructor(
|
|
27
|
+
name: string,
|
|
28
|
+
message: string,
|
|
29
|
+
status: number,
|
|
30
|
+
code?: string,
|
|
31
|
+
metadata?: Record<string, string>,
|
|
32
|
+
) {
|
|
21
33
|
super(message);
|
|
22
34
|
this.name = name;
|
|
23
35
|
this.status = status;
|
|
24
36
|
this.code = code;
|
|
37
|
+
this.metadata = metadata;
|
|
25
38
|
}
|
|
26
39
|
}
|
|
27
40
|
|
|
@@ -44,24 +57,36 @@ export class TwirpRpc {
|
|
|
44
57
|
this.prefix = prefix || defaultPrefix;
|
|
45
58
|
}
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
async request(
|
|
61
|
+
service: string,
|
|
62
|
+
method: string,
|
|
63
|
+
data: any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
64
|
+
headers: any, // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
65
|
+
timeout = 60,
|
|
66
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
67
|
+
): Promise<any> {
|
|
49
68
|
const path = `${this.prefix}/${this.pkg}.${service}/${method}`;
|
|
50
69
|
const url = new URL(path, this.host);
|
|
51
|
-
|
|
52
|
-
const response = await fetch(url, {
|
|
70
|
+
const init: RequestInit = {
|
|
53
71
|
method: 'POST',
|
|
54
72
|
headers: {
|
|
55
73
|
'Content-Type': 'application/json;charset=UTF-8',
|
|
56
74
|
...headers,
|
|
57
75
|
},
|
|
58
76
|
body: JSON.stringify(data),
|
|
59
|
-
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
if (timeout) {
|
|
80
|
+
init.signal = AbortSignal.timeout(timeout * 1000);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const response = await fetch(url, init);
|
|
60
84
|
|
|
61
85
|
if (!response.ok) {
|
|
62
86
|
const isJson = response.headers.get('content-type') === 'application/json';
|
|
63
87
|
let errorMessage = 'Unknown internal error';
|
|
64
88
|
let errorCode: string | undefined = undefined;
|
|
89
|
+
let metadata: Record<string, string> | undefined = undefined;
|
|
65
90
|
try {
|
|
66
91
|
if (isJson) {
|
|
67
92
|
const parsedError = (await response.json()) as Record<string, unknown>;
|
|
@@ -71,6 +96,9 @@ export class TwirpRpc {
|
|
|
71
96
|
if ('code' in parsedError) {
|
|
72
97
|
errorCode = <string>parsedError.code;
|
|
73
98
|
}
|
|
99
|
+
if ('meta' in parsedError) {
|
|
100
|
+
metadata = <Record<string, string>>parsedError.meta;
|
|
101
|
+
}
|
|
74
102
|
} else {
|
|
75
103
|
errorMessage = await response.text();
|
|
76
104
|
}
|
|
@@ -79,7 +107,7 @@ export class TwirpRpc {
|
|
|
79
107
|
console.debug(`Error when trying to parse error message, using defaults`, e);
|
|
80
108
|
}
|
|
81
109
|
|
|
82
|
-
throw new TwirpError(response.statusText, errorMessage, response.status, errorCode);
|
|
110
|
+
throw new TwirpError(response.statusText, errorMessage, response.status, errorCode, metadata);
|
|
83
111
|
}
|
|
84
112
|
const parsedResp = (await response.json()) as Record<string, unknown>;
|
|
85
113
|
|