livekit-server-sdk 2.4.0 → 2.5.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/src/SipClient.ts CHANGED
@@ -3,19 +3,28 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import {
5
5
  CreateSIPDispatchRuleRequest,
6
+ CreateSIPInboundTrunkRequest,
7
+ CreateSIPOutboundTrunkRequest,
6
8
  CreateSIPParticipantRequest,
7
9
  CreateSIPTrunkRequest,
8
10
  DeleteSIPDispatchRuleRequest,
9
11
  DeleteSIPTrunkRequest,
10
12
  ListSIPDispatchRuleRequest,
11
13
  ListSIPDispatchRuleResponse,
14
+ ListSIPInboundTrunkRequest,
15
+ ListSIPInboundTrunkResponse,
16
+ ListSIPOutboundTrunkRequest,
17
+ ListSIPOutboundTrunkResponse,
12
18
  ListSIPTrunkRequest,
13
19
  ListSIPTrunkResponse,
14
20
  SIPDispatchRule,
15
21
  SIPDispatchRuleDirect,
16
22
  SIPDispatchRuleIndividual,
17
23
  SIPDispatchRuleInfo,
24
+ SIPInboundTrunkInfo,
25
+ SIPOutboundTrunkInfo,
18
26
  SIPParticipantInfo,
27
+ SIPTransport,
19
28
  SIPTrunkInfo,
20
29
  } from '@livekit/protocol';
21
30
  import ServiceBase from './ServiceBase.js';
@@ -23,6 +32,9 @@ import { Rpc, TwirpRpc, livekitPackage } from './TwirpRPC.js';
23
32
 
24
33
  const svc = 'SIP';
25
34
 
