livekit-server-sdk 2.6.2 → 2.7.1
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/AccessToken.d.ts +2 -2
- package/dist/AccessToken.js +2 -2
- package/dist/EgressClient.d.ts +27 -27
- package/dist/EgressClient.d.ts.map +1 -1
- package/dist/EgressClient.js +23 -19
- package/dist/EgressClient.js.map +1 -1
- package/dist/IngressClient.d.ts +13 -12
- package/dist/IngressClient.d.ts.map +1 -1
- package/dist/IngressClient.js +11 -11
- package/dist/IngressClient.js.map +1 -1
- package/dist/RoomServiceClient.d.ts +24 -24
- package/dist/RoomServiceClient.js +16 -16
- package/dist/ServiceBase.d.ts +5 -5
- package/dist/ServiceBase.d.ts.map +1 -1
- package/dist/ServiceBase.js +3 -3
- package/dist/SipClient.d.ts +28 -22
- package/dist/SipClient.d.ts.map +1 -1
- package/dist/SipClient.js +36 -23
- package/dist/SipClient.js.map +1 -1
- package/dist/TwirpRPC.d.ts.map +1 -1
- package/dist/TwirpRPC.js +1 -0
- package/dist/TwirpRPC.js.map +1 -1
- package/dist/WebhookReceiver.d.ts +4 -5
- package/dist/WebhookReceiver.d.ts.map +1 -1
- package/dist/WebhookReceiver.js +3 -4
- package/dist/WebhookReceiver.js.map +1 -1
- package/dist/grants.d.ts +2 -0
- package/dist/grants.d.ts.map +1 -1
- package/dist/grants.js +1 -0
- package/dist/grants.js.map +1 -1
- package/package.json +3 -3
- package/src/AccessToken.ts +2 -2
- package/src/EgressClient.ts +32 -28
- package/src/IngressClient.ts +17 -15
- package/src/RoomServiceClient.ts +24 -24
- package/src/ServiceBase.ts +5 -5
- package/src/SipClient.ts +49 -23
- package/src/TwirpRPC.ts +2 -0
- package/src/WebhookReceiver.ts +4 -5
- package/src/grants.test.ts +2 -1
- package/src/grants.ts +4 -0
package/src/EgressClient.ts
CHANGED
|
@@ -121,9 +121,9 @@ export class EgressClient extends ServiceBase {
|
|
|
121
121
|
private readonly rpc: Rpc;
|
|
122
122
|
|
|
123
123
|
/**
|
|
124
|
-
* @param host hostname including protocol. i.e. 'https://cluster.livekit.io'
|
|
125
|
-
* @param apiKey API Key, can be set in env var LIVEKIT_API_KEY
|
|
126
|
-
* @param secret API Secret, can be set in env var LIVEKIT_API_SECRET
|
|
124
|
+
* @param host - hostname including protocol. i.e. 'https://cluster.livekit.io'
|
|
125
|
+
* @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
|
|
126
|
+
* @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
|
|
127
127
|
*/
|
|
128
128
|
constructor(host: string, apiKey?: string, secret?: string) {
|
|
129
129
|
super(apiKey, secret);
|
|
@@ -131,9 +131,9 @@ export class EgressClient extends ServiceBase {
|
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/**
|
|
134
|
-
* @param roomName room name
|
|
135
|
-
* @param output file or stream output
|
|
136
|
-
* @param opts RoomCompositeOptions
|
|
134
|
+
* @param roomName - room name
|
|
135
|
+
* @param output - file or stream output
|
|
136
|
+
* @param opts - RoomCompositeOptions
|
|
137
137
|
*/
|
|
138
138
|
async startRoomCompositeEgress(
|
|
139
139
|
roomName: string,
|
|
@@ -213,9 +213,9 @@ export class EgressClient extends ServiceBase {
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
/**
|
|
216
|
-
* @param url url
|
|
217
|
-
* @param output file or stream output
|
|
218
|
-
* @param opts WebOptions
|
|
216
|
+
* @param url - url
|
|
217
|
+
* @param output - file or stream output
|
|
218
|
+
* @param opts - WebOptions
|
|
219
219
|
*/
|
|
220
220
|
async startWebEgress(
|
|
221
221
|
url: string,
|
|
@@ -259,9 +259,9 @@ export class EgressClient extends ServiceBase {
|
|
|
259
259
|
/**
|
|
260
260
|
* Export a participant's audio and video tracks,
|
|
261
261
|
*
|
|
262
|
-
* @param roomName room name
|
|
263
|
-
* @param output one or more outputs
|
|
264
|
-
* @param opts ParticipantEgressOptions
|
|
262
|
+
* @param roomName - room name
|
|
263
|
+
* @param output - one or more outputs
|
|
264
|
+
* @param opts - ParticipantEgressOptions
|
|
265
265
|
*/
|
|
266
266
|
async startParticipantEgress(
|
|
267
267
|
roomName: string,
|
|
@@ -291,9 +291,9 @@ export class EgressClient extends ServiceBase {
|
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
/**
|
|
294
|
-
* @param roomName room name
|
|
295
|
-
* @param output file or stream output
|
|
296
|
-
* @param opts TrackCompositeOptions
|
|
294
|
+
* @param roomName - room name
|
|
295
|
+
* @param output - file or stream output
|
|
296
|
+
* @param opts - TrackCompositeOptions
|
|
297
297
|
*/
|
|
298
298
|
async startTrackCompositeEgress(
|
|
299
299
|
roomName: string,
|
|
@@ -361,6 +361,7 @@ export class EgressClient extends ServiceBase {
|
|
|
361
361
|
return EgressInfo.fromJson(data, { ignoreUnknownFields: true });
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
364
365
|
private isEncodedOutputs(output: any): output is EncodedOutputs {
|
|
365
366
|
return (
|
|
366
367
|
(<EncodedOutputs>output).file !== undefined ||
|
|
@@ -369,6 +370,7 @@ export class EgressClient extends ServiceBase {
|
|
|
369
370
|
);
|
|
370
371
|
}
|
|
371
372
|
|
|
373
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
372
374
|
private isEncodedFileOutput(output: any): output is EncodedFileOutput {
|
|
373
375
|
return (
|
|
374
376
|
(<EncodedFileOutput>output).filepath !== undefined ||
|
|
@@ -376,6 +378,7 @@ export class EgressClient extends ServiceBase {
|
|
|
376
378
|
);
|
|
377
379
|
}
|
|
378
380
|
|
|
381
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
379
382
|
private isSegmentedFileOutput(output: any): output is SegmentedFileOutput {
|
|
380
383
|
return (
|
|
381
384
|
(<SegmentedFileOutput>output).filenamePrefix !== undefined ||
|
|
@@ -384,6 +387,7 @@ export class EgressClient extends ServiceBase {
|
|
|
384
387
|
);
|
|
385
388
|
}
|
|
386
389
|
|
|
390
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
387
391
|
private isStreamOutput(output: any): output is StreamOutput {
|
|
388
392
|
return (
|
|
389
393
|
(<StreamOutput>output).protocol !== undefined || (<StreamOutput>output).urls !== undefined
|
|
@@ -492,9 +496,9 @@ export class EgressClient extends ServiceBase {
|
|
|
492
496
|
}
|
|
493
497
|
|
|
494
498
|
/**
|
|
495
|
-
* @param roomName room name
|
|
496
|
-
* @param output file or websocket output
|
|
497
|
-
* @param trackId track Id
|
|
499
|
+
* @param roomName - room name
|
|
500
|
+
* @param output - file or websocket output
|
|
501
|
+
* @param trackId - track Id
|
|
498
502
|
*/
|
|
499
503
|
async startTrackEgress(
|
|
500
504
|
roomName: string,
|
|
@@ -540,8 +544,8 @@ export class EgressClient extends ServiceBase {
|
|
|
540
544
|
}
|
|
541
545
|
|
|
542
546
|
/**
|
|
543
|
-
* @param egressId
|
|
544
|
-
* @param layout
|
|
547
|
+
* @param egressId -
|
|
548
|
+
* @param layout -
|
|
545
549
|
*/
|
|
546
550
|
async updateLayout(egressId: string, layout: string): Promise<EgressInfo> {
|
|
547
551
|
const data = await this.rpc.request(
|
|
@@ -554,9 +558,9 @@ export class EgressClient extends ServiceBase {
|
|
|
554
558
|
}
|
|
555
559
|
|
|
556
560
|
/**
|
|
557
|
-
* @param egressId
|
|
558
|
-
* @param addOutputUrls
|
|
559
|
-
* @param removeOutputUrls
|
|
561
|
+
* @param egressId -
|
|
562
|
+
* @param addOutputUrls -
|
|
563
|
+
* @param removeOutputUrls -
|
|
560
564
|
*/
|
|
561
565
|
async updateStream(
|
|
562
566
|
egressId: string,
|
|
@@ -576,17 +580,17 @@ export class EgressClient extends ServiceBase {
|
|
|
576
580
|
}
|
|
577
581
|
|
|
578
582
|
/**
|
|
579
|
-
* @param options options to filter listed Egresses, by default returns all
|
|
583
|
+
* @param options - options to filter listed Egresses, by default returns all
|
|
580
584
|
* Egress instances
|
|
581
585
|
*/
|
|
582
586
|
async listEgress(options?: ListEgressOptions): Promise<Array<EgressInfo>>;
|
|
583
587
|
/**
|
|
584
|
-
* @deprecated
|
|
585
|
-
* @param roomName list egress for one room only
|
|
588
|
+
* @deprecated use `listEgress(options?: ListEgressOptions)` instead
|
|
589
|
+
* @param roomName - list egress for one room only
|
|
586
590
|
*/
|
|
587
591
|
async listEgress(roomName?: string): Promise<Array<EgressInfo>>;
|
|
588
592
|
/**
|
|
589
|
-
* @param roomName list egress for one room only
|
|
593
|
+
* @param roomName - list egress for one room only
|
|
590
594
|
*/
|
|
591
595
|
async listEgress(options?: string | ListEgressOptions): Promise<Array<EgressInfo>> {
|
|
592
596
|
let req: Partial<ListEgressRequest> = {};
|
|
@@ -606,7 +610,7 @@ export class EgressClient extends ServiceBase {
|
|
|
606
610
|
}
|
|
607
611
|
|
|
608
612
|
/**
|
|
609
|
-
* @param egressId
|
|
613
|
+
* @param egressId -
|
|
610
614
|
*/
|
|
611
615
|
async stopEgress(egressId: string): Promise<EgressInfo> {
|
|
612
616
|
const data = await this.rpc.request(
|
package/src/IngressClient.ts
CHANGED
|
@@ -1,19 +1,18 @@
|
|
|
1
1
|
// SPDX-FileCopyrightText: 2024 LiveKit, Inc.
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
import type { IngressAudioOptions, IngressInput, IngressVideoOptions } from '@livekit/protocol';
|
|
4
5
|
import {
|
|
5
6
|
CreateIngressRequest,
|
|
6
7
|
DeleteIngressRequest,
|
|
7
|
-
IngressAudioOptions,
|
|
8
8
|
IngressInfo,
|
|
9
|
-
IngressInput,
|
|
10
|
-
IngressVideoOptions,
|
|
11
9
|
ListIngressRequest,
|
|
12
10
|
ListIngressResponse,
|
|
13
11
|
UpdateIngressRequest,
|
|
14
12
|
} from '@livekit/protocol';
|
|
15
13
|
import ServiceBase from './ServiceBase.js';
|
|
16
|
-
import { Rpc
|
|
14
|
+
import type { Rpc } from './TwirpRPC.js';
|
|
15
|
+
import { TwirpRpc, livekitPackage } from './TwirpRPC.js';
|
|
17
16
|
|
|
18
17
|
const svc = 'Ingress';
|
|
19
18
|
|
|
@@ -122,9 +121,9 @@ export class IngressClient extends ServiceBase {
|
|
|
122
121
|
private readonly rpc: Rpc;
|
|
123
122
|
|
|
124
123
|
/**
|
|
125
|
-
* @param host hostname including protocol. i.e. 'https://cluster.livekit.io'
|
|
126
|
-
* @param apiKey API Key, can be set in env var LIVEKIT_API_KEY
|
|
127
|
-
* @param secret API Secret, can be set in env var LIVEKIT_API_SECRET
|
|
124
|
+
* @param host - hostname including protocol. i.e. 'https://cluster.livekit.io'
|
|
125
|
+
* @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
|
|
126
|
+
* @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
|
|
128
127
|
*/
|
|
129
128
|
constructor(host: string, apiKey?: string, secret?: string) {
|
|
130
129
|
super(apiKey, secret);
|
|
@@ -132,8 +131,8 @@ export class IngressClient extends ServiceBase {
|
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
/**
|
|
135
|
-
* @param inputType protocol for the ingress
|
|
136
|
-
* @param opts CreateIngressOptions
|
|
134
|
+
* @param inputType - protocol for the ingress
|
|
135
|
+
* @param opts - CreateIngressOptions
|
|
137
136
|
*/
|
|
138
137
|
async createIngress(inputType: IngressInput, opts?: CreateIngressOptions): Promise<IngressInfo> {
|
|
139
138
|
let name: string = '';
|
|
@@ -184,8 +183,8 @@ export class IngressClient extends ServiceBase {
|
|
|
184
183
|
}
|
|
185
184
|
|
|
186
185
|
/**
|
|
187
|
-
* @param ingressId ID of the ingress to update
|
|
188
|
-
* @param opts UpdateIngressOptions
|
|
186
|
+
* @param ingressId - ID of the ingress to update
|
|
187
|
+
* @param opts - UpdateIngressOptions
|
|
189
188
|
*/
|
|
190
189
|
async updateIngress(ingressId: string, opts: UpdateIngressOptions): Promise<IngressInfo> {
|
|
191
190
|
const name: string = opts.name || '';
|
|
@@ -218,14 +217,17 @@ export class IngressClient extends ServiceBase {
|
|
|
218
217
|
}
|
|
219
218
|
|
|
220
219
|
/**
|
|
221
|
-
* @deprecated use listIngress(opts) instead
|
|
222
|
-
* @param roomName list ingress for one room only
|
|
220
|
+
* @deprecated use `listIngress(opts)` or `listIngress(arg)` instead
|
|
221
|
+
* @param roomName - list ingress for one room only
|
|
223
222
|
*/
|
|
224
223
|
async listIngress(roomName?: string): Promise<Array<IngressInfo>>;
|
|
225
224
|
/**
|
|
226
|
-
* @param opts list options
|
|
225
|
+
* @param opts - list options
|
|
227
226
|
*/
|
|
228
227
|
async listIngress(opts?: ListIngressOptions): Promise<Array<IngressInfo>>;
|
|
228
|
+
/**
|
|
229
|
+
* @param arg - list room name or options
|
|
230
|
+
*/
|
|
229
231
|
async listIngress(arg?: string | ListIngressOptions): Promise<Array<IngressInfo>> {
|
|
230
232
|
let req: Partial<ListIngressRequest> = {};
|
|
231
233
|
if (typeof arg === 'string') {
|
|
@@ -243,7 +245,7 @@ export class IngressClient extends ServiceBase {
|
|
|
243
245
|
}
|
|
244
246
|
|
|
245
247
|
/**
|
|
246
|
-
* @param ingressId ingress to delete
|
|
248
|
+
* @param ingressId - ingress to delete
|
|
247
249
|
*/
|
|
248
250
|
async deleteIngress(ingressId: string): Promise<IngressInfo> {
|
|
249
251
|
const data = await this.rpc.request(
|
package/src/RoomServiceClient.ts
CHANGED
|
@@ -122,7 +122,7 @@ export class RoomServiceClient extends ServiceBase {
|
|
|
122
122
|
* Creates a new room. Explicit room creation is not required, since rooms will
|
|
123
123
|
* be automatically created when the first participant joins. This method can be
|
|
124
124
|
* used to customize room settings.
|
|
125
|
-
* @param options
|
|
125
|
+
* @param options -
|
|
126
126
|
*/
|
|
127
127
|
async createRoom(options: CreateOptions): Promise<Room> {
|
|
128
128
|
const data = await this.rpc.request(
|
|
@@ -162,8 +162,8 @@ export class RoomServiceClient extends ServiceBase {
|
|
|
162
162
|
|
|
163
163
|
/**
|
|
164
164
|
* Update metadata of a room
|
|
165
|
-
* @param room name of the room
|
|
166
|
-
* @param metadata the new metadata for the room
|
|
165
|
+
* @param room - name of the room
|
|
166
|
+
* @param metadata - the new metadata for the room
|
|
167
167
|
*/
|
|
168
168
|
async updateRoomMetadata(room: string, metadata: string) {
|
|
169
169
|
const data = await this.rpc.request(
|
|
@@ -177,7 +177,7 @@ export class RoomServiceClient extends ServiceBase {
|
|
|
177
177
|
|
|
178
178
|
/**
|
|
179
179
|
* List participants in a room
|
|
180
|
-
* @param room name of the room
|
|
180
|
+
* @param room - name of the room
|
|
181
181
|
*/
|
|
182
182
|
async listParticipants(room: string): Promise<ParticipantInfo[]> {
|
|
183
183
|
const data = await this.rpc.request(
|
|
@@ -193,8 +193,8 @@ export class RoomServiceClient extends ServiceBase {
|
|
|
193
193
|
/**
|
|
194
194
|
* Get information on a specific participant, including the tracks that participant
|
|
195
195
|
* has published
|
|
196
|
-
* @param room name of the room
|
|
197
|
-
* @param identity identity of the participant to return
|
|
196
|
+
* @param room - name of the room
|
|
197
|
+
* @param identity - identity of the participant to return
|
|
198
198
|
*/
|
|
199
199
|
async getParticipant(room: string, identity: string): Promise<ParticipantInfo> {
|
|
200
200
|
const data = await this.rpc.request(
|
|
@@ -211,8 +211,8 @@ export class RoomServiceClient extends ServiceBase {
|
|
|
211
211
|
* Removes a participant in the room. This will disconnect the participant
|
|
212
212
|
* and will emit a Disconnected event for that participant.
|
|
213
213
|
* Even after being removed, the participant can still re-join the room.
|
|
214
|
-
* @param room
|
|
215
|
-
* @param identity
|
|
214
|
+
* @param room -
|
|
215
|
+
* @param identity -
|
|
216
216
|
*/
|
|
217
217
|
async removeParticipant(room: string, identity: string): Promise<void> {
|
|
218
218
|
await this.rpc.request(
|
|
@@ -225,10 +225,10 @@ export class RoomServiceClient extends ServiceBase {
|
|
|
225
225
|
|
|
226
226
|
/**
|
|
227
227
|
* Mutes a track that the participant has published.
|
|
228
|
-
* @param room
|
|
229
|
-
* @param identity
|
|
230
|
-
* @param trackSid sid of the track to be muted
|
|
231
|
-
* @param muted true to mute, false to unmute
|
|
228
|
+
* @param room -
|
|
229
|
+
* @param identity -
|
|
230
|
+
* @param trackSid - sid of the track to be muted
|
|
231
|
+
* @param muted - true to mute, false to unmute
|
|
232
232
|
*/
|
|
233
233
|
async mutePublishedTrack(
|
|
234
234
|
room: string,
|
|
@@ -312,10 +312,10 @@ export class RoomServiceClient extends ServiceBase {
|
|
|
312
312
|
|
|
313
313
|
/**
|
|
314
314
|
* Updates a participant's subscription to tracks
|
|
315
|
-
* @param room
|
|
316
|
-
* @param identity
|
|
317
|
-
* @param trackSids
|
|
318
|
-
* @param subscribe true to subscribe, false to unsubscribe
|
|
315
|
+
* @param room -
|
|
316
|
+
* @param identity -
|
|
317
|
+
* @param trackSids -
|
|
318
|
+
* @param subscribe - true to subscribe, false to unsubscribe
|
|
319
319
|
*/
|
|
320
320
|
async updateSubscriptions(
|
|
321
321
|
room: string,
|
|
@@ -340,10 +340,10 @@ export class RoomServiceClient extends ServiceBase {
|
|
|
340
340
|
|
|
341
341
|
/**
|
|
342
342
|
* Sends data message to participants in the room
|
|
343
|
-
* @param room
|
|
344
|
-
* @param data opaque payload to send
|
|
345
|
-
* @param kind delivery reliability
|
|
346
|
-
* @param options optionally specify a topic and destinationSids (when destinationSids is empty, message is sent to everyone)
|
|
343
|
+
* @param room -
|
|
344
|
+
* @param data - opaque payload to send
|
|
345
|
+
* @param kind - delivery reliability
|
|
346
|
+
* @param options - optionally specify a topic and destinationSids (when destinationSids is empty, message is sent to everyone)
|
|
347
347
|
*/
|
|
348
348
|
async sendData(
|
|
349
349
|
room: string,
|
|
@@ -354,10 +354,10 @@ export class RoomServiceClient extends ServiceBase {
|
|
|
354
354
|
/**
|
|
355
355
|
* Sends data message to participants in the room
|
|
356
356
|
* @deprecated use sendData(room, data, kind, options) instead
|
|
357
|
-
* @param room
|
|
358
|
-
* @param data opaque payload to send
|
|
359
|
-
* @param kind delivery reliability
|
|
360
|
-
* @param destinationSids optional. when empty, message is sent to everyone
|
|
357
|
+
* @param room -
|
|
358
|
+
* @param data - opaque payload to send
|
|
359
|
+
* @param kind - delivery reliability
|
|
360
|
+
* @param destinationSids - optional. when empty, message is sent to everyone
|
|
361
361
|
*/
|
|
362
362
|
async sendData(
|
|
363
363
|
room: string,
|
package/src/ServiceBase.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
//
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
import { AccessToken } from './AccessToken.js';
|
|
5
|
-
import { SIPGrant, VideoGrant } from './grants.js';
|
|
5
|
+
import type { SIPGrant, VideoGrant } from './grants.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Utilities to handle authentication
|
|
@@ -15,9 +15,9 @@ export default class ServiceBase {
|
|
|
15
15
|
private readonly ttl: string;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* @param apiKey API Key.
|
|
19
|
-
* @param secret API Secret.
|
|
20
|
-
* @param ttl token TTL
|
|
18
|
+
* @param apiKey - API Key.
|
|
19
|
+
* @param secret - API Secret.
|
|
20
|
+
* @param ttl - token TTL
|
|
21
21
|
*/
|
|
22
22
|
constructor(apiKey?: string, secret?: string, ttl?: string) {
|
|
23
23
|
this.apiKey = apiKey;
|
|
@@ -25,7 +25,7 @@ export default class ServiceBase {
|
|
|
25
25
|
this.ttl = ttl || '10m';
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
async authHeader(grant: VideoGrant, sip?: SIPGrant): Promise<
|
|
28
|
+
async authHeader(grant: VideoGrant, sip?: SIPGrant): Promise<Record<string, string>> {
|
|
29
29
|
const at = new AccessToken(this.apiKey, this.secret, { ttl: this.ttl });
|
|
30
30
|
at.addGrant(grant);
|
|
31
31
|
if (sip) {
|
package/src/SipClient.ts
CHANGED
|
@@ -26,9 +26,11 @@ import {
|
|
|
26
26
|
SIPParticipantInfo,
|
|
27
27
|
SIPTransport,
|
|
28
28
|
SIPTrunkInfo,
|
|
29
|
+
TransferSIPParticipantRequest,
|
|
29
30
|
} from '@livekit/protocol';
|
|
30
31
|
import ServiceBase from './ServiceBase.js';
|
|
31
|
-
import { Rpc
|
|
32
|
+
import type { Rpc } from './TwirpRPC.js';
|
|
33
|
+
import { TwirpRpc, livekitPackage } from './TwirpRPC.js';
|
|
32
34
|
|
|
33
35
|
const svc = 'SIP';
|
|
34
36
|
|
|
@@ -95,9 +97,9 @@ export class SipClient extends ServiceBase {
|
|
|
95
97
|
private readonly rpc: Rpc;
|
|
96
98
|
|
|
97
99
|
/**
|
|
98
|
-
* @param host hostname including protocol. i.e. 'https://cluster.livekit.io'
|
|
99
|
-
* @param apiKey API Key, can be set in env var LIVEKIT_API_KEY
|
|
100
|
-
* @param secret API Secret, can be set in env var LIVEKIT_API_SECRET
|
|
100
|
+
* @param host - hostname including protocol. i.e. 'https://cluster.livekit.io'
|
|
101
|
+
* @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
|
|
102
|
+
* @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
|
|
101
103
|
*/
|
|
102
104
|
constructor(host: string, apiKey?: string, secret?: string) {
|
|
103
105
|
super(apiKey, secret);
|
|
@@ -105,9 +107,9 @@ export class SipClient extends ServiceBase {
|
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
/**
|
|
108
|
-
* @param number phone number of the trunk
|
|
109
|
-
* @param opts CreateSipTrunkOptions
|
|
110
|
-
* @deprecated use createSipInboundTrunk or createSipOutboundTrunk
|
|
110
|
+
* @param number - phone number of the trunk
|
|
111
|
+
* @param opts - CreateSipTrunkOptions
|
|
112
|
+
* @deprecated use `createSipInboundTrunk` or `createSipOutboundTrunk`
|
|
111
113
|
*/
|
|
112
114
|
async createSipTrunk(number: string, opts?: CreateSipTrunkOptions): Promise<SIPTrunkInfo> {
|
|
113
115
|
let inboundAddresses: string[] | undefined;
|
|
@@ -155,9 +157,9 @@ export class SipClient extends ServiceBase {
|
|
|
155
157
|
}
|
|
156
158
|
|
|
157
159
|
/**
|
|
158
|
-
@param name human-readable name of the trunk
|
|
159
|
-
* @param numbers phone numbers of the trunk
|
|
160
|
-
* @param opts CreateSipTrunkOptions
|
|
160
|
+
* @param name - human-readable name of the trunk
|
|
161
|
+
* @param numbers - phone numbers of the trunk
|
|
162
|
+
* @param opts - CreateSipTrunkOptions
|
|
161
163
|
*/
|
|
162
164
|
async createSipInboundTrunk(
|
|
163
165
|
name: string,
|
|
@@ -200,10 +202,10 @@ export class SipClient extends ServiceBase {
|
|
|
200
202
|
}
|
|
201
203
|
|
|
202
204
|
/**
|
|
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
|
|
205
|
+
* @param name - human-readable name of the trunk
|
|
206
|
+
* @param address - hostname and port of the SIP server to dial
|
|
207
|
+
* @param numbers - phone numbers of the trunk
|
|
208
|
+
* @param opts - CreateSipTrunkOptions
|
|
207
209
|
*/
|
|
208
210
|
async createSipOutboundTrunk(
|
|
209
211
|
name: string,
|
|
@@ -245,7 +247,7 @@ export class SipClient extends ServiceBase {
|
|
|
245
247
|
}
|
|
246
248
|
|
|
247
249
|
/**
|
|
248
|
-
* @deprecated use listSipInboundTrunk or listSipOutboundTrunk
|
|
250
|
+
* @deprecated use `listSipInboundTrunk` or `listSipOutboundTrunk`
|
|
249
251
|
*/
|
|
250
252
|
async listSipTrunk(): Promise<Array<SIPTrunkInfo>> {
|
|
251
253
|
const req: Partial<ListSIPTrunkRequest> = {};
|
|
@@ -281,7 +283,7 @@ export class SipClient extends ServiceBase {
|
|
|
281
283
|
}
|
|
282
284
|
|
|
283
285
|
/**
|
|
284
|
-
* @param sipTrunkId sip trunk to delete
|
|
286
|
+
* @param sipTrunkId - sip trunk to delete
|
|
285
287
|
*/
|
|
286
288
|
async deleteSipTrunk(sipTrunkId: string): Promise<SIPTrunkInfo> {
|
|
287
289
|
const data = await this.rpc.request(
|
|
@@ -294,8 +296,8 @@ export class SipClient extends ServiceBase {
|
|
|
294
296
|
}
|
|
295
297
|
|
|
296
298
|
/**
|
|
297
|
-
* @param rule sip dispatch rule
|
|
298
|
-
* @param opts CreateSipDispatchRuleOptions
|
|
299
|
+
* @param rule - sip dispatch rule
|
|
300
|
+
* @param opts - CreateSipDispatchRuleOptions
|
|
299
301
|
*/
|
|
300
302
|
async createSipDispatchRule(
|
|
301
303
|
rule: SipDispatchRuleDirect | SipDispatchRuleIndividual,
|
|
@@ -364,7 +366,7 @@ export class SipClient extends ServiceBase {
|
|
|
364
366
|
}
|
|
365
367
|
|
|
366
368
|
/**
|
|
367
|
-
* @param sipDispatchRuleId sip trunk to delete
|
|
369
|
+
* @param sipDispatchRuleId - sip trunk to delete
|
|
368
370
|
*/
|
|
369
371
|
async deleteSipDispatchRule(sipDispatchRuleId: string): Promise<SIPDispatchRuleInfo> {
|
|
370
372
|
const data = await this.rpc.request(
|
|
@@ -377,10 +379,10 @@ export class SipClient extends ServiceBase {
|
|
|
377
379
|
}
|
|
378
380
|
|
|
379
381
|
/**
|
|
380
|
-
* @param sipTrunkId sip trunk to use for the call
|
|
381
|
-
* @param number number to dial
|
|
382
|
-
* @param roomName room to attach the call to
|
|
383
|
-
* @param opts CreateSipParticipantOptions
|
|
382
|
+
* @param sipTrunkId - sip trunk to use for the call
|
|
383
|
+
* @param number - number to dial
|
|
384
|
+
* @param roomName - room to attach the call to
|
|
385
|
+
* @param opts - CreateSipParticipantOptions
|
|
384
386
|
*/
|
|
385
387
|
async createSipParticipant(
|
|
386
388
|
sipTrunkId: string,
|
|
@@ -424,4 +426,28 @@ export class SipClient extends ServiceBase {
|
|
|
424
426
|
);
|
|
425
427
|
return SIPParticipantInfo.fromJson(data, { ignoreUnknownFields: true });
|
|
426
428
|
}
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* @param roomName - room the SIP participant to transfer is connectd to
|
|
432
|
+
* @param participantIdentity - identity of the SIP participant to transfer
|
|
433
|
+
* @param transferTo - SIP URL to transfer the participant to
|
|
434
|
+
*/
|
|
435
|
+
async transferSipParticipant(
|
|
436
|
+
roomName: string,
|
|
437
|
+
participantIdentity: string,
|
|
438
|
+
transferTo: string,
|
|
439
|
+
): Promise<void> {
|
|
440
|
+
const req = new TransferSIPParticipantRequest({
|
|
441
|
+
participantIdentity: participantIdentity,
|
|
442
|
+
roomName: roomName,
|
|
443
|
+
transferTo: transferTo,
|
|
444
|
+
}).toJson();
|
|
445
|
+
|
|
446
|
+
await this.rpc.request(
|
|
447
|
+
svc,
|
|
448
|
+
'TransferSIPParticipant',
|
|
449
|
+
req,
|
|
450
|
+
await this.authHeader({ roomAdmin: true, room: roomName }, { call: true }),
|
|
451
|
+
);
|
|
452
|
+
}
|
|
427
453
|
}
|
package/src/TwirpRPC.ts
CHANGED
|
@@ -10,6 +10,7 @@ const defaultPrefix = '/twirp';
|
|
|
10
10
|
|
|
11
11
|
export const livekitPackage = 'livekit';
|
|
12
12
|
export interface Rpc {
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
14
|
request(service: string, method: string, data: JsonValue, headers?: any): Promise<string>;
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -32,6 +33,7 @@ export class TwirpRpc {
|
|
|
32
33
|
this.prefix = prefix || defaultPrefix;
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
35
37
|
async request(service: string, method: string, data: any, headers?: any): Promise<any> {
|
|
36
38
|
const path = `${this.prefix}/${this.pkg}.${service}/${method}`;
|
|
37
39
|
const url = new URL(path, this.host);
|
package/src/WebhookReceiver.ts
CHANGED
|
@@ -37,7 +37,7 @@ export type WebhookEventNames =
|
|
|
37
37
|
| 'ingress_ended'
|
|
38
38
|
/**
|
|
39
39
|
* @internal
|
|
40
|
-
* @
|
|
40
|
+
* @remarks only used as a default value, not a valid webhook event
|
|
41
41
|
*/
|
|
42
42
|
| '';
|
|
43
43
|
|
|
@@ -49,10 +49,9 @@ export class WebhookReceiver {
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
/**
|
|
52
|
-
*
|
|
53
|
-
* @param
|
|
54
|
-
* @param
|
|
55
|
-
* @param skipAuth true to skip auth validation
|
|
52
|
+
* @param body - string of the posted body
|
|
53
|
+
* @param authHeader - `Authorization` header from the request
|
|
54
|
+
* @param skipAuth - true to skip auth validation
|
|
56
55
|
* @returns
|
|
57
56
|
*/
|
|
58
57
|
async receive(
|
package/src/grants.test.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
import { TrackSource } from '@livekit/protocol';
|
|
5
5
|
import { describe, expect, it } from 'vitest';
|
|
6
|
-
import { ClaimGrants, VideoGrant
|
|
6
|
+
import type { ClaimGrants, VideoGrant } from './grants';
|
|
7
|
+
import { claimsToJwtPayload } from './grants';
|
|
7
8
|
|
|
8
9
|
describe('ClaimGrants are parsed correctly', () => {
|
|
9
10
|
it('parses TrackSource correctly to strings', () => {
|
package/src/grants.ts
CHANGED
|
@@ -22,6 +22,7 @@ export function trackSourceToString(source: TrackSource) {
|
|
|
22
22
|
export function claimsToJwtPayload(
|
|
23
23
|
grant: ClaimGrants,
|
|
24
24
|
): JWTPayload & { video?: Record<string, unknown> } {
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
26
|
const claim: Record<string, any> = { ...grant };
|
|
26
27
|
// eslint-disable-next-line no-restricted-syntax
|
|
27
28
|
if (Array.isArray(claim.video?.canPublishSources)) {
|
|
@@ -85,6 +86,9 @@ export interface VideoGrant {
|
|
|
85
86
|
|
|
86
87
|
/** participant allowed to connect to LiveKit as Agent Framework worker */
|
|
87
88
|
agent?: boolean;
|
|
89
|
+
|
|
90
|
+
/** allow participant to subscribe to metrics */
|
|
91
|
+
canSubscribeMetrics?: boolean;
|
|
88
92
|
}
|
|
89
93
|
|
|
90
94
|
export interface SIPGrant {
|