livekit-server-sdk 2.13.3 → 2.14.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.
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 +8 -2
  39. package/dist/RoomServiceClient.d.ts +8 -2
  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 +8 -3
  44. package/dist/SipClient.cjs.map +1 -1
  45. package/dist/SipClient.d.cts +8 -3
  46. package/dist/SipClient.d.ts +8 -3
  47. package/dist/SipClient.d.ts.map +1 -1
  48. package/dist/SipClient.js +9 -3
  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 +2 -0
  63. package/dist/index.cjs.map +1 -1
  64. package/dist/index.d.cts +3 -2
  65. package/dist/index.d.ts +1 -1
  66. package/dist/index.d.ts.map +1 -1
  67. package/dist/index.js +2 -0
  68. package/dist/index.js.map +1 -1
  69. package/package.json +3 -3
  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 +13 -3
  76. package/src/SipClient.ts +14 -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 +1 -0
@@ -8,6 +8,7 @@ import {
8
8
  ListAgentDispatchRequest,
9
9
  ListAgentDispatchResponse,
10
10
  } from '@livekit/protocol';
11
+ import type { ClientOptions } from './ClientOptions.js';
11
12
  import { ServiceBase } from './ServiceBase.js';
12
13
  import { type Rpc, TwirpRpc, livekitPackage } from './TwirpRPC.js';
13
14
 
