livekit-server-sdk 2.14.0 → 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 (73) 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 +7 -3
  44. package/dist/SipClient.cjs.map +1 -1
  45. package/dist/SipClient.d.cts +6 -3
  46. package/dist/SipClient.d.ts +6 -3
  47. package/dist/SipClient.d.ts.map +1 -1
  48. package/dist/SipClient.js +8 -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.d.cts +2 -1
  63. package/package.json +2 -2
  64. package/src/AccessToken.ts +15 -1
  65. package/src/AgentDispatchClient.ts +7 -2
  66. package/src/ClientOptions.ts +13 -0
  67. package/src/EgressClient.ts +7 -2
  68. package/src/IngressClient.ts +7 -2
  69. package/src/RoomServiceClient.ts +7 -2
  70. package/src/SipClient.ts +11 -2
  71. package/src/TwirpRPC.ts +14 -3
  72. package/src/grants.test.ts +13 -1
  73. package/src/grants.ts +6 -0
@@ -1 +1 @@
1
- {"version":3,"file":"TwirpRPC.d.ts","sourceRoot":"","sources":["../src/TwirpRPC.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAMpD,eAAO,MAAM,cAAc,YAAY,CAAC;AACxC,MAAM,WAAW,GAAG;IAClB,OAAO,CACL,OAAO,EAA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O,CACL,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,GAAG,EAAE,yDAAyD;IACvE,OAAO,CAAC,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAAC;CACpB;AAED,qBAAa,UAAW,SAAQ,KAAK;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;gBAGhC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,MAAM,EACb,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;CAQpC;AAED;;GAEG;AACH,qBAAa,QAAQ;IACnB,IAAI,EAAE,MAAM,CAAC;IAEb,GAAG,EAAE,MAAM,CAAC;IAEZ,MAAM,EAAE,MAAM,CAAC;IAEf,cAAc,EAAE,MAAM,CAAC;gBAEX,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;IAUlD,OAAO,CACX,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,GAAG,EAAE,yDAAyD;IACpE,OAAO,EAAE,GAAG,EAAE,yDAAyD;IACvE,OAAO,SAAsB,GAE5B,OAAO,CAAC,GAAG,CAAC;CAkDhB"}
package/dist/TwirpRPC.js CHANGED
@@ -1,4 +1,5 @@
1
1
  const defaultPrefix = "/twirp";
2
+ const defaultTimeoutSeconds = 60;
2
3
  const livekitPackage = "livekit";
3
4
  class TwirpError extends Error {
4
5
  constructor(name, message, status, code, metadata) {
@@ -10,15 +11,16 @@ class TwirpError extends Error {
10
11
  }
11
12
  }
12
13
  class TwirpRpc {
13
- constructor(host, pkg, prefix) {
14
+ constructor(host, pkg, options) {
14
15
  if (host.startsWith("ws")) {
15
16
  host = host.replace("ws", "http");
16
17
  }
17
18
  this.host = host;
18
19
  this.pkg = pkg;
19
- this.prefix = prefix || defaultPrefix;
20
+ this.requestTimeout = (options == null ? void 0 : options.requestTimeout) ?? defaultTimeoutSeconds;
21
+ this.prefix = (options == null ? void 0 : options.prefix) || defaultPrefix;
20
22
  }
21
- async request(service, method, data, headers, timeout = 60) {
23
+ async request(service, method, data, headers, timeout = this.requestTimeout) {
22
24
  const path = `${this.prefix}/${this.pkg}.${service}/${method}`;
23
25
  const url = new URL(path, this.host);
24
26
  const init = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/TwirpRPC.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { JsonValue } from '@bufbuild/protobuf';\n\n// twirp RPC adapter for client implementation\n\nconst defaultPrefix = '/twirp';\n\nexport const livekitPackage = 'livekit';\nexport interface Rpc {\n request(\n service: string,\n method: string,\n data: JsonValue,\n headers: any, // eslint-disable-line @typescript-eslint/no-explicit-any\n timeout?: number,\n ): Promise<string>;\n}\n\nexport class TwirpError extends Error {\n status: number;\n code?: string;\n metadata?: Record<string, string>;\n\n constructor(\n name: string,\n message: string,\n status: number,\n code?: string,\n metadata?: Record<string, string>,\n ) {\n super(message);\n this.name = name;\n this.status = status;\n this.code = code;\n this.metadata = metadata;\n }\n}\n\n/**\n * JSON based Twirp V7 RPC\n */\nexport class TwirpRpc {\n host: string;\n\n pkg: string;\n\n prefix: string;\n\n constructor(host: string, pkg: string, prefix?: string) {\n if (host.startsWith('ws')) {\n host = host.replace('ws', 'http');\n }\n this.host = host;\n this.pkg = pkg;\n this.prefix = prefix || defaultPrefix;\n }\n\n async request(\n service: string,\n method: string,\n data: any, // eslint-disable-line @typescript-eslint/no-explicit-any\n headers: any, // eslint-disable-line @typescript-eslint/no-explicit-any\n timeout = 60,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n const path = `${this.prefix}/${this.pkg}.${service}/${method}`;\n const url = new URL(path, this.host);\n const init: RequestInit = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json;charset=UTF-8',\n ...headers,\n },\n body: JSON.stringify(data),\n };\n\n if (timeout) {\n init.signal = AbortSignal.timeout(timeout * 1000);\n }\n\n const response = await fetch(url, init);\n\n if (!response.ok) {\n const isJson = response.headers.get('content-type') === 'application/json';\n let errorMessage = 'Unknown internal error';\n let errorCode: string | undefined = undefined;\n let metadata: Record<string, string> | undefined = undefined;\n try {\n if (isJson) {\n const parsedError = (await response.json()) as Record<string, unknown>;\n if ('msg' in parsedError) {\n errorMessage = <string>parsedError.msg;\n }\n if ('code' in parsedError) {\n errorCode = <string>parsedError.code;\n }\n if ('meta' in parsedError) {\n metadata = <Record<string, string>>parsedError.meta;\n }\n } else {\n errorMessage = await response.text();\n }\n } catch (e) {\n // parsing went wrong, no op and we keep default error message\n console.debug(`Error when trying to parse error message, using defaults`, e);\n }\n\n throw new TwirpError(response.statusText, errorMessage, response.status, errorCode, metadata);\n }\n const parsedResp = (await response.json()) as Record<string, unknown>;\n\n const camelcaseKeys = await import('camelcase-keys').then((mod) => mod.default);\n return camelcaseKeys(parsedResp, { deep: true });\n }\n}\n"],"mappings":"AAOA,MAAM,gBAAgB;AAEf,MAAM,iBAAiB;AAWvB,MAAM,mBAAmB,MAAM;AAAA,EAKpC,YACE,MACA,SACA,QACA,MACA,UACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EAClB;AACF;AAKO,MAAM,SAAS;AAAA,EAOpB,YAAY,MAAc,KAAa,QAAiB;AACtD,QAAI,KAAK,WAAW,IAAI,GAAG;AACzB,aAAO,KAAK,QAAQ,MAAM,MAAM;AAAA,IAClC;AACA,SAAK,OAAO;AACZ,SAAK,MAAM;AACX,SAAK,SAAS,UAAU;AAAA,EAC1B;AAAA,EAEA,MAAM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ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { JsonValue } from '@bufbuild/protobuf';\n\n// twirp RPC adapter for client implementation\n\ntype Options = {\n /** Prefix for the RPC requests */\n prefix?: string;\n /** Timeout for fetch requests, in seconds. Must be within the valid range for abort signal timeouts. */\n requestTimeout?: number;\n};\n\nconst defaultPrefix = '/twirp';\nconst defaultTimeoutSeconds = 60;\n\nexport const livekitPackage = 'livekit';\nexport interface Rpc {\n request(\n service: string,\n method: string,\n data: JsonValue,\n headers: any, // eslint-disable-line @typescript-eslint/no-explicit-any\n timeout?: number,\n ): Promise<string>;\n}\n\nexport class TwirpError extends Error {\n status: number;\n code?: string;\n metadata?: Record<string, string>;\n\n constructor(\n name: string,\n message: string,\n status: number,\n code?: string,\n metadata?: Record<string, string>,\n ) {\n super(message);\n this.name = name;\n this.status = status;\n this.code = code;\n this.metadata = metadata;\n }\n}\n\n/**\n * JSON based Twirp V7 RPC\n */\nexport class TwirpRpc {\n host: string;\n\n pkg: string;\n\n prefix: string;\n\n requestTimeout: number;\n\n constructor(host: string, pkg: string, options?: Options) {\n if (host.startsWith('ws')) {\n host = host.replace('ws', 'http');\n }\n this.host = host;\n this.pkg = pkg;\n this.requestTimeout = options?.requestTimeout ?? defaultTimeoutSeconds;\n this.prefix = options?.prefix || defaultPrefix;\n }\n\n async request(\n service: string,\n method: string,\n data: any, // eslint-disable-line @typescript-eslint/no-explicit-any\n headers: any, // eslint-disable-line @typescript-eslint/no-explicit-any\n timeout = this.requestTimeout,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<any> {\n const path = `${this.prefix}/${this.pkg}.${service}/${method}`;\n const url = new URL(path, this.host);\n const init: RequestInit = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json;charset=UTF-8',\n ...headers,\n },\n body: JSON.stringify(data),\n };\n\n if (timeout) {\n init.signal = AbortSignal.timeout(timeout * 1000);\n }\n\n const response = await fetch(url, init);\n\n if (!response.ok) {\n const isJson = response.headers.get('content-type') === 'application/json';\n let errorMessage = 'Unknown internal error';\n let errorCode: string | undefined = undefined;\n let metadata: Record<string, string> | undefined = undefined;\n try {\n if (isJson) {\n const parsedError = (await response.json()) as Record<string, unknown>;\n if ('msg' in parsedError) {\n errorMessage = <string>parsedError.msg;\n }\n if ('code' in parsedError) {\n errorCode = <string>parsedError.code;\n }\n if ('meta' in parsedError) {\n metadata = <Record<string, string>>parsedError.meta;\n }\n } else {\n errorMessage = await response.text();\n }\n } catch (e) {\n // parsing went wrong, no op and we keep default error message\n console.debug(`Error when trying to parse error message, using defaults`, e);\n }\n\n throw new TwirpError(response.statusText, errorMessage, response.status, errorCode, metadata);\n }\n const parsedResp = (await response.json()) as Record<string, unknown>;\n\n const camelcaseKeys = await import('camelcase-keys').then((mod) => mod.default);\n return camelcaseKeys(parsedResp, { deep: true });\n }\n}\n"],"mappings":"AAcA,MAAM,gBAAgB;AACtB,MAAM,wBAAwB;AAEvB,MAAM,iBAAiB;AAWvB,MAAM,mBAAmB,MAAM;AAAA,EAKpC,YACE,MACA,SACA,QACA,MACA,UACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EAClB;AACF;AAKO,MAAM,SAAS;AAAA,EASpB,YAAY,MAAc,KAAa,SAAmB;AACxD,QAAI,KAAK,WAAW,IAAI,GAAG;AACzB,aAAO,KAAK,QAAQ,MAAM,MAAM;AAAA,IAClC;AACA,SAAK,OAAO;AACZ,SAAK,MAAM;AACX,SAAK,kBAAiB,mCAAS,mBAAkB;AACjD,SAAK,UAAS,mCAAS,WAAU;AAAA,EACnC;AAAA,EAEA,MAAM,QACJ,SACA,QACA,MACA,SACA,UAAU,KAAK,gBAED;AACd,UAAM,OAAO,GAAG,KAAK,MAAM,IAAI,KAAK,GAAG,IAAI,OAAO,IAAI,MAAM;AAC5D,UAAM,MAAM,IAAI,IAAI,MAAM,KAAK,IAAI;AACnC,UAAM,OAAoB;AAAA,MACxB,QAAQ;AAAA,MACR,SAAS;AAAA,QACP,gBAAgB;AAAA,QAChB,GAAG;AAAA,MACL;AAAA,MACA,MAAM,KAAK,UAAU,IAAI;AAAA,IAC3B;AAEA,QAAI,SAAS;AACX,WAAK,SAAS,YAAY,QAAQ,UAAU,GAAI;AAAA,IAClD;AAEA,UAAM,WAAW,MAAM,MAAM,KAAK,IAAI;AAEtC,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,SAAS,SAAS,QAAQ,IAAI,cAAc,MAAM;AACxD,UAAI,eAAe;AACnB,UAAI,YAAgC;AACpC,UAAI,WAA+C;AACnD,UAAI;AACF,YAAI,QAAQ;AACV,gBAAM,cAAe,MAAM,SAAS,KAAK;AACzC,cAAI,SAAS,aAAa;AACxB,2BAAuB,YAAY;AAAA,UACrC;AACA,cAAI,UAAU,aAAa;AACzB,wBAAoB,YAAY;AAAA,UAClC;AACA,cAAI,UAAU,aAAa;AACzB,uBAAmC,YAAY;AAAA,UACjD;AAAA,QACF,OAAO;AACL,yBAAe,MAAM,SAAS,KAAK;AAAA,QACrC;AAAA,MACF,SAAS,GAAG;AAEV,gBAAQ,MAAM,4DAA4D,CAAC;AAAA,MAC7E;AAEA,YAAM,IAAI,WAAW,SAAS,YAAY,cAAc,SAAS,QAAQ,WAAW,QAAQ;AAAA,IAC9F;AACA,UAAM,aAAc,MAAM,SAAS,KAAK;AAExC,UAAM,gBAAgB,MAAM,OAAO,gBAAgB,EAAE,KAAK,CAAC,QAAQ,IAAI,OAAO;AAC9E,WAAO,cAAc,YAAY,EAAE,MAAM,KAAK,CAAC;AAAA,EACjD;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/grants.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RoomConfiguration } from '@livekit/protocol';\nimport { TrackSource } from '@livekit/protocol';\nimport type { JWTPayload } from 'jose';\n\nexport function trackSourceToString(source: TrackSource) {\n switch (source) {\n case TrackSource.CAMERA:\n return 'camera';\n case TrackSource.MICROPHONE:\n return 'microphone';\n case TrackSource.SCREEN_SHARE:\n return 'screen_share';\n case TrackSource.SCREEN_SHARE_AUDIO:\n return 'screen_share_audio';\n default:\n throw new TypeError(`Cannot convert TrackSource ${source} to string`);\n }\n}\n\nexport function claimsToJwtPayload(\n grant: ClaimGrants,\n): JWTPayload & { video?: Record<string, unknown> } {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const claim: Record<string, any> = { ...grant };\n // eslint-disable-next-line no-restricted-syntax\n if (Array.isArray(claim.video?.canPublishSources)) {\n claim.video.canPublishSources = claim.video.canPublishSources.map(trackSourceToString);\n }\n return claim;\n}\n\nexport interface VideoGrant {\n /** permission to create a room */\n roomCreate?: boolean;\n\n /** permission to join a room as a participant, room must be set */\n roomJoin?: boolean;\n\n /** permission to list rooms */\n roomList?: boolean;\n\n /** permission to start a recording */\n roomRecord?: boolean;\n\n /** permission to control a specific room, room must be set */\n roomAdmin?: boolean;\n\n /** name of the room, must be set for admin or join permissions */\n room?: string;\n\n /** permissions to control ingress, not specific to any room or ingress */\n ingressAdmin?: boolean;\n\n /**\n * allow participant to publish. If neither canPublish or canSubscribe is set,\n * both publish and subscribe are enabled\n */\n canPublish?: boolean;\n\n /**\n * TrackSource types that the participant is allowed to publish\n * When set, it supersedes CanPublish. Only sources explicitly set here can be published\n */\n canPublishSources?: TrackSource[];\n\n /** allow participant to subscribe to other tracks */\n canSubscribe?: boolean;\n\n /**\n * allow participants to publish data, defaults to true if not set\n */\n canPublishData?: boolean;\n\n /**\n * by default, a participant is not allowed to update its own metadata\n */\n canUpdateOwnMetadata?: boolean;\n\n /** participant isn't visible to others */\n hidden?: boolean;\n\n /** participant is recording the room, when set, allows room to indicate it's being recorded */\n recorder?: boolean;\n\n /** participant allowed to connect to LiveKit as Agent Framework worker */\n agent?: boolean;\n\n /** allow participant to subscribe to metrics */\n canSubscribeMetrics?: boolean;\n\n /** destination room which this participant can forward to */\n destinationRoom?: string;\n}\n\nexport interface SIPGrant {\n /** manage sip resources */\n admin?: boolean;\n\n /** make outbound calls */\n call?: boolean;\n}\n\nexport interface InferenceGrant {\n /** perform inference */\n perform?: boolean;\n}\n\n/** @internal */\nexport interface ClaimGrants extends JWTPayload {\n name?: string;\n video?: VideoGrant;\n sip?: SIPGrant;\n inference?: InferenceGrant;\n kind?: string;\n metadata?: string;\n attributes?: Record<string, string>;\n sha256?: string;\n roomPreset?: string;\n roomConfig?: RoomConfiguration;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAA4B;AAGrB,SAAS,oBAAoB,QAAqB;AACvD,UAAQ,QAAQ;AAAA,IACd,KAAK,4BAAY;AACf,aAAO;AAAA,IACT,KAAK,4BAAY;AACf,aAAO;AAAA,IACT,KAAK,4BAAY;AACf,aAAO;AAAA,IACT,KAAK,4BAAY;AACf,aAAO;AAAA,IACT;AACE,YAAM,IAAI,UAAU,8BAA8B,MAAM,YAAY;AAAA,EACxE;AACF;AAEO,SAAS,mBACd,OACkD;AAxBpD;AA0BE,QAAM,QAA6B,EAAE,GAAG,MAAM;AAE9C,MAAI,MAAM,SAAQ,WAAM,UAAN,mBAAa,iBAAiB,GAAG;AACjD,UAAM,MAAM,oBAAoB,MAAM,MAAM,kBAAkB,IAAI,mBAAmB;AAAA,EACvF;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/grants.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RoomConfiguration } from '@livekit/protocol';\nimport { TrackSource } from '@livekit/protocol';\nimport type { JWTPayload } from 'jose';\n\nexport function trackSourceToString(source: TrackSource) {\n switch (source) {\n case TrackSource.CAMERA:\n return 'camera';\n case TrackSource.MICROPHONE:\n return 'microphone';\n case TrackSource.SCREEN_SHARE:\n return 'screen_share';\n case TrackSource.SCREEN_SHARE_AUDIO:\n return 'screen_share_audio';\n default:\n throw new TypeError(`Cannot convert TrackSource ${source} to string`);\n }\n}\n\nexport function claimsToJwtPayload(\n grant: ClaimGrants,\n): JWTPayload & { video?: Record<string, unknown> } {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const claim: Record<string, any> = { ...grant };\n // eslint-disable-next-line no-restricted-syntax\n if (Array.isArray(claim.video?.canPublishSources)) {\n claim.video.canPublishSources = claim.video.canPublishSources.map(trackSourceToString);\n }\n return claim;\n}\n\nexport interface VideoGrant {\n /** permission to create a room */\n roomCreate?: boolean;\n\n /** permission to join a room as a participant, room must be set */\n roomJoin?: boolean;\n\n /** permission to list rooms */\n roomList?: boolean;\n\n /** permission to start a recording */\n roomRecord?: boolean;\n\n /** permission to control a specific room, room must be set */\n roomAdmin?: boolean;\n\n /** name of the room, must be set for admin or join permissions */\n room?: string;\n\n /** permissions to control ingress, not specific to any room or ingress */\n ingressAdmin?: boolean;\n\n /**\n * allow participant to publish. If neither canPublish or canSubscribe is set,\n * both publish and subscribe are enabled\n */\n canPublish?: boolean;\n\n /**\n * TrackSource types that the participant is allowed to publish\n * When set, it supersedes CanPublish. Only sources explicitly set here can be published\n */\n canPublishSources?: TrackSource[];\n\n /** allow participant to subscribe to other tracks */\n canSubscribe?: boolean;\n\n /**\n * allow participants to publish data, defaults to true if not set\n */\n canPublishData?: boolean;\n\n /**\n * by default, a participant is not allowed to update its own metadata\n */\n canUpdateOwnMetadata?: boolean;\n\n /** participant isn't visible to others */\n hidden?: boolean;\n\n /** participant is recording the room, when set, allows room to indicate it's being recorded */\n recorder?: boolean;\n\n /** participant allowed to connect to LiveKit as Agent Framework worker */\n agent?: boolean;\n\n /** allow participant to subscribe to metrics */\n canSubscribeMetrics?: boolean;\n\n /** destination room which this participant can forward to */\n destinationRoom?: string;\n}\n\nexport interface SIPGrant {\n /** manage sip resources */\n admin?: boolean;\n\n /** make outbound calls */\n call?: boolean;\n}\n\nexport interface InferenceGrant {\n /** perform inference */\n perform?: boolean;\n}\n\nexport interface ObservabilityGrant {\n /** write grants to publish observability data */\n write?: boolean;\n}\n\n/** @internal */\nexport interface ClaimGrants extends JWTPayload {\n name?: string;\n video?: VideoGrant;\n sip?: SIPGrant;\n inference?: InferenceGrant;\n observability?: ObservabilityGrant;\n kind?: string;\n metadata?: string;\n attributes?: Record<string, string>;\n sha256?: string;\n roomPreset?: string;\n roomConfig?: RoomConfiguration;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAA4B;AAGrB,SAAS,oBAAoB,QAAqB;AACvD,UAAQ,QAAQ;AAAA,IACd,KAAK,4BAAY;AACf,aAAO;AAAA,IACT,KAAK,4BAAY;AACf,aAAO;AAAA,IACT,KAAK,4BAAY;AACf,aAAO;AAAA,IACT,KAAK,4BAAY;AACf,aAAO;AAAA,IACT;AACE,YAAM,IAAI,UAAU,8BAA8B,MAAM,YAAY;AAAA,EACxE;AACF;AAEO,SAAS,mBACd,OACkD;AAxBpD;AA0BE,QAAM,QAA6B,EAAE,GAAG,MAAM;AAE9C,MAAI,MAAM,SAAQ,WAAM,UAAN,mBAAa,iBAAiB,GAAG;AACjD,UAAM,MAAM,oBAAoB,MAAM,MAAM,kBAAkB,IAAI,mBAAmB;AAAA,EACvF;AACA,SAAO;AACT;","names":[]}
package/dist/grants.d.cts CHANGED
@@ -61,12 +61,17 @@ interface InferenceGrant {
61
61
  /** perform inference */
62
62
  perform?: boolean;
63
63
  }
64
+ interface ObservabilityGrant {
65
+ /** write grants to publish observability data */
66
+ write?: boolean;
67
+ }
64
68
  /** @internal */
65
69
  interface ClaimGrants extends JWTPayload {
66
70
  name?: string;
67
71
  video?: VideoGrant;
68
72
  sip?: SIPGrant;
69
73
  inference?: InferenceGrant;
74
+ observability?: ObservabilityGrant;
70
75
  kind?: string;
71
76
  metadata?: string;
72
77
  attributes?: Record<string, string>;
@@ -75,4 +80,4 @@ interface ClaimGrants extends JWTPayload {
75
80
  roomConfig?: RoomConfiguration;
76
81
  }
77
82
 
78
- export { type ClaimGrants, type InferenceGrant, type SIPGrant, type VideoGrant, claimsToJwtPayload, trackSourceToString };
83
+ export { type ClaimGrants, type InferenceGrant, type ObservabilityGrant, type SIPGrant, type VideoGrant, claimsToJwtPayload, trackSourceToString };
package/dist/grants.d.ts CHANGED
@@ -61,12 +61,17 @@ export interface InferenceGrant {
61
61
  /** perform inference */
62
62
  perform?: boolean;
63
63
  }
64
+ export interface ObservabilityGrant {
65
+ /** write grants to publish observability data */
66
+ write?: boolean;
67
+ }
64
68
  /** @internal */
65
69
  export interface ClaimGrants extends JWTPayload {
66
70
  name?: string;
67
71
  video?: VideoGrant;
68
72
  sip?: SIPGrant;
69
73
  inference?: InferenceGrant;
74
+ observability?: ObservabilityGrant;
70
75
  kind?: string;
71
76
  metadata?: string;
72
77
  attributes?: Record<string, string>;
@@ -1 +1 @@
1
- {"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../src/grants.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAEvC,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,WAAW,mEAatD;AAED,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,WAAW,GACjB,UAAU,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,CAQlD;AAED,MAAM,WAAW,UAAU;IACzB,kCAAkC;IAClC,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB,+BAA+B;IAC/B,QAAQ,CAAC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RoomConfiguration } from '@livekit/protocol';\nimport { TrackSource } from '@livekit/protocol';\nimport type { JWTPayload } from 'jose';\n\nexport function trackSourceToString(source: TrackSource) {\n switch (source) {\n case TrackSource.CAMERA:\n return 'camera';\n case TrackSource.MICROPHONE:\n return 'microphone';\n case TrackSource.SCREEN_SHARE:\n return 'screen_share';\n case TrackSource.SCREEN_SHARE_AUDIO:\n return 'screen_share_audio';\n default:\n throw new TypeError(`Cannot convert TrackSource ${source} to string`);\n }\n}\n\nexport function claimsToJwtPayload(\n grant: ClaimGrants,\n): JWTPayload & { video?: Record<string, unknown> } {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const claim: Record<string, any> = { ...grant };\n // eslint-disable-next-line no-restricted-syntax\n if (Array.isArray(claim.video?.canPublishSources)) {\n claim.video.canPublishSources = claim.video.canPublishSources.map(trackSourceToString);\n }\n return claim;\n}\n\nexport interface VideoGrant {\n /** permission to create a room */\n roomCreate?: boolean;\n\n /** permission to join a room as a participant, room must be set */\n roomJoin?: boolean;\n\n /** permission to list rooms */\n roomList?: boolean;\n\n /** permission to start a recording */\n roomRecord?: boolean;\n\n /** permission to control a specific room, room must be set */\n roomAdmin?: boolean;\n\n /** name of the room, must be set for admin or join permissions */\n room?: string;\n\n /** permissions to control ingress, not specific to any room or ingress */\n ingressAdmin?: boolean;\n\n /**\n * allow participant to publish. If neither canPublish or canSubscribe is set,\n * both publish and subscribe are enabled\n */\n canPublish?: boolean;\n\n /**\n * TrackSource types that the participant is allowed to publish\n * When set, it supersedes CanPublish. Only sources explicitly set here can be published\n */\n canPublishSources?: TrackSource[];\n\n /** allow participant to subscribe to other tracks */\n canSubscribe?: boolean;\n\n /**\n * allow participants to publish data, defaults to true if not set\n */\n canPublishData?: boolean;\n\n /**\n * by default, a participant is not allowed to update its own metadata\n */\n canUpdateOwnMetadata?: boolean;\n\n /** participant isn't visible to others */\n hidden?: boolean;\n\n /** participant is recording the room, when set, allows room to indicate it's being recorded */\n recorder?: boolean;\n\n /** participant allowed to connect to LiveKit as Agent Framework worker */\n agent?: boolean;\n\n /** allow participant to subscribe to metrics */\n canSubscribeMetrics?: boolean;\n\n /** destination room which this participant can forward to */\n destinationRoom?: string;\n}\n\nexport interface SIPGrant {\n /** manage sip resources */\n admin?: boolean;\n\n /** make outbound calls */\n call?: boolean;\n}\n\nexport interface InferenceGrant {\n /** perform inference */\n perform?: boolean;\n}\n\n/** @internal */\nexport interface ClaimGrants extends JWTPayload {\n name?: string;\n video?: VideoGrant;\n sip?: SIPGrant;\n inference?: InferenceGrant;\n kind?: string;\n metadata?: string;\n attributes?: Record<string, string>;\n sha256?: string;\n roomPreset?: string;\n roomConfig?: RoomConfiguration;\n}\n"],"mappings":"AAIA,SAAS,mBAAmB;AAGrB,SAAS,oBAAoB,QAAqB;AACvD,UAAQ,QAAQ;AAAA,IACd,KAAK,YAAY;AACf,aAAO;AAAA,IACT,KAAK,YAAY;AACf,aAAO;AAAA,IACT,KAAK,YAAY;AACf,aAAO;AAAA,IACT,KAAK,YAAY;AACf,aAAO;AAAA,IACT;AACE,YAAM,IAAI,UAAU,8BAA8B,MAAM,YAAY;AAAA,EACxE;AACF;AAEO,SAAS,mBACd,OACkD;AAxBpD;AA0BE,QAAM,QAA6B,EAAE,GAAG,MAAM;AAE9C,MAAI,MAAM,SAAQ,WAAM,UAAN,mBAAa,iBAAiB,GAAG;AACjD,UAAM,MAAM,oBAAoB,MAAM,MAAM,kBAAkB,IAAI,mBAAmB;AAAA,EACvF;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/grants.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RoomConfiguration } from '@livekit/protocol';\nimport { TrackSource } from '@livekit/protocol';\nimport type { JWTPayload } from 'jose';\n\nexport function trackSourceToString(source: TrackSource) {\n switch (source) {\n case TrackSource.CAMERA:\n return 'camera';\n case TrackSource.MICROPHONE:\n return 'microphone';\n case TrackSource.SCREEN_SHARE:\n return 'screen_share';\n case TrackSource.SCREEN_SHARE_AUDIO:\n return 'screen_share_audio';\n default:\n throw new TypeError(`Cannot convert TrackSource ${source} to string`);\n }\n}\n\nexport function claimsToJwtPayload(\n grant: ClaimGrants,\n): JWTPayload & { video?: Record<string, unknown> } {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const claim: Record<string, any> = { ...grant };\n // eslint-disable-next-line no-restricted-syntax\n if (Array.isArray(claim.video?.canPublishSources)) {\n claim.video.canPublishSources = claim.video.canPublishSources.map(trackSourceToString);\n }\n return claim;\n}\n\nexport interface VideoGrant {\n /** permission to create a room */\n roomCreate?: boolean;\n\n /** permission to join a room as a participant, room must be set */\n roomJoin?: boolean;\n\n /** permission to list rooms */\n roomList?: boolean;\n\n /** permission to start a recording */\n roomRecord?: boolean;\n\n /** permission to control a specific room, room must be set */\n roomAdmin?: boolean;\n\n /** name of the room, must be set for admin or join permissions */\n room?: string;\n\n /** permissions to control ingress, not specific to any room or ingress */\n ingressAdmin?: boolean;\n\n /**\n * allow participant to publish. If neither canPublish or canSubscribe is set,\n * both publish and subscribe are enabled\n */\n canPublish?: boolean;\n\n /**\n * TrackSource types that the participant is allowed to publish\n * When set, it supersedes CanPublish. Only sources explicitly set here can be published\n */\n canPublishSources?: TrackSource[];\n\n /** allow participant to subscribe to other tracks */\n canSubscribe?: boolean;\n\n /**\n * allow participants to publish data, defaults to true if not set\n */\n canPublishData?: boolean;\n\n /**\n * by default, a participant is not allowed to update its own metadata\n */\n canUpdateOwnMetadata?: boolean;\n\n /** participant isn't visible to others */\n hidden?: boolean;\n\n /** participant is recording the room, when set, allows room to indicate it's being recorded */\n recorder?: boolean;\n\n /** participant allowed to connect to LiveKit as Agent Framework worker */\n agent?: boolean;\n\n /** allow participant to subscribe to metrics */\n canSubscribeMetrics?: boolean;\n\n /** destination room which this participant can forward to */\n destinationRoom?: string;\n}\n\nexport interface SIPGrant {\n /** manage sip resources */\n admin?: boolean;\n\n /** make outbound calls */\n call?: boolean;\n}\n\nexport interface InferenceGrant {\n /** perform inference */\n perform?: boolean;\n}\n\nexport interface ObservabilityGrant {\n /** write grants to publish observability data */\n write?: boolean;\n}\n\n/** @internal */\nexport interface ClaimGrants extends JWTPayload {\n name?: string;\n video?: VideoGrant;\n sip?: SIPGrant;\n inference?: InferenceGrant;\n observability?: ObservabilityGrant;\n kind?: string;\n metadata?: string;\n attributes?: Record<string, string>;\n sha256?: string;\n roomPreset?: string;\n roomConfig?: RoomConfiguration;\n}\n"],"mappings":"AAIA,SAAS,mBAAmB;AAGrB,SAAS,oBAAoB,QAAqB;AACvD,UAAQ,QAAQ;AAAA,IACd,KAAK,YAAY;AACf,aAAO;AAAA,IACT,KAAK,YAAY;AACf,aAAO;AAAA,IACT,KAAK,YAAY;AACf,aAAO;AAAA,IACT,KAAK,YAAY;AACf,aAAO;AAAA,IACT;AACE,YAAM,IAAI,UAAU,8BAA8B,MAAM,YAAY;AAAA,EACxE;AACF;AAEO,SAAS,mBACd,OACkD;AAxBpD;AA0BE,QAAM,QAA6B,EAAE,GAAG,MAAM;AAE9C,MAAI,MAAM,SAAQ,WAAM,UAAN,mBAAa,iBAAiB,GAAG;AACjD,UAAM,MAAM,oBAAoB,MAAM,MAAM,kBAAkB,IAAI,mBAAmB;AAAA,EACvF;AACA,SAAO;AACT;","names":[]}
package/dist/index.d.cts CHANGED
@@ -2,11 +2,12 @@ export { AliOSSUpload, AudioCodec, AutoParticipantEgress, AutoTrackEgress, Azure
2
2
  export { AccessToken, AccessTokenOptions, TokenVerifier } from './AccessToken.cjs';
3
3
  export { AgentDispatchClient } from './AgentDispatchClient.cjs';
4
4
  export { BaseOptions, EgressClient, EncodedOutputs, ListEgressOptions, ParticipantEgressOptions, RoomCompositeOptions, TrackCompositeOptions, WebOptions } from './EgressClient.cjs';
5
- export { ClaimGrants, InferenceGrant, SIPGrant, VideoGrant, claimsToJwtPayload, trackSourceToString } from './grants.cjs';
5
+ export { ClaimGrants, InferenceGrant, ObservabilityGrant, SIPGrant, VideoGrant, claimsToJwtPayload, trackSourceToString } from './grants.cjs';
6
6
  export { CreateIngressOptions, IngressClient, ListIngressOptions, UpdateIngressOptions } from './IngressClient.cjs';
7
7
  export { CreateOptions, RoomServiceClient, SendDataOptions, UpdateParticipantOptions } from './RoomServiceClient.cjs';
8
8
  export { CreateSipDispatchRuleOptions, CreateSipInboundTrunkOptions, CreateSipOutboundTrunkOptions, CreateSipParticipantOptions, CreateSipTrunkOptions, ListSipDispatchRuleOptions, ListSipTrunkOptions, SipClient, SipDispatchRuleDirect, SipDispatchRuleIndividual, SipDispatchRuleUpdateOptions, SipInboundTrunkUpdateOptions, SipOutboundTrunkUpdateOptions, TransferSipParticipantOptions } from './SipClient.cjs';
9
9
  export { WebhookEvent, WebhookEventNames, WebhookReceiver, authorizeHeader } from './WebhookReceiver.cjs';
10
+ import './ClientOptions.cjs';
10
11
  import './ServiceBase.cjs';
11
12
  import 'jose';
12
13
  import '@bufbuild/protobuf';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livekit-server-sdk",
3
- "version": "2.14.0",
3
+ "version": "2.14.1",
4
4
  "description": "Server-side SDK for LiveKit",
5
5
  "main": "dist/index.js",
6
6
  "require": "dist/index.cjs",
@@ -39,7 +39,7 @@
39
39
  "@edge-runtime/vm": "^5.0.0",
40
40
  "@livekit/changesets-changelog-github": "^0.0.4",
41
41
  "@types/node": "^20.10.1",
42
- "happy-dom": "^17.0.0",
42
+ "happy-dom": "^20.0.0",
43
43
  "prettier": "^3.0.0",
44
44
  "tsup": "^8.3.5",
45
45
  "typedoc": "^0.28.0",
@@ -3,7 +3,13 @@
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import type { RoomConfiguration } from '@livekit/protocol';
5
5
  import * as jose from 'jose';
6
- import type { ClaimGrants, InferenceGrant, SIPGrant, VideoGrant } from './grants.js';
6
+ import type {
7
+ ClaimGrants,
8
+ InferenceGrant,
9
+ ObservabilityGrant,
10
+ SIPGrant,
11
+ VideoGrant,
12
+ } from './grants.js';
7
13
  import { claimsToJwtPayload } from './grants.js';
8
14
 
9
15
  // 6 hours
@@ -118,6 +124,14 @@ export class AccessToken {
118
124
  this.grants.sip = { ...(this.grants.sip ?? {}), ...grant };
119
125
  }
120
126
 
127
+ /**
128
+ * Adds an observability grant to this token.
129
+ * @param grant -
130
+ */
131
+ addObservabilityGrant(grant: ObservabilityGrant) {
132
+ this.grants.observability = { ...(this.grants.observability ?? {}), ...grant };
133
+ }
134
+
121
135
  get name(): string | undefined {
122
136
  return this.grants.name;
123
137
  }
@@ -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
  /**
@@ -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,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';
@@ -215,10 +217,14 @@ export class SipClient extends ServiceBase {
215
217
  * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
216
218
  * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
217
219
  * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
220
+ * @param options - client options
218
221
  */
219
- constructor(host: string, apiKey?: string, secret?: string) {
222
+ constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {
220
223
  super(apiKey, secret);
221
- 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);
222
228
  }
223
229
 
224
230
  /**
@@ -698,6 +704,7 @@ export class SipClient extends ServiceBase {
698
704
  * @param number - number to dial
699
705
  * @param roomName - room to attach the call to
700
706
  * @param opts - CreateSipParticipantOptions
707
+ * @param outboundTrunkConfig - Optional outbound trunk configuration for sip participant.
701
708
  * @returns Created SIP participant
702
709
  */
703
710
  async createSipParticipant(
@@ -705,6 +712,7 @@ export class SipClient extends ServiceBase {
705
712
  number: string,
706
713
  roomName: string,
707
714
  opts?: CreateSipParticipantOptions,
715
+ outboundTrunkConfig?: SIPOutboundConfig,
708
716
  ): Promise<SIPParticipantInfo> {
709
717
  if (opts === undefined) {
710
718
  opts = {};
@@ -716,6 +724,7 @@ export class SipClient extends ServiceBase {
716
724
 
717
725
  const req = new CreateSIPParticipantRequest({
718
726
  sipTrunkId: sipTrunkId,
727
+ trunk: outboundTrunkConfig,
719
728
  sipCallTo: number,
720
729
  sipNumber: opts.fromNumber,
721
730
  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>;