livekit-server-sdk 2.14.0 → 2.14.2

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.
Files changed (80) hide show
  1. package/dist/AccessToken.cjs +7 -0
  2. package/dist/AccessToken.cjs.map +1 -1
  3. package/dist/AccessToken.d.cts +6 -1
  4. package/dist/AccessToken.d.ts +6 -1
  5. package/dist/AccessToken.d.ts.map +1 -1
  6. package/dist/AccessToken.js +7 -0
  7. package/dist/AccessToken.js.map +1 -1
  8. package/dist/AgentDispatchClient.cjs +4 -2
  9. package/dist/AgentDispatchClient.cjs.map +1 -1
  10. package/dist/AgentDispatchClient.d.cts +3 -1
  11. package/dist/AgentDispatchClient.d.ts +3 -1
  12. package/dist/AgentDispatchClient.d.ts.map +1 -1
  13. package/dist/AgentDispatchClient.js +4 -2
  14. package/dist/AgentDispatchClient.js.map +1 -1
  15. package/dist/ClientOptions.cjs +17 -0
  16. package/dist/ClientOptions.cjs.map +1 -0
  17. package/dist/ClientOptions.d.cts +11 -0
  18. package/dist/ClientOptions.d.ts +10 -0
  19. package/dist/ClientOptions.d.ts.map +1 -0
  20. package/dist/ClientOptions.js +1 -0
  21. package/dist/ClientOptions.js.map +1 -0
  22. package/dist/EgressClient.cjs +4 -2
  23. package/dist/EgressClient.cjs.map +1 -1
  24. package/dist/EgressClient.d.cts +3 -1
  25. package/dist/EgressClient.d.ts +3 -1
  26. package/dist/EgressClient.d.ts.map +1 -1
  27. package/dist/EgressClient.js +4 -2
  28. package/dist/EgressClient.js.map +1 -1
  29. package/dist/IngressClient.cjs +4 -2
  30. package/dist/IngressClient.cjs.map +1 -1
  31. package/dist/IngressClient.d.cts +3 -1
  32. package/dist/IngressClient.d.ts +3 -1
  33. package/dist/IngressClient.d.ts.map +1 -1
  34. package/dist/IngressClient.js +4 -2
  35. package/dist/IngressClient.js.map +1 -1
  36. package/dist/RoomServiceClient.cjs +4 -2
  37. package/dist/RoomServiceClient.cjs.map +1 -1
  38. package/dist/RoomServiceClient.d.cts +3 -1
  39. package/dist/RoomServiceClient.d.ts +3 -1
  40. package/dist/RoomServiceClient.d.ts.map +1 -1
  41. package/dist/RoomServiceClient.js +4 -2
  42. package/dist/RoomServiceClient.js.map +1 -1
  43. package/dist/SipClient.cjs +11 -5
  44. package/dist/SipClient.cjs.map +1 -1
  45. package/dist/SipClient.d.cts +10 -3
  46. package/dist/SipClient.d.ts +10 -3
  47. package/dist/SipClient.d.ts.map +1 -1
  48. package/dist/SipClient.js +13 -5
  49. package/dist/SipClient.js.map +1 -1
  50. package/dist/TwirpRPC.cjs +5 -3
  51. package/dist/TwirpRPC.cjs.map +1 -1
  52. package/dist/TwirpRPC.d.cts +8 -1
  53. package/dist/TwirpRPC.d.ts +9 -1
  54. package/dist/TwirpRPC.d.ts.map +1 -1
  55. package/dist/TwirpRPC.js +5 -3
  56. package/dist/TwirpRPC.js.map +1 -1
  57. package/dist/grants.cjs.map +1 -1
  58. package/dist/grants.d.cts +6 -1
  59. package/dist/grants.d.ts +5 -0
  60. package/dist/grants.d.ts.map +1 -1
  61. package/dist/grants.js.map +1 -1
  62. package/dist/index.cjs +19 -0
  63. package/dist/index.cjs.map +1 -1
  64. package/dist/index.d.cts +4 -2
  65. package/dist/index.d.ts +2 -1
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +18 -0
  68. package/dist/index.js.map +1 -1
  69. package/package.json +2 -2
  70. package/src/AccessToken.ts +15 -1
  71. package/src/AgentDispatchClient.ts +7 -2
  72. package/src/ClientOptions.ts +13 -0
  73. package/src/EgressClient.ts +7 -2
  74. package/src/IngressClient.ts +7 -2
  75. package/src/RoomServiceClient.ts +7 -2
  76. package/src/SipClient.ts +18 -2
  77. package/src/TwirpRPC.ts +14 -3
  78. package/src/grants.test.ts +13 -1
  79. package/src/grants.ts +6 -0
  80. package/src/index.ts +9 -0