@@ -29,10 +30,14 @@ export class AgentDispatchClient extends ServiceBase {
29
30
  * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
30
31
  * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
31
32
  * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
33
+ * @param options - client options
32
34
  */
33
- constructor(host: string, apiKey?: string, secret?: string) {
35
+ constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {
34
36
  super(apiKey, secret);
35
- this.rpc = new TwirpRpc(host, livekitPackage);
37
+ const rpcOptions = options?.requestTimeout
38
+ ? { requestTimeout: options.requestTimeout }
39
+ : undefined;
40
+ this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);
36
41
  }
37
42
 
38
43
  /**
@@ -0,0 +1,13 @@
1
+ // SPDX-FileCopyrightText: 2024 LiveKit, Inc.
2
+ //
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ /**
6
+ * Options common to all clients
7
+ */
8
+ export type ClientOptions = {
9
+ /**
10
+ * Optional timeout, in seconds, for all server requests
11
+ */
12
+ requestTimeout?: number;
13
+ };
@@ -25,6 +25,7 @@ import {
25
25
  UpdateStreamRequest,
26
26
  WebEgressRequest,
27
27
  } from '@livekit/protocol';
28
+ import type { ClientOptions } from './ClientOptions.js';
28
29
  import { ServiceBase } from './ServiceBase.js';
29
30
  import type { Rpc } from './TwirpRPC.js';
30
31
  import { TwirpRpc, livekitPackage } from './TwirpRPC.js';
@@ -137,10 +138,14 @@ export class EgressClient extends ServiceBase {
137
138
  * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
138
139
  * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
139
140
  * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
141
+ * @param options - client options
140
142
  */
141
- constructor(host: string, apiKey?: string, secret?: string) {
143
+ constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {
142
144
  super(apiKey, secret);
143
- this.rpc = new TwirpRpc(host, livekitPackage);
145
+ const rpcOptions = options?.requestTimeout
146
+ ? { requestTimeout: options.requestTimeout }
147
+ : undefined;
148
+ this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);
144
149
  }
145
150
 
146
151
  /**
@@ -10,6 +10,7 @@ import {
10
10
  ListIngressResponse,
11
11
  UpdateIngressRequest,
12
12
  } from '@livekit/protocol';
13
+ import type { ClientOptions } from './ClientOptions.js';
13
14
  import { ServiceBase } from './ServiceBase.js';
14
15
  import type { Rpc } from './TwirpRPC.js';
15
16
  import { TwirpRpc, livekitPackage } from './TwirpRPC.js';
@@ -124,10 +125,14 @@ export class IngressClient extends ServiceBase {
124
125
  * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
125
126
  * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
126
127
  * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
128
+ * @param options - client options
127
129
  */
128
- constructor(host: string, apiKey?: string, secret?: string) {
130
+ constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {
129
131
  super(apiKey, secret);
130
- this.rpc = new TwirpRpc(host, livekitPackage);
132
+ const rpcOptions = options?.requestTimeout
133
+ ? { requestTimeout: options.requestTimeout }
134
+ : undefined;
135
+ this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);
131
136
  }
132
137
 
133
138
  /**
@@ -1,7 +1,7 @@
1
1
  // SPDX-FileCopyrightText: 2024 LiveKit, Inc.
2
2
  //
3
3
  // SPDX-License-Identifier: Apache-2.0
4
- import type { DataPacket_Kind, RoomEgress, TrackInfo } from '@livekit/protocol';
4
+ import type { DataPacket_Kind, RoomAgentDispatch, RoomEgress, TrackInfo } from '@livekit/protocol';
5
5
  import {
6
6
  CreateRoomRequest,
7
7
  DeleteRoomRequest,
@@ -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';
@@ -79,6 +80,11 @@ export interface CreateOptions {
79
80
  */
80
81
  syncStreams?: boolean;
81
82
 
83
+ /**
84
+ * agents that should be dispatched to this room
85
+ */
86
+ agents?: RoomAgentDispatch[];
87
+
82
88
  /**
83
89
  * override the node room is allocated to, for debugging
84
90
  * does not work with Cloud
@@ -115,10 +121,14 @@ export class RoomServiceClient extends ServiceBase {
115
121
  * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
116
122
  * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
117
123
  * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
124
+ * @param options - client options
118
125
  */
119
- constructor(host: string, apiKey?: string, secret?: string) {
126
+ constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {
120
127
  super(apiKey, secret);
121
- 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);
122
132
  }
123
133
 
124
134
  /**
package/src/SipClient.ts CHANGED
@@ -29,6 +29,7 @@ import {
29
29
  SIPDispatchRuleIndividual,
30
30
  SIPDispatchRuleInfo,
31
31
  SIPInboundTrunkInfo,
32
+ SIPOutboundConfig,
32
33
  SIPOutboundTrunkInfo,
33
34
  SIPParticipantInfo,
34
35
  SIPTransport,
@@ -38,6 +39,7 @@ import {
38
39
  UpdateSIPInboundTrunkRequest,
39
40
  UpdateSIPOutboundTrunkRequest,
40
41
  } from '@livekit/protocol';
42
+ import type { ClientOptions } from './ClientOptions.js';
41
43
  import { ServiceBase } from './ServiceBase.js';
42
44
  import type { Rpc } from './TwirpRPC.js';
43
45
  import { TwirpRpc, livekitPackage } from './TwirpRPC.js';
@@ -123,6 +125,8 @@ export interface CreateSipParticipantOptions {
123
125
  participantIdentity?: string;
124
126
  /** Optional name of the participant */
125
127
  participantName?: string;
128
+ /** Optional display name for the SIP participant */
129
+ displayName?: string;
126
130
  /** Optional metadata to attach to the participant */
127
131
  participantMetadata?: string;
128
132
  /** Optional attributes to attach to the participant */
@@ -213,10 +217,14 @@ export class SipClient extends ServiceBase {
213
217
  * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
214
218
  * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
215
219
  * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
220
+ * @param options - client options
216
221
  */
217
- constructor(host: string, apiKey?: string, secret?: string) {
222
+ constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {
218
223
  super(apiKey, secret);
219
- this.rpc = new TwirpRpc(host, livekitPackage);
224
+ const rpcOptions = options?.requestTimeout
225
+ ? { requestTimeout: options.requestTimeout }
226
+ : undefined;
227
+ this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);
220
228
  }
221
229
 
222
230
  /**
@@ -696,6 +704,7 @@ export class SipClient extends ServiceBase {
696
704
  * @param number - number to dial
697
705
  * @param roomName - room to attach the call to
698
706
  * @param opts - CreateSipParticipantOptions
707
+ * @param outboundTrunkConfig - Optional outbound trunk configuration for sip participant.
699
708
  * @returns Created SIP participant
700
709
  */
701
710
  async createSipParticipant(
@@ -703,6 +712,7 @@ export class SipClient extends ServiceBase {
703
712
  number: string,
704
713
  roomName: string,
705
714
  opts?: CreateSipParticipantOptions,
715
+ outboundTrunkConfig?: SIPOutboundConfig,
706
716
  ): Promise<SIPParticipantInfo> {
707
717
  if (opts === undefined) {
708
718
  opts = {};
@@ -714,11 +724,13 @@ export class SipClient extends ServiceBase {
714
724
 
715
725
  const req = new CreateSIPParticipantRequest({
716
726
  sipTrunkId: sipTrunkId,
727
+ trunk: outboundTrunkConfig,
717
728
  sipCallTo: number,
718
729
  sipNumber: opts.fromNumber,
719
730
  roomName: roomName,
720
731
  participantIdentity: opts.participantIdentity || 'sip-participant',
721
732
  participantName: opts.participantName,
733
+ displayName: opts.displayName,
722
734
  participantMetadata: opts.participantMetadata,
723
735
  participantAttributes: opts.participantAttributes,
724
736
  dtmf: opts.dtmf,
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
@@ -34,6 +34,7 @@ export {
34
34
  ParticipantInfo_State,
35
35
  ParticipantPermission,
36
36
  Room,
37
+ RoomAgentDispatch,
37
38
  RoomCompositeEgressRequest,
38
39
  RoomEgress,
39
40
  S3Upload,