35
+ /**
36
+ * @deprecated use CreateSipInboundTrunkOptions or CreateSipOutboundTrunkOptions
37
+ */
26
38
  export interface CreateSipTrunkOptions {
27
39
  name?: string;
28
40
  metadata?: string;
@@ -34,6 +46,19 @@ export interface CreateSipTrunkOptions {
34
46
  outbound_username?: string;
35
47
  outbound_password?: string;
36
48
  }
49
+ export interface CreateSipInboundTrunkOptions {
50
+ metadata?: string;
51
+ allowed_addresses?: string[];
52
+ allowed_numbers?: string[];
53
+ auth_username?: string;
54
+ auth_password?: string;
55
+ }
56
+ export interface CreateSipOutboundTrunkOptions {
57
+ metadata?: string;
58
+ transport: SIPTransport;
59
+ auth_username?: string;
60
+ auth_password?: string;
61
+ }
37
62
 
38
63
  export interface SipDispatchRuleDirect {
39
64
  type: 'direct';
@@ -60,6 +85,7 @@ export interface CreateSipParticipantOptions {
60
85
  participantMetadata?: string;
61
86
  dtmf?: string;
62
87
  playRingtone?: boolean;
88
+ hidePhoneNumber?: boolean;
63
89
  }
64
90
 
65
91
  /**
@@ -81,6 +107,7 @@ export class SipClient extends ServiceBase {
81
107
  /**
82
108
  * @param number phone number of the trunk
83
109
  * @param opts CreateSipTrunkOptions
110
+ * @deprecated use createSipInboundTrunk or createSipOutboundTrunk
84
111
  */
85
112
  async createSipTrunk(number: string, opts?: CreateSipTrunkOptions): Promise<SIPTrunkInfo> {
86
113
  let inboundAddresses: string[] | undefined;
@@ -118,21 +145,141 @@ export class SipClient extends ServiceBase {
118
145
  outboundPassword: outboundPassword,
119
146
  }).toJson();
120
147
 
121
- const data = await this.rpc.request(svc, 'CreateSIPTrunk', req, await this.authHeader({}));
148
+ const data = await this.rpc.request(
149
+ svc,
150
+ 'CreateSIPTrunk',
151
+ req,
152
+ await this.authHeader({}, { admin: true }),
153
+ );
122
154
  return SIPTrunkInfo.fromJson(data, { ignoreUnknownFields: true });
123
155
  }
124
156
 
157
+ /**
158
+ @param name human-readable name of the trunk
159
+ * @param numbers phone numbers of the trunk
160
+ * @param opts CreateSipTrunkOptions
161
+ */
162
+ async createSipInboundTrunk(
163
+ name: string,
164
+ numbers: string[],
165
+ opts?: CreateSipInboundTrunkOptions,
166
+ ): Promise<SIPInboundTrunkInfo> {
167
+ let allowedAddresses: string[] | undefined;
168
+ let allowedNumbers: string[] | undefined;
169
+ let authUsername: string = '';
170
+ let authPassword: string = '';
171
+ let metadata: string = '';
172
+
173
+ if (opts !== undefined) {
174
+ allowedAddresses = opts.allowed_addresses;
175
+ allowedNumbers = opts.allowed_numbers;
176
+ authUsername = opts.auth_username || '';
177
+ authPassword = opts.auth_password || '';
178
+ metadata = opts.metadata || '';
179
+ }
180
+
181
+ const req = new CreateSIPInboundTrunkRequest({
182
+ trunk: new SIPInboundTrunkInfo({
183
+ name: name,
184
+ numbers: numbers,
185
+ metadata: metadata,
186
+ allowedAddresses: allowedAddresses,
187
+ allowedNumbers: allowedNumbers,
188
+ authUsername: authUsername,
189
+ authPassword: authPassword,
190
+ }),
191
+ }).toJson();
192
+
193
+ const data = await this.rpc.request(
194
+ svc,
195
+ 'CreateSIPInboundTrunk',
196
+ req,
197
+ await this.authHeader({}, { admin: true }),
198
+ );
199
+ return SIPInboundTrunkInfo.fromJson(data, { ignoreUnknownFields: true });
200
+ }
201
+
202
+ /**
203
+ * @param name human-readable name of the trunk
204
+ * @param address hostname and port of the SIP server to dial
205
+ * @param numbers phone numbers of the trunk
206
+ * @param opts CreateSipTrunkOptions
207
+ */
208
+ async createSipOutboundTrunk(
209
+ name: string,
210
+ address: string,
211
+ numbers: string[],
212
+ opts?: CreateSipOutboundTrunkOptions,
213
+ ): Promise<SIPOutboundTrunkInfo> {
214
+ let authUsername: string = '';
215
+ let authPassword: string = '';
216
+ let transport: SIPTransport = SIPTransport.SIP_TRANSPORT_AUTO;
217
+ let metadata: string = '';
218
+
219
+ if (opts !== undefined) {
220
+ authUsername = opts.auth_username || '';
221
+ authPassword = opts.auth_password || '';
222
+ transport = opts.transport || SIPTransport.SIP_TRANSPORT_AUTO;
223
+ metadata = opts.metadata || '';
224
+ }
225
+
226
+ const req = new CreateSIPOutboundTrunkRequest({
227
+ trunk: new SIPOutboundTrunkInfo({
228
+ name: name,
229
+ address: address,
230
+ numbers: numbers,
231
+ metadata: metadata,
232
+ transport: transport,
233
+ authUsername: authUsername,
234
+ authPassword: authPassword,
235
+ }),
236
+ }).toJson();
237
+
238
+ const data = await this.rpc.request(
239
+ svc,
240
+ 'CreateSIPOutboundTrunk',
241
+ req,
242
+ await this.authHeader({}, { admin: true }),
243
+ );
244
+ return SIPOutboundTrunkInfo.fromJson(data, { ignoreUnknownFields: true });
245
+ }
246
+
247
+ /**
248
+ * @deprecated use listSipInboundTrunk or listSipOutboundTrunk
249
+ */
125
250
  async listSipTrunk(): Promise<Array<SIPTrunkInfo>> {
126
251
  const req: Partial<ListSIPTrunkRequest> = {};
127
252
  const data = await this.rpc.request(
128
253
  svc,
129
254
  'ListSIPTrunk',
130
255
  new ListSIPTrunkRequest(req).toJson(),
131
- await this.authHeader({}),
256
+ await this.authHeader({}, { admin: true }),
132
257
  );
133
258
  return ListSIPTrunkResponse.fromJson(data, { ignoreUnknownFields: true }).items ?? [];
134
259
  }
135
260
 
261
+ async listSipInboundTrunk(): Promise<Array<SIPInboundTrunkInfo>> {
262
+ const req: Partial<ListSIPInboundTrunkRequest> = {};
263
+ const data = await this.rpc.request(
264
+ svc,
265
+ 'ListSIPInboundTrunk',
266
+ new ListSIPInboundTrunkRequest(req).toJson(),
267
+ await this.authHeader({}, { admin: true }),
268
+ );
269
+ return ListSIPInboundTrunkResponse.fromJson(data, { ignoreUnknownFields: true }).items ?? [];
270
+ }
271
+
272
+ async listSipOutboundTrunk(): Promise<Array<SIPOutboundTrunkInfo>> {
273
+ const req: Partial<ListSIPOutboundTrunkRequest> = {};
274
+ const data = await this.rpc.request(
275
+ svc,
276
+ 'ListSIPOutboundTrunk',
277
+ new ListSIPOutboundTrunkRequest(req).toJson(),
278
+ await this.authHeader({}, { admin: true }),
279
+ );
280
+ return ListSIPOutboundTrunkResponse.fromJson(data, { ignoreUnknownFields: true }).items ?? [];
281
+ }
282
+
136
283
  /**
137
284
  * @param sipTrunkId sip trunk to delete
138
285
  */
@@ -141,7 +288,7 @@ export class SipClient extends ServiceBase {
141
288
  svc,
142
289
  'DeleteSIPTrunk',
143
290
  new DeleteSIPTrunkRequest({ sipTrunkId }).toJson(),
144
- await this.authHeader({}),
291
+ await this.authHeader({}, { admin: true }),
145
292
  );
146
293
  return SIPTrunkInfo.fromJson(data, { ignoreUnknownFields: true });
147
294
  }