@@ -22,6 +22,7 @@ import {
22
22
  UpdateRoomMetadataRequest,
23
23
  UpdateSubscriptionsRequest,
24
24
  } from '@livekit/protocol';
25
+ import type { ClientOptions } from './ClientOptions.js';
25
26
  import { ServiceBase } from './ServiceBase.js';
26
27
  import type { Rpc } from './TwirpRPC.js';
27
28
  import { TwirpRpc, livekitPackage } from './TwirpRPC.js';
@@ -120,10 +121,14 @@ export class RoomServiceClient extends ServiceBase {
120
121
  * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
121
122
  * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
122
123
  * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
124
+ * @param options - client options
123
125
  */
124
- constructor(host: string, apiKey?: string, secret?: string) {
126
+ constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {
125
127
  super(apiKey, secret);
126
- this.rpc = new TwirpRpc(host, livekitPackage);
128
+ const rpcOptions = options?.requestTimeout
129
+ ? { requestTimeout: options.requestTimeout }
130
+ : undefined;
131
+ this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);
127
132
  }
128
133
 
129
134
  /**
package/src/SipClient.ts CHANGED
@@ -29,6 +29,8 @@ import {
29
29
  SIPDispatchRuleIndividual,
30
30
  SIPDispatchRuleInfo,
31
31
  SIPInboundTrunkInfo,
32
+ SIPMediaEncryption,
33
+ SIPOutboundConfig,
32
34
  SIPOutboundTrunkInfo,
33
35
  SIPParticipantInfo,
34
36
  SIPTransport,
@@ -38,6 +40,7 @@ import {
38
40
  UpdateSIPInboundTrunkRequest,
39
41
  UpdateSIPOutboundTrunkRequest,
40
42
  } from '@livekit/protocol';
43
+ import type { ClientOptions } from './ClientOptions.js';
41
44
  import { ServiceBase } from './ServiceBase.js';
42
45
  import type { Rpc } from './TwirpRPC.js';
43
46
  import { TwirpRpc, livekitPackage } from './TwirpRPC.js';
@@ -77,6 +80,7 @@ export interface CreateSipInboundTrunkOptions {
77
80
  // Map SIP response headers from INVITE to sip.h.* participant attributes automatically.
78
81
  includeHeaders?: SIPHeaderOptions;
79
82
  krispEnabled?: boolean;
83
+ mediaEncryption?: SIPMediaEncryption;
80
84
  }
81
85
  export interface CreateSipOutboundTrunkOptions {
82
86
  metadata?: string;
@@ -92,6 +96,7 @@ export interface CreateSipOutboundTrunkOptions {
92
96
  headersToAttributes?: { [key: string]: string };
93
97
  // Map SIP response headers from INVITE to sip.h.* participant attributes automatically.
94
98
  includeHeaders?: SIPHeaderOptions;
99
+ mediaEncryption?: SIPMediaEncryption;
95
100
  }
96
101
 
97
102
  export interface SipDispatchRuleDirect {
@@ -187,6 +192,7 @@ export interface SipInboundTrunkUpdateOptions {
187
192
  authPassword?: string;
188
193
  name?: string;
189
194
  metadata?: string;
195
+ mediaEncryption?: SIPMediaEncryption;
190
196
  }
191
197
 
192
198
  export interface SipOutboundTrunkUpdateOptions {
@@ -198,6 +204,7 @@ export interface SipOutboundTrunkUpdateOptions {
198
204
  destinationCountry?: string;
199
205
  name?: string;
200
206
  metadata?: string;
207
+ mediaEncryption?: SIPMediaEncryption;
201
208
  }
202
209
 
203
210
  export interface TransferSipParticipantOptions {
@@ -215,10 +222,14 @@ export class SipClient extends ServiceBase {
215
222
  * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
216
223
  * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
217
224
  * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
225
+ * @param options - client options
218
226
  */
219
- constructor(host: string, apiKey?: string, secret?: string) {
227
+ constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {
220
228
  super(apiKey, secret);
221
- this.rpc = new TwirpRpc(host, livekitPackage);
229
+ const rpcOptions = options?.requestTimeout
230
+ ? { requestTimeout: options.requestTimeout }
231
+ : undefined;
232
+ this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);
222
233
  }
223
234
 
224
235
  /**
@@ -300,6 +311,7 @@ export class SipClient extends ServiceBase {
300
311
  headersToAttributes: opts.headersToAttributes,
301
312
  includeHeaders: opts.includeHeaders,
302
313
  krispEnabled: opts.krispEnabled,
314
+ mediaEncryption: opts.mediaEncryption,
303
315
  }),
304
316
  }).toJson();
305
317
 
@@ -346,6 +358,7 @@ export class SipClient extends ServiceBase {
346
358
  headersToAttributes: opts.headersToAttributes,
347
359
  includeHeaders: opts.includeHeaders,
348
360
  destinationCountry: opts.destinationCountry,
361
+ mediaEncryption: opts.mediaEncryption,
349
362
  }),
350
363
  }).toJson();
351
364
 
@@ -698,6 +711,7 @@ export class SipClient extends ServiceBase {
698
711
  * @param number - number to dial
699
712
  * @param roomName - room to attach the call to
700
713
  * @param opts - CreateSipParticipantOptions
714
+ * @param outboundTrunkConfig - Optional outbound trunk configuration for sip participant.
701
715
  * @returns Created SIP participant
702
716
  */
703
717
  async createSipParticipant(
@@ -705,6 +719,7 @@ export class SipClient extends ServiceBase {
705
719
  number: string,
706
720
  roomName: string,
707
721
  opts?: CreateSipParticipantOptions,
722
+ outboundTrunkConfig?: SIPOutboundConfig,
708
723
  ): Promise<SIPParticipantInfo> {
709
724
  if (opts === undefined) {
710
725
  opts = {};
@@ -716,6 +731,7 @@ export class SipClient extends ServiceBase {
716
731
 
717
732
  const req = new CreateSIPParticipantRequest({
718
733
  sipTrunkId: sipTrunkId,
734
+ trunk: outboundTrunkConfig,
719
735
  sipCallTo: number,
720
736
  sipNumber: opts.fromNumber,
721
737
  roomName: roomName,
package/src/TwirpRPC.ts CHANGED
@@ -5,7 +5,15 @@ import type { JsonValue } from '@bufbuild/protobuf';
5
5
 
6
6
  // twirp RPC adapter for client implementation
7
7
 
8
+ type Options = {
9
+ /** Prefix for the RPC requests */
10
+ prefix?: string;
11
+ /** Timeout for fetch requests, in seconds. Must be within the valid range for abort signal timeouts. */
12
+ requestTimeout?: number;
13
+ };
14
+
8
15
  const defaultPrefix = '/twirp';
16
+ const defaultTimeoutSeconds = 60;
9
17
 
10
18
  export const livekitPackage = 'livekit';
11
19
  export interface Rpc {
@@ -48,13 +56,16 @@ export class TwirpRpc {
48
56
 
49
57
  prefix: string;
50
58
 
51
- constructor(host: string, pkg: string, prefix?: string) {
59
+ requestTimeout: number;
60
+
61
+ constructor(host: string, pkg: string, options?: Options) {
52
62
  if (host.startsWith('ws')) {
53
63
  host = host.replace('ws', 'http');
54
64
  }
55
65
  this.host = host;
56
66
  this.pkg = pkg;
57
- this.prefix = prefix || defaultPrefix;
67
+ this.requestTimeout = options?.requestTimeout ?? defaultTimeoutSeconds;
68
+ this.prefix = options?.prefix || defaultPrefix;
58
69
  }
59
70
 
60
71
  async request(
@@ -62,7 +73,7 @@ export class TwirpRpc {
62
73
  method: string,
63
74
  data: any, // eslint-disable-line @typescript-eslint/no-explicit-any
64
75
  headers: any, // eslint-disable-line @typescript-eslint/no-explicit-any
65
- timeout = 60,
76
+ timeout = this.requestTimeout,
66
77
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
67
78
  ): Promise<any> {
68
79
  const path = `${this.prefix}/${this.pkg}.${service}/${method}`;
@@ -3,7 +3,7 @@
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 type { ClaimGrants, VideoGrant } from './grants.js';
6
+ import type { ClaimGrants, ObservabilityGrant, VideoGrant } from './grants.js';
7
7
  import { claimsToJwtPayload } from './grants.js';
8
8
 
9
9
  describe('ClaimGrants are parsed correctly', () => {
@@ -28,4 +28,16 @@ describe('ClaimGrants are parsed correctly', () => {
28
28
  'screen_share_audio',
29
29
  ]);
30
30
  });
31
+
32
+ it('parses ObservabilityGrant correctly', () => {
33
+ const grant: ObservabilityGrant = {
34
+ write: true,
35
+ };
36
+
37
+ const claim: ClaimGrants = { observability: grant };
38
+
39
+ const jwtPayload = claimsToJwtPayload(claim);
40
+ expect(jwtPayload.observability).toBeTypeOf('object');
41
+ expect((jwtPayload.observability as ObservabilityGrant)?.write).toBe(true);
42
+ });
31
43
  });
package/src/grants.ts CHANGED
@@ -108,12 +108,18 @@ export interface InferenceGrant {
108
108
  perform?: boolean;
109
109
  }
110
110
 
111
+ export interface ObservabilityGrant {
112
+ /** write grants to publish observability data */
113
+ write?: boolean;
114
+ }
115
+
111
116
  /** @internal */
112
117
  export interface ClaimGrants extends JWTPayload {
113
118
  name?: string;
114
119
  video?: VideoGrant;
115
120
  sip?: SIPGrant;
116
121
  inference?: InferenceGrant;
122
+ observability?: ObservabilityGrant;
117
123
  kind?: string;
118
124
  metadata?: string;
119
125
  attributes?: Record<string, string>;
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  export {
6
6
  AliOSSUpload,
7
+ AgentDispatch,
7
8
  AudioCodec,
8
9
  AutoParticipantEgress,
9
10
  AutoTrackEgress,
@@ -36,11 +37,18 @@ export {
36
37
  Room,
37
38
  RoomAgentDispatch,
38
39
  RoomCompositeEgressRequest,
40
+ RoomConfiguration,
39
41
  RoomEgress,
40
42
  S3Upload,
43
+ SIPDispatchRule,
41
44
  SIPDispatchRuleInfo,
45
+ SIPDispatchRuleDirect,
46
+ SIPDispatchRuleIndividual,
42
47
  SIPParticipantInfo,
48
+ SIPOutboundTrunkInfo,
49
+ SIPInboundTrunkInfo,
43
50
  SIPTrunkInfo,
51
+ SIPCallStatus,
44
52
  SegmentedFileOutput,
45
53
  SegmentedFileProtocol,
46
54
  StreamOutput,
@@ -61,4 +69,5 @@ export * from './grants.js';
61
69
  export * from './IngressClient.js';
62
70
  export * from './RoomServiceClient.js';
63
71
  export * from './SipClient.js';
72
+ export { TwirpError } from './TwirpRPC.js';
64
73
  export * from './WebhookReceiver.js';