@@ -200,7 +347,7 @@ export class SipClient extends ServiceBase {
200
347
  svc,
201
348
  'CreateSIPDispatchRule',
202
349
  req,
203
- await this.authHeader({}),
350
+ await this.authHeader({}, { admin: true }),
204
351
  );
205
352
  return SIPDispatchRuleInfo.fromJson(data, { ignoreUnknownFields: true });
206
353
  }
@@ -211,7 +358,7 @@ export class SipClient extends ServiceBase {
211
358
  svc,
212
359
  'ListSIPDispatchRule',
213
360
  new ListSIPDispatchRuleRequest(req).toJson(),
214
- await this.authHeader({}),
361
+ await this.authHeader({}, { admin: true }),
215
362
  );
216
363
  return ListSIPDispatchRuleResponse.fromJson(data, { ignoreUnknownFields: true }).items ?? [];
217
364
  }
@@ -224,7 +371,7 @@ export class SipClient extends ServiceBase {
224
371
  svc,
225
372
  'DeleteSIPDispatchRule',
226
373
  new DeleteSIPDispatchRuleRequest({ sipDispatchRuleId }).toJson(),
227
- await this.authHeader({}),
374
+ await this.authHeader({}, { admin: true }),
228
375
  );
229
376
  return SIPDispatchRuleInfo.fromJson(data, { ignoreUnknownFields: true });
230
377
  }
@@ -246,6 +393,7 @@ export class SipClient extends ServiceBase {
246
393
  let participantMetadata: string = '';
247
394
  let dtmf: string = '';
248
395
  let playRingtone: boolean = false;
396
+ let hidePhoneNumber: boolean = false;
249
397
 
250
398
  if (opts !== undefined) {
251
399
  participantIdentity = opts.participantIdentity || '';
@@ -253,6 +401,7 @@ export class SipClient extends ServiceBase {
253
401
  participantMetadata = opts.participantMetadata || '';
254
402
  dtmf = opts.dtmf || '';
255
403
  playRingtone = opts.playRingtone || false;
404
+ hidePhoneNumber = opts.hidePhoneNumber || false;
256
405
  }
257
406
 
258
407
  const req = new CreateSIPParticipantRequest({
@@ -264,13 +413,14 @@ export class SipClient extends ServiceBase {
264
413
  participantMetadata: participantMetadata,
265
414
  dtmf: dtmf,
266
415
  playRingtone: playRingtone,
416
+ hidePhoneNumber: hidePhoneNumber,
267
417
  }).toJson();
268
418
 
269
419
  const data = await this.rpc.request(
270
420
  svc,
271
421
  'CreateSIPParticipant',
272
422
  req,
273
- await this.authHeader({}),
423
+ await this.authHeader({}, { call: true }),
274
424
  );
275
425
  return SIPParticipantInfo.fromJson(data, { ignoreUnknownFields: true });
276
426
  }
package/src/grants.ts CHANGED
@@ -2,7 +2,7 @@
2
2
  //
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import { TrackSource } from '@livekit/protocol';
5
- import { JWTPayload } from 'jose';
5
+ import type { JWTPayload } from 'jose';
6
6
 
7
7
  export function trackSourceToString(source: TrackSource) {
8
8
  switch (source) {
@@ -83,14 +83,25 @@ export interface VideoGrant {
83
83
  /** participant is recording the room, when set, allows room to indicate it's being recorded */
84
84
  recorder?: boolean;
85
85
 
86
- /** participant acts as a server side participant/bot/agent */
86
+ /** participant allowed to connect to LiveKit as Agent Framework worker */
87
87
  agent?: boolean;
88
88
  }
89
89
 
90
+ export interface SIPGrant {
91
+ /** manage sip resources */
92
+ admin?: boolean;
93
+
94
+ /** make outbound calls */
95
+ call?: boolean;
96
+ }
97
+
90
98
  /** @internal */
91
99
  export interface ClaimGrants extends JWTPayload {
92
100
  name?: string;
93
101
  video?: VideoGrant;
102
+ sip?: SIPGrant;
103
+ kind?: string;
94
104
  metadata?: string;
105
+ attributes?: Record<string, string>;
95
106
  sha256?: string;
96
107
  }