livekit-server-sdk 2.18.0 → 2.19.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/README.md +1 -1
- package/dist/AccessToken.cjs +4 -1
- package/dist/AccessToken.cjs.map +1 -1
- package/dist/AccessToken.d.ts.map +1 -1
- package/dist/AccessToken.js +4 -1
- package/dist/AccessToken.js.map +1 -1
- package/dist/IngressClient.cjs +4 -1
- package/dist/IngressClient.cjs.map +1 -1
- package/dist/IngressClient.d.cts +10 -0
- package/dist/IngressClient.d.ts +10 -0
- package/dist/IngressClient.d.ts.map +1 -1
- package/dist/IngressClient.js +4 -1
- package/dist/IngressClient.js.map +1 -1
- package/dist/TwirpRPC.cjs +5 -0
- package/dist/TwirpRPC.cjs.map +1 -1
- package/dist/TwirpRPC.d.cts +2 -1
- package/dist/TwirpRPC.d.ts +2 -1
- package/dist/TwirpRPC.d.ts.map +1 -1
- package/dist/TwirpRPC.js +4 -0
- package/dist/TwirpRPC.js.map +1 -1
- package/dist/crypto/digest.cjs +4 -16
- package/dist/crypto/digest.cjs.map +1 -1
- package/dist/crypto/digest.d.ts.map +1 -1
- package/dist/crypto/digest.js +4 -6
- package/dist/crypto/digest.js.map +1 -1
- package/dist/crypto/uuid.cjs +25 -17
- package/dist/crypto/uuid.cjs.map +1 -1
- package/dist/crypto/uuid.d.cts +2 -1
- package/dist/crypto/uuid.d.ts +2 -1
- package/dist/crypto/uuid.d.ts.map +1 -1
- package/dist/crypto/uuid.js +23 -6
- package/dist/crypto/uuid.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.d.cts +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +3 -3
- package/src/AccessToken.test.ts +13 -0
- package/src/AccessToken.ts +3 -0
- package/src/IngressClient.ts +14 -1
- package/src/TwirpRPC.test.ts +76 -4
- package/src/TwirpRPC.ts +8 -1
- package/src/crypto/digest.ts +5 -7
- package/src/crypto/uuid.ts +24 -6
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -175,7 +175,7 @@ try {
|
|
|
175
175
|
});
|
|
176
176
|
} catch (e) {
|
|
177
177
|
if (e instanceof SipCallError) {
|
|
178
|
-
console.log(e.message); // e.g. "SIP call failed: 486 Busy Here (
|
|
178
|
+
console.log(e.message); // e.g. "SIP call failed: 486 Busy Here (failed_precondition)"
|
|
179
179
|
if (e.sipStatusCode === 486) {
|
|
180
180
|
// callee is busy
|
|
181
181
|
}
|
package/dist/AccessToken.cjs
CHANGED
|
@@ -171,7 +171,10 @@ class TokenVerifier {
|
|
|
171
171
|
const secret = new TextEncoder().encode(this.apiSecret);
|
|
172
172
|
const { payload } = await jose.jwtVerify(token, secret, {
|
|
173
173
|
issuer: this.apiKey,
|
|
174
|
-
clockTolerance
|
|
174
|
+
clockTolerance,
|
|
175
|
+
// First-party minters always set exp. Without this, a hand-rolled token
|
|
176
|
+
// with a valid signature and no exp verifies forever (livekit/protocol#1706).
|
|
177
|
+
requiredClaims: ["exp"]
|
|
175
178
|
});
|
|
176
179
|
if (!payload) {
|
|
177
180
|
throw Error("invalid token");
|
package/dist/AccessToken.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/AccessToken.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RoomConfiguration } from '@livekit/protocol';\nimport * as jose from 'jose';\nimport type {\n ClaimGrants,\n InferenceGrant,\n ObservabilityGrant,\n SIPGrant,\n VideoGrant,\n} from './grants.js';\nimport { claimsToJwtPayload } from './grants.js';\n\n// 6 hours\nconst defaultTTL = `6h`;\n\nconst defaultClockToleranceSeconds = 10;\n\nexport interface AccessTokenOptions {\n /**\n * amount of time before expiration\n * expressed in seconds or a string describing a time span zeit/ms.\n * eg: '2 days', '10h', or seconds as numeric value\n */\n ttl?: number | string;\n\n /**\n * display name for the participant, available as `Participant.name`\n */\n name?: string;\n\n /**\n * identity of the user, required for room join tokens\n */\n identity?: string;\n\n /**\n * custom participant metadata\n */\n metadata?: string;\n\n /**\n * custom participant attributes\n */\n attributes?: Record<string, string>;\n}\n\nexport class AccessToken {\n private apiKey: string;\n\n private apiSecret: string;\n\n private grants: ClaimGrants;\n\n identity?: string;\n\n ttl: number | string;\n\n /**\n * Creates a new AccessToken\n * @param apiKey - API Key, can be set in env LIVEKIT_API_KEY\n * @param apiSecret - Secret, can be set in env LIVEKIT_API_SECRET\n */\n constructor(apiKey?: string, apiSecret?: string, options?: AccessTokenOptions) {\n if (!apiKey) {\n apiKey = process.env.LIVEKIT_API_KEY;\n }\n if (!apiSecret) {\n apiSecret = process.env.LIVEKIT_API_SECRET;\n }\n if (!apiKey || !apiSecret) {\n throw Error('api-key and api-secret must be set');\n }\n // @ts-expect-error we're not including dom lib for the server sdk so document is not defined\n else if (typeof document !== 'undefined') {\n // check against document rather than window because deno provides window\n console.error(\n 'You should not include your API secret in your web client bundle.\\n\\n' +\n 'Your web client should request a token from your backend server which should then use ' +\n 'the API secret to generate a token. See https://docs.livekit.io/client/connect/',\n );\n }\n this.apiKey = apiKey;\n this.apiSecret = apiSecret;\n this.grants = {};\n this.identity = options?.identity;\n this.ttl = options?.ttl || defaultTTL;\n if (typeof this.ttl === 'number') {\n this.ttl = `${this.ttl}s`;\n }\n if (options?.metadata) {\n this.metadata = options.metadata;\n }\n if (options?.attributes) {\n this.attributes = options.attributes;\n }\n if (options?.name) {\n this.name = options.name;\n }\n }\n\n /**\n * Adds a video grant to this token.\n * @param grant -\n */\n addGrant(grant: VideoGrant) {\n this.grants.video = { ...(this.grants.video ?? {}), ...grant };\n }\n\n /**\n * Adds an inference grant to this token.\n * @param grant -\n */\n addInferenceGrant(grant: InferenceGrant) {\n this.grants.inference = { ...(this.grants.inference ?? {}), ...grant };\n }\n\n /**\n * Adds a SIP grant to this token.\n * @param grant -\n */\n addSIPGrant(grant: SIPGrant) {\n this.grants.sip = { ...(this.grants.sip ?? {}), ...grant };\n }\n\n /**\n * Adds an observability grant to this token.\n * @param grant -\n */\n addObservabilityGrant(grant: ObservabilityGrant) {\n this.grants.observability = { ...(this.grants.observability ?? {}), ...grant };\n }\n\n get name(): string | undefined {\n return this.grants.name;\n }\n\n set name(name: string) {\n this.grants.name = name;\n }\n\n get metadata(): string | undefined {\n return this.grants.metadata;\n }\n\n /**\n * Set metadata to be passed to the Participant, used only when joining the room\n */\n set metadata(md: string) {\n this.grants.metadata = md;\n }\n\n get attributes(): Record<string, string> | undefined {\n return this.grants.attributes;\n }\n\n set attributes(attrs: Record<string, string>) {\n this.grants.attributes = attrs;\n }\n\n get kind(): string | undefined {\n return this.grants.kind;\n }\n\n set kind(kind: string) {\n this.grants.kind = kind;\n }\n\n get sha256(): string | undefined {\n return this.grants.sha256;\n }\n\n set sha256(sha: string | undefined) {\n this.grants.sha256 = sha;\n }\n\n get roomPreset(): string | undefined {\n return this.grants.roomPreset;\n }\n\n set roomPreset(preset: string | undefined) {\n this.grants.roomPreset = preset;\n }\n\n get roomConfig(): RoomConfiguration | undefined {\n return this.grants.roomConfig;\n }\n\n set roomConfig(config: RoomConfiguration | undefined) {\n this.grants.roomConfig = config;\n }\n\n /**\n * @returns JWT encoded token\n */\n async toJwt(): Promise<string> {\n // TODO: check for video grant validity\n\n const secret = new TextEncoder().encode(this.apiSecret);\n\n const jwt = new jose.SignJWT(claimsToJwtPayload(this.grants))\n .setProtectedHeader({ alg: 'HS256' })\n .setIssuer(this.apiKey)\n .setExpirationTime(this.ttl)\n .setNotBefore(new Date());\n if (this.identity) {\n jwt.setSubject(this.identity);\n } else if (this.grants.video?.roomJoin) {\n throw Error('identity is required for join but not set');\n }\n return jwt.sign(secret);\n }\n}\n\nexport class TokenVerifier {\n private apiKey: string;\n\n private apiSecret: string;\n\n constructor(apiKey: string, apiSecret: string) {\n this.apiKey = apiKey;\n this.apiSecret = apiSecret;\n }\n\n async verify(\n token: string,\n clockTolerance: string | number = defaultClockToleranceSeconds,\n ): Promise<ClaimGrants> {\n const secret = new TextEncoder().encode(this.apiSecret);\n const { payload } = await jose.jwtVerify(token, secret, {\n issuer: this.apiKey,\n clockTolerance,\n });\n if (!payload) {\n throw Error('invalid token');\n }\n\n return payload as ClaimGrants;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,WAAsB;AAQtB,oBAAmC;AAGnC,MAAM,aAAa;AAEnB,MAAM,+BAA+B;AA+B9B,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBvB,YAAY,QAAiB,WAAoB,SAA8B;AAC7E,QAAI,CAAC,QAAQ;AACX,eAAS,QAAQ,IAAI;AAAA,IACvB;AACA,QAAI,CAAC,WAAW;AACd,kBAAY,QAAQ,IAAI;AAAA,IAC1B;AACA,QAAI,CAAC,UAAU,CAAC,WAAW;AACzB,YAAM,MAAM,oCAAoC;AAAA,IAClD,WAES,OAAO,aAAa,aAAa;AAExC,cAAQ;AAAA,QACN;AAAA,MAGF;AAAA,IACF;AACA,SAAK,SAAS;AACd,SAAK,YAAY;AACjB,SAAK,SAAS,CAAC;AACf,SAAK,WAAW,mCAAS;AACzB,SAAK,OAAM,mCAAS,QAAO;AAC3B,QAAI,OAAO,KAAK,QAAQ,UAAU;AAChC,WAAK,MAAM,GAAG,KAAK,GAAG;AAAA,IACxB;AACA,QAAI,mCAAS,UAAU;AACrB,WAAK,WAAW,QAAQ;AAAA,IAC1B;AACA,QAAI,mCAAS,YAAY;AACvB,WAAK,aAAa,QAAQ;AAAA,IAC5B;AACA,QAAI,mCAAS,MAAM;AACjB,WAAK,OAAO,QAAQ;AAAA,IACtB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAS,OAAmB;AAC1B,SAAK,OAAO,QAAQ,EAAE,GAAI,KAAK,OAAO,SA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ACzC,SAAK,OAAO,aAAa;AAAA,EAC3B;AAAA,EAEA,IAAI,aAA4C;AAC9C,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEA,IAAI,WAAW,QAAuC;AACpD,SAAK,OAAO,aAAa;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,QAAyB;AApMjC;AAuMI,UAAM,SAAS,IAAI,YAAY,EAAE,OAAO,KAAK,SAAS;AAEtD,UAAM,MAAM,IAAI,KAAK,YAAQ,kCAAmB,KAAK,MAAM,CAAC,EACzD,mBAAmB,EAAE,KAAK,QAAQ,CAAC,EACnC,UAAU,KAAK,MAAM,EACrB,kBAAkB,KAAK,GAAG,EAC1B,aAAa,oBAAI,KAAK,CAAC;AAC1B,QAAI,KAAK,UAAU;AACjB,UAAI,WAAW,KAAK,QAAQ;AAAA,IAC9B,YAAW,UAAK,OAAO,UAAZ,mBAAmB,UAAU;AACtC,YAAM,MAAM,2CAA2C;AAAA,IACzD;AACA,WAAO,IAAI,KAAK,MAAM;AAAA,EACxB;AACF;AAEO,MAAM,cAAc;AAAA,EAKzB,YAAY,QAAgB,WAAmB;AAC7C,SAAK,SAAS;AACd,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAM,OACJ,OACA,iBAAkC,8BACZ;AACtB,UAAM,SAAS,IAAI,YAAY,EAAE,OAAO,KAAK,SAAS;AACtD,UAAM,EAAE,QAAQ,IAAI,MAAM,KAAK,UAAU,OAAO,QAAQ;AAAA,MACtD,QAAQ,KAAK;AAAA,MACb;AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/AccessToken.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RoomConfiguration } from '@livekit/protocol';\nimport * as jose from 'jose';\nimport type {\n ClaimGrants,\n InferenceGrant,\n ObservabilityGrant,\n SIPGrant,\n VideoGrant,\n} from './grants.js';\nimport { claimsToJwtPayload } from './grants.js';\n\n// 6 hours\nconst defaultTTL = `6h`;\n\nconst defaultClockToleranceSeconds = 10;\n\nexport interface AccessTokenOptions {\n /**\n * amount of time before expiration\n * expressed in seconds or a string describing a time span zeit/ms.\n * eg: '2 days', '10h', or seconds as numeric value\n */\n ttl?: number | string;\n\n /**\n * display name for the participant, available as `Participant.name`\n */\n name?: string;\n\n /**\n * identity of the user, required for room join tokens\n */\n identity?: string;\n\n /**\n * custom participant metadata\n */\n metadata?: string;\n\n /**\n * custom participant attributes\n */\n attributes?: Record<string, string>;\n}\n\nexport class AccessToken {\n private apiKey: string;\n\n private apiSecret: string;\n\n private grants: ClaimGrants;\n\n identity?: string;\n\n ttl: number | string;\n\n /**\n * Creates a new AccessToken\n * @param apiKey - API Key, can be set in env LIVEKIT_API_KEY\n * @param apiSecret - Secret, can be set in env LIVEKIT_API_SECRET\n */\n constructor(apiKey?: string, apiSecret?: string, options?: AccessTokenOptions) {\n if (!apiKey) {\n apiKey = process.env.LIVEKIT_API_KEY;\n }\n if (!apiSecret) {\n apiSecret = process.env.LIVEKIT_API_SECRET;\n }\n if (!apiKey || !apiSecret) {\n throw Error('api-key and api-secret must be set');\n }\n // @ts-expect-error we're not including dom lib for the server sdk so document is not defined\n else if (typeof document !== 'undefined') {\n // check against document rather than window because deno provides window\n console.error(\n 'You should not include your API secret in your web client bundle.\\n\\n' +\n 'Your web client should request a token from your backend server which should then use ' +\n 'the API secret to generate a token. See https://docs.livekit.io/client/connect/',\n );\n }\n this.apiKey = apiKey;\n this.apiSecret = apiSecret;\n this.grants = {};\n this.identity = options?.identity;\n this.ttl = options?.ttl || defaultTTL;\n if (typeof this.ttl === 'number') {\n this.ttl = `${this.ttl}s`;\n }\n if (options?.metadata) {\n this.metadata = options.metadata;\n }\n if (options?.attributes) {\n this.attributes = options.attributes;\n }\n if (options?.name) {\n this.name = options.name;\n }\n }\n\n /**\n * Adds a video grant to this token.\n * @param grant -\n */\n addGrant(grant: VideoGrant) {\n this.grants.video = { ...(this.grants.video ?? {}), ...grant };\n }\n\n /**\n * Adds an inference grant to this token.\n * @param grant -\n */\n addInferenceGrant(grant: InferenceGrant) {\n this.grants.inference = { ...(this.grants.inference ?? {}), ...grant };\n }\n\n /**\n * Adds a SIP grant to this token.\n * @param grant -\n */\n addSIPGrant(grant: SIPGrant) {\n this.grants.sip = { ...(this.grants.sip ?? {}), ...grant };\n }\n\n /**\n * Adds an observability grant to this token.\n * @param grant -\n */\n addObservabilityGrant(grant: ObservabilityGrant) {\n this.grants.observability = { ...(this.grants.observability ?? {}), ...grant };\n }\n\n get name(): string | undefined {\n return this.grants.name;\n }\n\n set name(name: string) {\n this.grants.name = name;\n }\n\n get metadata(): string | undefined {\n return this.grants.metadata;\n }\n\n /**\n * Set metadata to be passed to the Participant, used only when joining the room\n */\n set metadata(md: string) {\n this.grants.metadata = md;\n }\n\n get attributes(): Record<string, string> | undefined {\n return this.grants.attributes;\n }\n\n set attributes(attrs: Record<string, string>) {\n this.grants.attributes = attrs;\n }\n\n get kind(): string | undefined {\n return this.grants.kind;\n }\n\n set kind(kind: string) {\n this.grants.kind = kind;\n }\n\n get sha256(): string | undefined {\n return this.grants.sha256;\n }\n\n set sha256(sha: string | undefined) {\n this.grants.sha256 = sha;\n }\n\n get roomPreset(): string | undefined {\n return this.grants.roomPreset;\n }\n\n set roomPreset(preset: string | undefined) {\n this.grants.roomPreset = preset;\n }\n\n get roomConfig(): RoomConfiguration | undefined {\n return this.grants.roomConfig;\n }\n\n set roomConfig(config: RoomConfiguration | undefined) {\n this.grants.roomConfig = config;\n }\n\n /**\n * @returns JWT encoded token\n */\n async toJwt(): Promise<string> {\n // TODO: check for video grant validity\n\n const secret = new TextEncoder().encode(this.apiSecret);\n\n const jwt = new jose.SignJWT(claimsToJwtPayload(this.grants))\n .setProtectedHeader({ alg: 'HS256' })\n .setIssuer(this.apiKey)\n .setExpirationTime(this.ttl)\n .setNotBefore(new Date());\n if (this.identity) {\n jwt.setSubject(this.identity);\n } else if (this.grants.video?.roomJoin) {\n throw Error('identity is required for join but not set');\n }\n return jwt.sign(secret);\n }\n}\n\nexport class TokenVerifier {\n private apiKey: string;\n\n private apiSecret: string;\n\n constructor(apiKey: string, apiSecret: string) {\n this.apiKey = apiKey;\n this.apiSecret = apiSecret;\n }\n\n async verify(\n token: string,\n clockTolerance: string | number = defaultClockToleranceSeconds,\n ): Promise<ClaimGrants> {\n const secret = new TextEncoder().encode(this.apiSecret);\n const { payload } = await jose.jwtVerify(token, secret, {\n issuer: this.apiKey,\n clockTolerance,\n // First-party minters always set exp. Without this, a hand-rolled token\n // with a valid signature and no exp verifies forever (livekit/protocol#1706).\n requiredClaims: ['exp'],\n });\n if (!payload) {\n throw Error('invalid token');\n }\n\n return payload as ClaimGrants;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,WAAsB;AAQtB,oBAAmC;AAGnC,MAAM,aAAa;AAEnB,MAAM,+BAA+B;AA+B9B,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBvB,YAAY,QAAiB,WAAoB,SAA8B;AAC7E,QAAI,CAAC,QAAQ;AACX,eAAS,QAAQ,IAAI;AAAA,IACvB;AACA,QAAI,CAAC,WAAW;AACd,kBAAY,QAAQ,IAAI;AAAA,IAC1B;AACA,QAAI,CAAC,UAAU,CAAC,WAAW;AACzB,YAAM,MAAM,oCAAoC;AAAA,IAClD,WAES,OAAO,aAAa,aAAa;AAExC,cAAQ;AAAA,QACN;AAAA,MAGF;AAAA,IACF;AACA,SAAK,SAAS;AACd,SAAK,YAAY;AACjB,SAAK,SAAS,CAAC;AACf,SAAK,WAAW,mCAAS;AACzB,SAAK,OAAM,mCAAS,QAAO;AAC3B,QAAI,OAAO,KAAK,QAAQ,UAAU;AAChC,WAAK,MAAM,GAAG,KAAK,GAAG;AAAA,IACxB;AACA,QAAI,mCAAS,UAAU;AACrB,WAAK,WAAW,QAAQ;AAAA,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AK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAE3C;IAED,IAAI,IAAI,IAAI,MAAM,GAAG,SAAS,CAE7B;IAED,IAAI,IAAI,CAAC,IAAI,EAAE,MAAM,EAEpB;IAED,IAAI,MAAM,IAAI,MAAM,GAAG,SAAS,CAE/B;IAED,IAAI,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAEjC;IAED,IAAI,UAAU,IAAI,MAAM,GAAG,SAAS,CAEnC;IAED,IAAI,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,EAExC;IAED,IAAI,UAAU,IAAI,iBAAiB,GAAG,SAAS,CAE9C;IAED,IAAI,UAAU,CAAC,MAAM,EAAE,iBAAiB,GAAG,SAAS,EAEnD;IAED;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;CAiB/B;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,CAAC,SAAS,CAAS;gBAEd,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;IAKvC,MAAM,CACV,KAAK,EAAE,MAAM,EACb,cAAc,GAAE,MAAM,GAAG,MAAqC,GAC7D,OAAO,CAAC,WAAW,CAAC;CAexB"}
|
package/dist/AccessToken.js
CHANGED
|
@@ -137,7 +137,10 @@ class TokenVerifier {
|
|
|
137
137
|
const secret = new TextEncoder().encode(this.apiSecret);
|
|
138
138
|
const { payload } = await jose.jwtVerify(token, secret, {
|
|
139
139
|
issuer: this.apiKey,
|
|
140
|
-
clockTolerance
|
|
140
|
+
clockTolerance,
|
|
141
|
+
// First-party minters always set exp. Without this, a hand-rolled token
|
|
142
|
+
// with a valid signature and no exp verifies forever (livekit/protocol#1706).
|
|
143
|
+
requiredClaims: ["exp"]
|
|
141
144
|
});
|
|
142
145
|
if (!payload) {
|
|
143
146
|
throw Error("invalid token");
|
package/dist/AccessToken.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/AccessToken.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RoomConfiguration } from '@livekit/protocol';\nimport * as jose from 'jose';\nimport type {\n ClaimGrants,\n InferenceGrant,\n ObservabilityGrant,\n SIPGrant,\n VideoGrant,\n} from './grants.js';\nimport { claimsToJwtPayload } from './grants.js';\n\n// 6 hours\nconst defaultTTL = `6h`;\n\nconst defaultClockToleranceSeconds = 10;\n\nexport interface AccessTokenOptions {\n /**\n * amount of time before expiration\n * expressed in seconds or a string describing a time span zeit/ms.\n * eg: '2 days', '10h', or seconds as numeric value\n */\n ttl?: number | string;\n\n /**\n * display name for the participant, available as `Participant.name`\n */\n name?: string;\n\n /**\n * identity of the user, required for room join tokens\n */\n identity?: string;\n\n /**\n * custom participant metadata\n */\n metadata?: string;\n\n /**\n * custom participant attributes\n */\n attributes?: Record<string, string>;\n}\n\nexport class AccessToken {\n private apiKey: string;\n\n private apiSecret: string;\n\n private grants: ClaimGrants;\n\n identity?: string;\n\n ttl: number | string;\n\n /**\n * Creates a new AccessToken\n * @param apiKey - API Key, can be set in env LIVEKIT_API_KEY\n * @param apiSecret - Secret, can be set in env LIVEKIT_API_SECRET\n */\n constructor(apiKey?: string, apiSecret?: string, options?: AccessTokenOptions) {\n if (!apiKey) {\n apiKey = process.env.LIVEKIT_API_KEY;\n }\n if (!apiSecret) {\n apiSecret = process.env.LIVEKIT_API_SECRET;\n }\n if (!apiKey || !apiSecret) {\n throw Error('api-key and api-secret must be set');\n }\n // @ts-expect-error we're not including dom lib for the server sdk so document is not defined\n else if (typeof document !== 'undefined') {\n // check against document rather than window because deno provides window\n console.error(\n 'You should not include your API secret in your web client bundle.\\n\\n' +\n 'Your web client should request a token from your backend server which should then use ' +\n 'the API secret to generate a token. See https://docs.livekit.io/client/connect/',\n );\n }\n this.apiKey = apiKey;\n this.apiSecret = apiSecret;\n this.grants = {};\n this.identity = options?.identity;\n this.ttl = options?.ttl || defaultTTL;\n if (typeof this.ttl === 'number') {\n this.ttl = `${this.ttl}s`;\n }\n if (options?.metadata) {\n this.metadata = options.metadata;\n }\n if (options?.attributes) {\n this.attributes = options.attributes;\n }\n if (options?.name) {\n this.name = options.name;\n }\n }\n\n /**\n * Adds a video grant to this token.\n * @param grant -\n */\n addGrant(grant: VideoGrant) {\n this.grants.video = { ...(this.grants.video ?? {}), ...grant };\n }\n\n /**\n * Adds an inference grant to this token.\n * @param grant -\n */\n addInferenceGrant(grant: InferenceGrant) {\n this.grants.inference = { ...(this.grants.inference ?? {}), ...grant };\n }\n\n /**\n * Adds a SIP grant to this token.\n * @param grant -\n */\n addSIPGrant(grant: SIPGrant) {\n this.grants.sip = { ...(this.grants.sip ?? {}), ...grant };\n }\n\n /**\n * Adds an observability grant to this token.\n * @param grant -\n */\n addObservabilityGrant(grant: ObservabilityGrant) {\n this.grants.observability = { ...(this.grants.observability ?? {}), ...grant };\n }\n\n get name(): string | undefined {\n return this.grants.name;\n }\n\n set name(name: string) {\n this.grants.name = name;\n }\n\n get metadata(): string | undefined {\n return this.grants.metadata;\n }\n\n /**\n * Set metadata to be passed to the Participant, used only when joining the room\n */\n set metadata(md: string) {\n this.grants.metadata = md;\n }\n\n get attributes(): Record<string, string> | undefined {\n return this.grants.attributes;\n }\n\n set attributes(attrs: Record<string, string>) {\n this.grants.attributes = attrs;\n }\n\n get kind(): string | undefined {\n return this.grants.kind;\n }\n\n set kind(kind: string) {\n this.grants.kind = kind;\n }\n\n get sha256(): string | undefined {\n return this.grants.sha256;\n }\n\n set sha256(sha: string | undefined) {\n this.grants.sha256 = sha;\n }\n\n get roomPreset(): string | undefined {\n return this.grants.roomPreset;\n }\n\n set roomPreset(preset: string | undefined) {\n this.grants.roomPreset = preset;\n }\n\n get roomConfig(): RoomConfiguration | undefined {\n return this.grants.roomConfig;\n }\n\n set roomConfig(config: RoomConfiguration | undefined) {\n this.grants.roomConfig = config;\n }\n\n /**\n * @returns JWT encoded token\n */\n async toJwt(): Promise<string> {\n // TODO: check for video grant validity\n\n const secret = new TextEncoder().encode(this.apiSecret);\n\n const jwt = new jose.SignJWT(claimsToJwtPayload(this.grants))\n .setProtectedHeader({ alg: 'HS256' })\n .setIssuer(this.apiKey)\n .setExpirationTime(this.ttl)\n .setNotBefore(new Date());\n if (this.identity) {\n jwt.setSubject(this.identity);\n } else if (this.grants.video?.roomJoin) {\n throw Error('identity is required for join but not set');\n }\n return jwt.sign(secret);\n }\n}\n\nexport class TokenVerifier {\n private apiKey: string;\n\n private apiSecret: string;\n\n constructor(apiKey: string, apiSecret: string) {\n this.apiKey = apiKey;\n this.apiSecret = apiSecret;\n }\n\n async verify(\n token: string,\n clockTolerance: string | number = defaultClockToleranceSeconds,\n ): Promise<ClaimGrants> {\n const secret = new TextEncoder().encode(this.apiSecret);\n const { payload } = await jose.jwtVerify(token, secret, {\n issuer: this.apiKey,\n clockTolerance,\n });\n if (!payload) {\n throw Error('invalid token');\n }\n\n return payload as ClaimGrants;\n }\n}\n"],"mappings":"AAIA,YAAY,UAAU;AAQtB,SAAS,0BAA0B;AAGnC,MAAM,aAAa;AAEnB,MAAM,+BAA+B;AA+B9B,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBvB,YAAY,QAAiB,WAAoB,SAA8B;AAC7E,QAAI,CAAC,QAAQ;AACX,eAAS,QAAQ,IAAI;AAAA,IACvB;AACA,QAAI,CAAC,WAAW;AACd,kBAAY,QAAQ,IAAI;AAAA,IAC1B;AACA,QAAI,CAAC,UAAU,CAAC,WAAW;AACzB,YAAM,MAAM,oCAAoC;AAAA,IAClD,WAES,OAAO,aAAa,aAAa;AAExC,cAAQ;AAAA,QACN;AAAA,MAGF;AAAA,IACF;AACA,SAAK,SAAS;AACd,SAAK,YAAY;AACjB,SAAK,SAAS,CAAC;AACf,SAAK,WAAW,mCAAS;AACzB,SAAK,OAAM,mCAAS,QAAO;AAC3B,QAAI,OAAO,KAAK,Q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AAQ,IAAI,MAAM,KAAK,UAAU,OAAO,QAAQ;AAAA,MACtD,QAAQ,KAAK;AAAA,MACb;AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/AccessToken.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { RoomConfiguration } from '@livekit/protocol';\nimport * as jose from 'jose';\nimport type {\n ClaimGrants,\n InferenceGrant,\n ObservabilityGrant,\n SIPGrant,\n VideoGrant,\n} from './grants.js';\nimport { claimsToJwtPayload } from './grants.js';\n\n// 6 hours\nconst defaultTTL = `6h`;\n\nconst defaultClockToleranceSeconds = 10;\n\nexport interface AccessTokenOptions {\n /**\n * amount of time before expiration\n * expressed in seconds or a string describing a time span zeit/ms.\n * eg: '2 days', '10h', or seconds as numeric value\n */\n ttl?: number | string;\n\n /**\n * display name for the participant, available as `Participant.name`\n */\n name?: string;\n\n /**\n * identity of the user, required for room join tokens\n */\n identity?: string;\n\n /**\n * custom participant metadata\n */\n metadata?: string;\n\n /**\n * custom participant attributes\n */\n attributes?: Record<string, string>;\n}\n\nexport class AccessToken {\n private apiKey: string;\n\n private apiSecret: string;\n\n private grants: ClaimGrants;\n\n identity?: string;\n\n ttl: number | string;\n\n /**\n * Creates a new AccessToken\n * @param apiKey - API Key, can be set in env LIVEKIT_API_KEY\n * @param apiSecret - Secret, can be set in env LIVEKIT_API_SECRET\n */\n constructor(apiKey?: string, apiSecret?: string, options?: AccessTokenOptions) {\n if (!apiKey) {\n apiKey = process.env.LIVEKIT_API_KEY;\n }\n if (!apiSecret) {\n apiSecret = process.env.LIVEKIT_API_SECRET;\n }\n if (!apiKey || !apiSecret) {\n throw Error('api-key and api-secret must be set');\n }\n // @ts-expect-error we're not including dom lib for the server sdk so document is not defined\n else if (typeof document !== 'undefined') {\n // check against document rather than window because deno provides window\n console.error(\n 'You should not include your API secret in your web client bundle.\\n\\n' +\n 'Your web client should request a token from your backend server which should then use ' +\n 'the API secret to generate a token. See https://docs.livekit.io/client/connect/',\n );\n }\n this.apiKey = apiKey;\n this.apiSecret = apiSecret;\n this.grants = {};\n this.identity = options?.identity;\n this.ttl = options?.ttl || defaultTTL;\n if (typeof this.ttl === 'number') {\n this.ttl = `${this.ttl}s`;\n }\n if (options?.metadata) {\n this.metadata = options.metadata;\n }\n if (options?.attributes) {\n this.attributes = options.attributes;\n }\n if (options?.name) {\n this.name = options.name;\n }\n }\n\n /**\n * Adds a video grant to this token.\n * @param grant -\n */\n addGrant(grant: VideoGrant) {\n this.grants.video = { ...(this.grants.video ?? {}), ...grant };\n }\n\n /**\n * Adds an inference grant to this token.\n * @param grant -\n */\n addInferenceGrant(grant: InferenceGrant) {\n this.grants.inference = { ...(this.grants.inference ?? {}), ...grant };\n }\n\n /**\n * Adds a SIP grant to this token.\n * @param grant -\n */\n addSIPGrant(grant: SIPGrant) {\n this.grants.sip = { ...(this.grants.sip ?? {}), ...grant };\n }\n\n /**\n * Adds an observability grant to this token.\n * @param grant -\n */\n addObservabilityGrant(grant: ObservabilityGrant) {\n this.grants.observability = { ...(this.grants.observability ?? {}), ...grant };\n }\n\n get name(): string | undefined {\n return this.grants.name;\n }\n\n set name(name: string) {\n this.grants.name = name;\n }\n\n get metadata(): string | undefined {\n return this.grants.metadata;\n }\n\n /**\n * Set metadata to be passed to the Participant, used only when joining the room\n */\n set metadata(md: string) {\n this.grants.metadata = md;\n }\n\n get attributes(): Record<string, string> | undefined {\n return this.grants.attributes;\n }\n\n set attributes(attrs: Record<string, string>) {\n this.grants.attributes = attrs;\n }\n\n get kind(): string | undefined {\n return this.grants.kind;\n }\n\n set kind(kind: string) {\n this.grants.kind = kind;\n }\n\n get sha256(): string | undefined {\n return this.grants.sha256;\n }\n\n set sha256(sha: string | undefined) {\n this.grants.sha256 = sha;\n }\n\n get roomPreset(): string | undefined {\n return this.grants.roomPreset;\n }\n\n set roomPreset(preset: string | undefined) {\n this.grants.roomPreset = preset;\n }\n\n get roomConfig(): RoomConfiguration | undefined {\n return this.grants.roomConfig;\n }\n\n set roomConfig(config: RoomConfiguration | undefined) {\n this.grants.roomConfig = config;\n }\n\n /**\n * @returns JWT encoded token\n */\n async toJwt(): Promise<string> {\n // TODO: check for video grant validity\n\n const secret = new TextEncoder().encode(this.apiSecret);\n\n const jwt = new jose.SignJWT(claimsToJwtPayload(this.grants))\n .setProtectedHeader({ alg: 'HS256' })\n .setIssuer(this.apiKey)\n .setExpirationTime(this.ttl)\n .setNotBefore(new Date());\n if (this.identity) {\n jwt.setSubject(this.identity);\n } else if (this.grants.video?.roomJoin) {\n throw Error('identity is required for join but not set');\n }\n return jwt.sign(secret);\n }\n}\n\nexport class TokenVerifier {\n private apiKey: string;\n\n private apiSecret: string;\n\n constructor(apiKey: string, apiSecret: string) {\n this.apiKey = apiKey;\n this.apiSecret = apiSecret;\n }\n\n async verify(\n token: string,\n clockTolerance: string | number = defaultClockToleranceSeconds,\n ): Promise<ClaimGrants> {\n const secret = new TextEncoder().encode(this.apiSecret);\n const { payload } = await jose.jwtVerify(token, secret, {\n issuer: this.apiKey,\n clockTolerance,\n // First-party minters always set exp. Without this, a hand-rolled token\n // with a valid signature and no exp verifies forever (livekit/protocol#1706).\n requiredClaims: ['exp'],\n });\n if (!payload) {\n throw Error('invalid token');\n }\n\n return payload as ClaimGrants;\n }\n}\n"],"mappings":"AAIA,YAAY,UAAU;AAQtB,SAAS,0BAA0B;AAGnC,MAAM,aAAa;AAEnB,MAAM,+BAA+B;AA+B9B,MAAM,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAgBvB,YAAY,QAAiB,WAAoB,SAA8B;AAC7E,QAAI,CAAC,QAAQ;AACX,eAAS,QAAQ,IAAI;AAAA,IACvB;AACA,QAAI,CAAC,WAAW;AACd,kBAAY,QAAQ,IAAI;AAAA,IAC1B;AACA,QAAI,CAAC,UAAU,CAAC,WAAW;AACzB,YAAM,MAAM,oCAAoC;AAAA,IAClD,WAES,OAAO,aAAa,aAAa;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YAAY,QAAgB,WAAmB;AAC7C,SAAK,SAAS;AACd,SAAK,YAAY;AAAA,EACnB;AAAA,EAEA,MAAM,OACJ,OACA,iBAAkC,8BACZ;AACtB,UAAM,SAAS,IAAI,YAAY,EAAE,OAAO,KAAK,SAAS;AACtD,UAAM,EAAE,QAAQ,IAAI,MAAM,KAAK,UAAU,OAAO,QAAQ;AAAA,MACtD,QAAQ,KAAK;AAAA,MACb;AAAA;AAAA;AAAA,MAGA,gBAAgB,CAAC,KAAK;AAAA,IACxB,CAAC;AACD,QAAI,CAAC,SAAS;AACZ,YAAM,MAAM,eAAe;AAAA,IAC7B;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/IngressClient.cjs
CHANGED
|
@@ -54,6 +54,7 @@ class IngressClient extends import_ServiceBase.ServiceBase {
|
|
|
54
54
|
}
|
|
55
55
|
const roomName = opts.roomName;
|
|
56
56
|
const enableTranscoding = opts.enableTranscoding;
|
|
57
|
+
const enabled = opts.enabled;
|
|
57
58
|
const audio = opts.audio;
|
|
58
59
|
const video = opts.video;
|
|
59
60
|
const participantMetadata = opts.participantMetadata;
|
|
@@ -78,6 +79,7 @@ class IngressClient extends import_ServiceBase.ServiceBase {
|
|
|
78
79
|
bypassTranscoding,
|
|
79
80
|
enableTranscoding,
|
|
80
81
|
url,
|
|
82
|
+
enabled,
|
|
81
83
|
audio,
|
|
82
84
|
video
|
|
83
85
|
}).toJson();
|
|
@@ -99,7 +101,7 @@ class IngressClient extends import_ServiceBase.ServiceBase {
|
|
|
99
101
|
const participantName = opts.participantName || "";
|
|
100
102
|
const participantIdentity = opts.participantIdentity || "";
|
|
101
103
|
const { participantMetadata } = opts;
|
|
102
|
-
const { audio, video, bypassTranscoding, enableTranscoding } = opts;
|
|
104
|
+
const { audio, video, bypassTranscoding, enableTranscoding, enabled } = opts;
|
|
103
105
|
const req = new import_protocol.UpdateIngressRequest({
|
|
104
106
|
ingressId,
|
|
105
107
|
name,
|
|
@@ -109,6 +111,7 @@ class IngressClient extends import_ServiceBase.ServiceBase {
|
|
|
109
111
|
participantMetadata,
|
|
110
112
|
bypassTranscoding,
|
|
111
113
|
enableTranscoding,
|
|
114
|
+
enabled,
|
|
112
115
|
audio,
|
|
113
116
|
video
|
|
114
117
|
}).toJson();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/IngressClient.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { IngressAudioOptions, IngressInput, IngressVideoOptions } from '@livekit/protocol';\nimport {\n CreateIngressRequest,\n DeleteIngressRequest,\n IngressInfo,\n ListIngressRequest,\n ListIngressResponse,\n UpdateIngressRequest,\n} from '@livekit/protocol';\nimport type { ClientOptions } from './ClientOptions.js';\nimport { ServiceBase } from './ServiceBase.js';\nimport type { Rpc } from './TwirpRPC.js';\nimport { TwirpRpc, livekitPackage } from './TwirpRPC.js';\n\nconst svc = 'Ingress';\n\nexport interface CreateIngressOptions {\n /**\n * ingress name. optional\n */\n name?: string;\n /**\n * name of the room to send media to. required\n */\n roomName?: string;\n /**\n * unique identity of the participant. required\n */\n participantIdentity: string;\n /**\n * participant display name\n */\n participantName?: string;\n /**\n * metadata to attach to the participant\n */\n participantMetadata?: string;\n /**\n * @deprecated use `enableTranscoding` instead.\n * whether to skip transcoding and forward the input media directly. Only supported by WHIP\n */\n bypassTranscoding?: boolean;\n /**\n * whether to enable transcoding or forward the input media directly.\n * Transcoding is required for all input types except WHIP. For WHIP, the default is to not transcode.\n */\n enableTranscoding?: boolean | undefined;\n /**\n * url of the media to pull for ingresses of type URL\n */\n url?: string;\n /**\n * custom audio encoding parameters. optional\n */\n audio?: IngressAudioOptions;\n /**\n * custom video encoding parameters. optional\n */\n video?: IngressVideoOptions;\n}\n\nexport interface UpdateIngressOptions {\n /**\n * ingress name. optional\n */\n name: string;\n /**\n * name of the room to send media to.\n */\n roomName?: string;\n /**\n * unique identity of the participant.\n */\n participantIdentity?: string;\n /**\n * participant display name\n */\n participantName?: string;\n /**\n * metadata to attach to the participant\n */\n participantMetadata?: string;\n /**\n * @deprecated use `enableTranscoding` instead\n * whether to skip transcoding and forward the input media directly. Only supported by WHIP\n */\n bypassTranscoding?: boolean | undefined;\n /**\n * whether to enable transcoding or forward the input media directly.\n * Transcoding is required for all input types except WHIP. For WHIP, the default is to not transcode.\n */\n enableTranscoding?: boolean | undefined;\n /**\n * custom audio encoding parameters. optional\n */\n audio?: IngressAudioOptions;\n /**\n * custom video encoding parameters. optional\n */\n video?: IngressVideoOptions;\n}\n\nexport interface ListIngressOptions {\n /**\n * list ingress for one room only\n */\n roomName?: string;\n\n /**\n * list ingress by ID\n */\n ingressId?: string;\n}\n\n/**\n * Client to access Ingress APIs\n */\nexport class IngressClient extends ServiceBase {\n private readonly rpc: Rpc;\n\n /**\n * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'\n * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY\n * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET\n * @param options - client options\n */\n constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {\n super({ apiKey, secret, token: options?.token });\n this.rpc = new TwirpRpc(host, livekitPackage, {\n requestTimeout: options?.requestTimeout,\n failover: options?.failover,\n });\n }\n\n /**\n * @param inputType - protocol for the ingress\n * @param opts - CreateIngressOptions\n */\n async createIngress(inputType: IngressInput, opts: CreateIngressOptions): Promise<IngressInfo> {\n let name: string = '';\n let participantName: string = '';\n let participantIdentity: string = '';\n let bypassTranscoding: boolean = false;\n let url: string = '';\n\n if (opts == null) {\n throw new Error('options dictionary is required');\n }\n\n const roomName: string | undefined = opts.roomName;\n const enableTranscoding: boolean | undefined = opts.enableTranscoding;\n const audio: IngressAudioOptions | undefined = opts.audio;\n const video: IngressVideoOptions | undefined = opts.video;\n const participantMetadata: string | undefined = opts.participantMetadata;\n\n name = opts.name || '';\n participantName = opts.participantName || '';\n participantIdentity = opts.participantIdentity || '';\n bypassTranscoding = opts.bypassTranscoding || false;\n url = opts.url || '';\n\n if (typeof roomName == 'undefined') {\n throw new Error('required roomName option not provided');\n }\n\n if (participantIdentity == '') {\n throw new Error('required participantIdentity option not provided');\n }\n\n const req = new CreateIngressRequest({\n inputType,\n name,\n roomName,\n participantIdentity,\n participantMetadata,\n participantName,\n bypassTranscoding,\n enableTranscoding,\n url,\n audio,\n video,\n }).toJson();\n\n const data = await this.rpc.request(\n svc,\n 'CreateIngress',\n req,\n await this.authHeader({ ingressAdmin: true }),\n );\n return IngressInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * @param ingressId - ID of the ingress to update\n * @param opts - UpdateIngressOptions\n */\n async updateIngress(ingressId: string, opts: UpdateIngressOptions): Promise<IngressInfo> {\n const name: string = opts.name || '';\n const roomName: string = opts.roomName || '';\n const participantName: string = opts.participantName || '';\n const participantIdentity: string = opts.participantIdentity || '';\n const { participantMetadata } = opts;\n const { audio, video, bypassTranscoding, enableTranscoding } = opts;\n\n const req = new UpdateIngressRequest({\n ingressId,\n name,\n roomName,\n participantIdentity,\n participantName,\n participantMetadata,\n bypassTranscoding,\n enableTranscoding,\n audio,\n video,\n }).toJson();\n\n const data = await this.rpc.request(\n svc,\n 'UpdateIngress',\n req,\n await this.authHeader({ ingressAdmin: true }),\n );\n return IngressInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * @deprecated use `listIngress(opts)` or `listIngress(arg)` instead\n * @param roomName - list ingress for one room only\n */\n async listIngress(roomName?: string): Promise<Array<IngressInfo>>;\n /**\n * @param opts - list options\n */\n async listIngress(opts?: ListIngressOptions): Promise<Array<IngressInfo>>;\n /**\n * @param arg - list room name or options\n */\n async listIngress(arg?: string | ListIngressOptions): Promise<Array<IngressInfo>> {\n let req: Partial<ListIngressRequest> = {};\n if (typeof arg === 'string') {\n req.roomName = arg;\n } else if (arg) {\n req = arg;\n }\n const data = await this.rpc.request(\n svc,\n 'ListIngress',\n new ListIngressRequest(req).toJson(),\n await this.authHeader({ ingressAdmin: true }),\n );\n return ListIngressResponse.fromJson(data, { ignoreUnknownFields: true }).items ?? [];\n }\n\n /**\n * @param ingressId - ingress to delete\n */\n async deleteIngress(ingressId: string): Promise<IngressInfo> {\n const data = await this.rpc.request(\n svc,\n 'DeleteIngress',\n new DeleteIngressRequest({ ingressId }).toJson(),\n await this.authHeader({ ingressAdmin: true }),\n );\n return IngressInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAOO;AAEP,yBAA4B;AAE5B,sBAAyC;AAEzC,MAAM,MAAM;AAuGL,MAAM,sBAAsB,+BAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YAAY,MAAc,QAAiB,QAAiB,SAAyB;AACnF,UAAM,EAAE,QAAQ,QAAQ,OAAO,mCAAS,MAAM,CAAC;AAC/C,SAAK,MAAM,IAAI,yBAAS,MAAM,gCAAgB;AAAA,MAC5C,gBAAgB,mCAAS;AAAA,MACzB,UAAU,mCAAS;AAAA,IACrB,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,cAAc,WAAyB,MAAkD;AAC7F,QAAI,OAAe;AACnB,QAAI,kBAA0B;AAC9B,QAAI,sBAA8B;AAClC,QAAI,oBAA6B;AACjC,QAAI,MAAc;AAElB,QAAI,QAAQ,MAAM;AAChB,YAAM,IAAI,MAAM,gCAAgC;AAAA,IAClD;AAEA,UAAM,WAA+B,KAAK;AAC1C,UAAM,oBAAyC,KAAK;AACpD,UAAM,QAAyC,KAAK;AACpD,UAAM,QAAyC,KAAK;AACpD,UAAM,sBAA0C,KAAK;AAErD,WAAO,KAAK,QAAQ;AACpB,sBAAkB,KAAK,mBAAmB;AAC1C,0BAAsB,KAAK,uBAAuB;AAClD,wBAAoB,KAAK,qBAAqB;AAC9C,UAAM,KAAK,OAAO;AAElB,Q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gE;AAChF,QAAI,MAAmC,CAAC;AACxC,QAAI,OAAO,QAAQ,UAAU;AAC3B,UAAI,WAAW;AAAA,IACjB,WAAW,KAAK;AACd,YAAM;AAAA,IACR;AACA,UAAM,OAAO,MAAM,KAAK,IAAI;AAAA,MAC1B;AAAA,MACA;AAAA,MACA,IAAI,mCAAmB,GAAG,EAAE,OAAO;AAAA,MACnC,MAAM,KAAK,WAAW,EAAE,cAAc,KAAK,CAAC;AAAA,IAC9C;AACA,WAAO,oCAAoB,SAAS,MAAM,EAAE,qBAAqB,KAAK,CAAC,EAAE,SAAS,CAAC;AAAA,EACrF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,WAAyC;AAC3D,UAAM,OAAO,MAAM,KAAK,IAAI;AAAA,MAC1B;AAAA,MACA;AAAA,MACA,IAAI,qCAAqB,EAAE,UAAU,CAAC,EAAE,OAAO;AAAA,MAC/C,MAAM,KAAK,WAAW,EAAE,cAAc,KAAK,CAAC;AAAA,IAC9C;AACA,WAAO,4BAAY,SAAS,MAAM,EAAE,qBAAqB,KAAK,CAAC;AAAA,EACjE;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/IngressClient.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { IngressAudioOptions, IngressInput, IngressVideoOptions } from '@livekit/protocol';\nimport {\n CreateIngressRequest,\n DeleteIngressRequest,\n IngressInfo,\n ListIngressRequest,\n ListIngressResponse,\n UpdateIngressRequest,\n} from '@livekit/protocol';\nimport type { ClientOptions } from './ClientOptions.js';\nimport { ServiceBase } from './ServiceBase.js';\nimport type { Rpc } from './TwirpRPC.js';\nimport { TwirpRpc, livekitPackage } from './TwirpRPC.js';\n\nconst svc = 'Ingress';\n\nexport interface CreateIngressOptions {\n /**\n * ingress name. optional\n */\n name?: string;\n /**\n * name of the room to send media to. required\n */\n roomName?: string;\n /**\n * unique identity of the participant. required\n */\n participantIdentity: string;\n /**\n * participant display name\n */\n participantName?: string;\n /**\n * metadata to attach to the participant\n */\n participantMetadata?: string;\n /**\n * @deprecated use `enableTranscoding` instead.\n * whether to skip transcoding and forward the input media directly. Only supported by WHIP\n */\n bypassTranscoding?: boolean;\n /**\n * whether to enable transcoding or forward the input media directly.\n * Transcoding is required for all input types except WHIP. For WHIP, the default is to not transcode.\n */\n enableTranscoding?: boolean | undefined;\n /**\n * url of the media to pull for ingresses of type URL\n */\n url?: string;\n /**\n * whether the ingress is enabled. When set to false, new connection attempts are rejected\n * while the stream key is preserved. The default is true.\n */\n enabled?: boolean;\n /**\n * custom audio encoding parameters. optional\n */\n audio?: IngressAudioOptions;\n /**\n * custom video encoding parameters. optional\n */\n video?: IngressVideoOptions;\n}\n\nexport interface UpdateIngressOptions {\n /**\n * ingress name. optional\n */\n name: string;\n /**\n * name of the room to send media to.\n */\n roomName?: string;\n /**\n * unique identity of the participant.\n */\n participantIdentity?: string;\n /**\n * participant display name\n */\n participantName?: string;\n /**\n * metadata to attach to the participant\n */\n participantMetadata?: string;\n /**\n * @deprecated use `enableTranscoding` instead\n * whether to skip transcoding and forward the input media directly. Only supported by WHIP\n */\n bypassTranscoding?: boolean | undefined;\n /**\n * whether to enable transcoding or forward the input media directly.\n * Transcoding is required for all input types except WHIP. For WHIP, the default is to not transcode.\n */\n enableTranscoding?: boolean | undefined;\n /**\n * whether the ingress is enabled. When set to false, new connection attempts are rejected\n * while the stream key is preserved. The default is true.\n */\n enabled?: boolean;\n /**\n * custom audio encoding parameters. optional\n */\n audio?: IngressAudioOptions;\n /**\n * custom video encoding parameters. optional\n */\n video?: IngressVideoOptions;\n}\n\nexport interface ListIngressOptions {\n /**\n * list ingress for one room only\n */\n roomName?: string;\n\n /**\n * list ingress by ID\n */\n ingressId?: string;\n}\n\n/**\n * Client to access Ingress APIs\n */\nexport class IngressClient extends ServiceBase {\n private readonly rpc: Rpc;\n\n /**\n * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'\n * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY\n * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET\n * @param options - client options\n */\n constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {\n super({ apiKey, secret, token: options?.token });\n this.rpc = new TwirpRpc(host, livekitPackage, {\n requestTimeout: options?.requestTimeout,\n failover: options?.failover,\n });\n }\n\n /**\n * @param inputType - protocol for the ingress\n * @param opts - CreateIngressOptions\n */\n async createIngress(inputType: IngressInput, opts: CreateIngressOptions): Promise<IngressInfo> {\n let name: string = '';\n let participantName: string = '';\n let participantIdentity: string = '';\n let bypassTranscoding: boolean = false;\n let url: string = '';\n\n if (opts == null) {\n throw new Error('options dictionary is required');\n }\n\n const roomName: string | undefined = opts.roomName;\n const enableTranscoding: boolean | undefined = opts.enableTranscoding;\n const enabled: boolean | undefined = opts.enabled;\n const audio: IngressAudioOptions | undefined = opts.audio;\n const video: IngressVideoOptions | undefined = opts.video;\n const participantMetadata: string | undefined = opts.participantMetadata;\n\n name = opts.name || '';\n participantName = opts.participantName || '';\n participantIdentity = opts.participantIdentity || '';\n bypassTranscoding = opts.bypassTranscoding || false;\n url = opts.url || '';\n\n if (typeof roomName == 'undefined') {\n throw new Error('required roomName option not provided');\n }\n\n if (participantIdentity == '') {\n throw new Error('required participantIdentity option not provided');\n }\n\n const req = new CreateIngressRequest({\n inputType,\n name,\n roomName,\n participantIdentity,\n participantMetadata,\n participantName,\n bypassTranscoding,\n enableTranscoding,\n url,\n enabled,\n audio,\n video,\n }).toJson();\n\n const data = await this.rpc.request(\n svc,\n 'CreateIngress',\n req,\n await this.authHeader({ ingressAdmin: true }),\n );\n return IngressInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * @param ingressId - ID of the ingress to update\n * @param opts - UpdateIngressOptions\n */\n async updateIngress(ingressId: string, opts: UpdateIngressOptions): Promise<IngressInfo> {\n const name: string = opts.name || '';\n const roomName: string = opts.roomName || '';\n const participantName: string = opts.participantName || '';\n const participantIdentity: string = opts.participantIdentity || '';\n const { participantMetadata } = opts;\n const { audio, video, bypassTranscoding, enableTranscoding, enabled } = opts;\n\n const req = new UpdateIngressRequest({\n ingressId,\n name,\n roomName,\n participantIdentity,\n participantName,\n participantMetadata,\n bypassTranscoding,\n enableTranscoding,\n enabled,\n audio,\n video,\n }).toJson();\n\n const data = await this.rpc.request(\n svc,\n 'UpdateIngress',\n req,\n await this.authHeader({ ingressAdmin: true }),\n );\n return IngressInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * @deprecated use `listIngress(opts)` or `listIngress(arg)` instead\n * @param roomName - list ingress for one room only\n */\n async listIngress(roomName?: string): Promise<Array<IngressInfo>>;\n /**\n * @param opts - list options\n */\n async listIngress(opts?: ListIngressOptions): Promise<Array<IngressInfo>>;\n /**\n * @param arg - list room name or options\n */\n async listIngress(arg?: string | ListIngressOptions): Promise<Array<IngressInfo>> {\n let req: Partial<ListIngressRequest> = {};\n if (typeof arg === 'string') {\n req.roomName = arg;\n } else if (arg) {\n req = arg;\n }\n const data = await this.rpc.request(\n svc,\n 'ListIngress',\n new ListIngressRequest(req).toJson(),\n await this.authHeader({ ingressAdmin: true }),\n );\n return ListIngressResponse.fromJson(data, { ignoreUnknownFields: true }).items ?? [];\n }\n\n /**\n * @param ingressId - ingress to delete\n */\n async deleteIngress(ingressId: string): Promise<IngressInfo> {\n const data = await this.rpc.request(\n svc,\n 'DeleteIngress',\n new DeleteIngressRequest({ ingressId }).toJson(),\n await this.authHeader({ ingressAdmin: true }),\n );\n return IngressInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAOO;AAEP,yBAA4B;AAE5B,sBAAyC;AAEzC,MAAM,MAAM;AAiHL,MAAM,sBAAsB,+BAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YAAY,MAAc,QAAiB,QAA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AA,MAC1B;AAAA,MACA;AAAA,MACA,IAAI,qCAAqB,EAAE,UAAU,CAAC,EAAE,OAAO;AAAA,MAC/C,MAAM,KAAK,WAAW,EAAE,cAAc,KAAK,CAAC;AAAA,IAC9C;AACA,WAAO,4BAAY,SAAS,MAAM,EAAE,qBAAqB,KAAK,CAAC;AAAA,EACjE;AACF;","names":[]}
|
package/dist/IngressClient.d.cts
CHANGED
|
@@ -39,6 +39,11 @@ interface CreateIngressOptions {
|
|
|
39
39
|
* url of the media to pull for ingresses of type URL
|
|
40
40
|
*/
|
|
41
41
|
url?: string;
|
|
42
|
+
/**
|
|
43
|
+
* whether the ingress is enabled. When set to false, new connection attempts are rejected
|
|
44
|
+
* while the stream key is preserved. The default is true.
|
|
45
|
+
*/
|
|
46
|
+
enabled?: boolean;
|
|
42
47
|
/**
|
|
43
48
|
* custom audio encoding parameters. optional
|
|
44
49
|
*/
|
|
@@ -79,6 +84,11 @@ interface UpdateIngressOptions {
|
|
|
79
84
|
* Transcoding is required for all input types except WHIP. For WHIP, the default is to not transcode.
|
|
80
85
|
*/
|
|
81
86
|
enableTranscoding?: boolean | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* whether the ingress is enabled. When set to false, new connection attempts are rejected
|
|
89
|
+
* while the stream key is preserved. The default is true.
|
|
90
|
+
*/
|
|
91
|
+
enabled?: boolean;
|
|
82
92
|
/**
|
|
83
93
|
* custom audio encoding parameters. optional
|
|
84
94
|
*/
|
package/dist/IngressClient.d.ts
CHANGED
|
@@ -39,6 +39,11 @@ interface CreateIngressOptions {
|
|
|
39
39
|
* url of the media to pull for ingresses of type URL
|
|
40
40
|
*/
|
|
41
41
|
url?: string;
|
|
42
|
+
/**
|
|
43
|
+
* whether the ingress is enabled. When set to false, new connection attempts are rejected
|
|
44
|
+
* while the stream key is preserved. The default is true.
|
|
45
|
+
*/
|
|
46
|
+
enabled?: boolean;
|
|
42
47
|
/**
|
|
43
48
|
* custom audio encoding parameters. optional
|
|
44
49
|
*/
|
|
@@ -79,6 +84,11 @@ interface UpdateIngressOptions {
|
|
|
79
84
|
* Transcoding is required for all input types except WHIP. For WHIP, the default is to not transcode.
|
|
80
85
|
*/
|
|
81
86
|
enableTranscoding?: boolean | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* whether the ingress is enabled. When set to false, new connection attempts are rejected
|
|
89
|
+
* while the stream key is preserved. The default is true.
|
|
90
|
+
*/
|
|
91
|
+
enabled?: boolean;
|
|
82
92
|
/**
|
|
83
93
|
* custom audio encoding parameters. optional
|
|
84
94
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IngressClient.d.ts","sourceRoot":"","sources":["../src/IngressClient.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAChG,OAAO,EAGL,WAAW,EAIZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAM/C,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,mBAAmB,EAAE,MAAM,CAAC;IAC5B;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACxC;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,mBAAmB,CAAC;IAC5B;;OAEG;IACH,KAAK,CAAC,EAAE,mBAAmB,CAAC;CAC7B;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;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,aAAc,SAAQ,WAAW;IAC5C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAM;IAE1B;;;;;OAKG;gBACS,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa;IAQnF;;;OAGG;IACG,aAAa,CAAC,SAAS,EAAE,YAAY,EAAE,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;IAwD9F;;;OAGG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,WAAW,CAAC;IA+BxF;;;OAGG;IACG,WAAW,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IACjE;;OAEG;IACG,WAAW,CAAC,IAAI,CAAC,EAAE,kBAAkB,GAAG,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;IAoBzE;;OAEG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;CAS7D"}
|
package/dist/IngressClient.js
CHANGED
|
@@ -38,6 +38,7 @@ class IngressClient extends ServiceBase {
|
|
|
38
38
|
}
|
|
39
39
|
const roomName = opts.roomName;
|
|
40
40
|
const enableTranscoding = opts.enableTranscoding;
|
|
41
|
+
const enabled = opts.enabled;
|
|
41
42
|
const audio = opts.audio;
|
|
42
43
|
const video = opts.video;
|
|
43
44
|
const participantMetadata = opts.participantMetadata;
|
|
@@ -62,6 +63,7 @@ class IngressClient extends ServiceBase {
|
|
|
62
63
|
bypassTranscoding,
|
|
63
64
|
enableTranscoding,
|
|
64
65
|
url,
|
|
66
|
+
enabled,
|
|
65
67
|
audio,
|
|
66
68
|
video
|
|
67
69
|
}).toJson();
|
|
@@ -83,7 +85,7 @@ class IngressClient extends ServiceBase {
|
|
|
83
85
|
const participantName = opts.participantName || "";
|
|
84
86
|
const participantIdentity = opts.participantIdentity || "";
|
|
85
87
|
const { participantMetadata } = opts;
|
|
86
|
-
const { audio, video, bypassTranscoding, enableTranscoding } = opts;
|
|
88
|
+
const { audio, video, bypassTranscoding, enableTranscoding, enabled } = opts;
|
|
87
89
|
const req = new UpdateIngressRequest({
|
|
88
90
|
ingressId,
|
|
89
91
|
name,
|
|
@@ -93,6 +95,7 @@ class IngressClient extends ServiceBase {
|
|
|
93
95
|
participantMetadata,
|
|
94
96
|
bypassTranscoding,
|
|
95
97
|
enableTranscoding,
|
|
98
|
+
enabled,
|
|
96
99
|
audio,
|
|
97
100
|
video
|
|
98
101
|
}).toJson();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/IngressClient.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { IngressAudioOptions, IngressInput, IngressVideoOptions } from '@livekit/protocol';\nimport {\n CreateIngressRequest,\n DeleteIngressRequest,\n IngressInfo,\n ListIngressRequest,\n ListIngressResponse,\n UpdateIngressRequest,\n} from '@livekit/protocol';\nimport type { ClientOptions } from './ClientOptions.js';\nimport { ServiceBase } from './ServiceBase.js';\nimport type { Rpc } from './TwirpRPC.js';\nimport { TwirpRpc, livekitPackage } from './TwirpRPC.js';\n\nconst svc = 'Ingress';\n\nexport interface CreateIngressOptions {\n /**\n * ingress name. optional\n */\n name?: string;\n /**\n * name of the room to send media to. required\n */\n roomName?: string;\n /**\n * unique identity of the participant. required\n */\n participantIdentity: string;\n /**\n * participant display name\n */\n participantName?: string;\n /**\n * metadata to attach to the participant\n */\n participantMetadata?: string;\n /**\n * @deprecated use `enableTranscoding` instead.\n * whether to skip transcoding and forward the input media directly. Only supported by WHIP\n */\n bypassTranscoding?: boolean;\n /**\n * whether to enable transcoding or forward the input media directly.\n * Transcoding is required for all input types except WHIP. For WHIP, the default is to not transcode.\n */\n enableTranscoding?: boolean | undefined;\n /**\n * url of the media to pull for ingresses of type URL\n */\n url?: string;\n /**\n * custom audio encoding parameters. optional\n */\n audio?: IngressAudioOptions;\n /**\n * custom video encoding parameters. optional\n */\n video?: IngressVideoOptions;\n}\n\nexport interface UpdateIngressOptions {\n /**\n * ingress name. optional\n */\n name: string;\n /**\n * name of the room to send media to.\n */\n roomName?: string;\n /**\n * unique identity of the participant.\n */\n participantIdentity?: string;\n /**\n * participant display name\n */\n participantName?: string;\n /**\n * metadata to attach to the participant\n */\n participantMetadata?: string;\n /**\n * @deprecated use `enableTranscoding` instead\n * whether to skip transcoding and forward the input media directly. Only supported by WHIP\n */\n bypassTranscoding?: boolean | undefined;\n /**\n * whether to enable transcoding or forward the input media directly.\n * Transcoding is required for all input types except WHIP. For WHIP, the default is to not transcode.\n */\n enableTranscoding?: boolean | undefined;\n /**\n * custom audio encoding parameters. optional\n */\n audio?: IngressAudioOptions;\n /**\n * custom video encoding parameters. optional\n */\n video?: IngressVideoOptions;\n}\n\nexport interface ListIngressOptions {\n /**\n * list ingress for one room only\n */\n roomName?: string;\n\n /**\n * list ingress by ID\n */\n ingressId?: string;\n}\n\n/**\n * Client to access Ingress APIs\n */\nexport class IngressClient extends ServiceBase {\n private readonly rpc: Rpc;\n\n /**\n * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'\n * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY\n * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET\n * @param options - client options\n */\n constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {\n super({ apiKey, secret, token: options?.token });\n this.rpc = new TwirpRpc(host, livekitPackage, {\n requestTimeout: options?.requestTimeout,\n failover: options?.failover,\n });\n }\n\n /**\n * @param inputType - protocol for the ingress\n * @param opts - CreateIngressOptions\n */\n async createIngress(inputType: IngressInput, opts: CreateIngressOptions): Promise<IngressInfo> {\n let name: string = '';\n let participantName: string = '';\n let participantIdentity: string = '';\n let bypassTranscoding: boolean = false;\n let url: string = '';\n\n if (opts == null) {\n throw new Error('options dictionary is required');\n }\n\n const roomName: string | undefined = opts.roomName;\n const enableTranscoding: boolean | undefined = opts.enableTranscoding;\n const audio: IngressAudioOptions | undefined = opts.audio;\n const video: IngressVideoOptions | undefined = opts.video;\n const participantMetadata: string | undefined = opts.participantMetadata;\n\n name = opts.name || '';\n participantName = opts.participantName || '';\n participantIdentity = opts.participantIdentity || '';\n bypassTranscoding = opts.bypassTranscoding || false;\n url = opts.url || '';\n\n if (typeof roomName == 'undefined') {\n throw new Error('required roomName option not provided');\n }\n\n if (participantIdentity == '') {\n throw new Error('required participantIdentity option not provided');\n }\n\n const req = new CreateIngressRequest({\n inputType,\n name,\n roomName,\n participantIdentity,\n participantMetadata,\n participantName,\n bypassTranscoding,\n enableTranscoding,\n url,\n audio,\n video,\n }).toJson();\n\n const data = await this.rpc.request(\n svc,\n 'CreateIngress',\n req,\n await this.authHeader({ ingressAdmin: true }),\n );\n return IngressInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * @param ingressId - ID of the ingress to update\n * @param opts - UpdateIngressOptions\n */\n async updateIngress(ingressId: string, opts: UpdateIngressOptions): Promise<IngressInfo> {\n const name: string = opts.name || '';\n const roomName: string = opts.roomName || '';\n const participantName: string = opts.participantName || '';\n const participantIdentity: string = opts.participantIdentity || '';\n const { participantMetadata } = opts;\n const { audio, video, bypassTranscoding, enableTranscoding } = opts;\n\n const req = new UpdateIngressRequest({\n ingressId,\n name,\n roomName,\n participantIdentity,\n participantName,\n participantMetadata,\n bypassTranscoding,\n enableTranscoding,\n audio,\n video,\n }).toJson();\n\n const data = await this.rpc.request(\n svc,\n 'UpdateIngress',\n req,\n await this.authHeader({ ingressAdmin: true }),\n );\n return IngressInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * @deprecated use `listIngress(opts)` or `listIngress(arg)` instead\n * @param roomName - list ingress for one room only\n */\n async listIngress(roomName?: string): Promise<Array<IngressInfo>>;\n /**\n * @param opts - list options\n */\n async listIngress(opts?: ListIngressOptions): Promise<Array<IngressInfo>>;\n /**\n * @param arg - list room name or options\n */\n async listIngress(arg?: string | ListIngressOptions): Promise<Array<IngressInfo>> {\n let req: Partial<ListIngressRequest> = {};\n if (typeof arg === 'string') {\n req.roomName = arg;\n } else if (arg) {\n req = arg;\n }\n const data = await this.rpc.request(\n svc,\n 'ListIngress',\n new ListIngressRequest(req).toJson(),\n await this.authHeader({ ingressAdmin: true }),\n );\n return ListIngressResponse.fromJson(data, { ignoreUnknownFields: true }).items ?? [];\n }\n\n /**\n * @param ingressId - ingress to delete\n */\n async deleteIngress(ingressId: string): Promise<IngressInfo> {\n const data = await this.rpc.request(\n svc,\n 'DeleteIngress',\n new DeleteIngressRequest({ ingressId }).toJson(),\n await this.authHeader({ ingressAdmin: true }),\n );\n return IngressInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n}\n"],"mappings":"AAIA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,mBAAmB;AAE5B,SAAS,UAAU,sBAAsB;AAEzC,MAAM,MAAM;AAuGL,MAAM,sBAAsB,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YAAY,MAAc,QAAiB,QAAiB,SAAyB;AACnF,UAAM,EAAE,QAAQ,QAAQ,OAAO,mCAAS,MAAM,CAAC;AAC/C,SAAK,MAAM,IAAI,SAAS,MAAM,gBAAgB;AAAA,MAC5C,gBAAgB,mCAAS;AAAA,MACzB,UAAU,mCAAS;AAAA,IACrB,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,cAAc,WAAyB,MAAkD;AAC7F,QAAI,OAAe;AACnB,QAAI,kBAA0B;AAC9B,QAAI,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;AAAA,MACnC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC,EAAE,OAAO;AAEV,UAAM,OAAO,MAAM,KAAK,IAAI;AAAA,MAC1B;AAAA,MACA;AAAA,MACA;AAAA,MACA,MAAM,KAAK,WAAW,EAAE,cAAc,KAAK,CAAC;AAAA,IAC9C;AACA,WAAO,YAAY,SAAS,MAAM,EAAE,qBAAqB,KAAK,CAAC;AAAA,EACjE;AAAA;AAAA;AAAA;AAAA,EAcA,MAAM,YAAY,KAAgE;AAChF,QAAI,MAAmC,CAAC;AACxC,QAAI,OAAO,QAAQ,UAAU;AAC3B,UAAI,WAAW;AAAA,IACjB,WAAW,KAAK;AACd,YAAM;AAAA,IACR;AACA,UAAM,OAAO,MAAM,KAAK,IAAI;AAAA,MAC1B;AAAA,MACA;AAAA,MACA,IAAI,mBAAmB,GAAG,EAAE,OAAO;AAAA,MACnC,MAAM,KAAK,WAAW,EAAE,cAAc,KAAK,CAAC;AAAA,IAC9C;AACA,WAAO,oBAAoB,SAAS,MAAM,EAAE,qBAAqB,KAAK,CAAC,EAAE,SAAS,CAAC;AAAA,EACrF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,WAAyC;AAC3D,UAAM,OAAO,MAAM,KAAK,IAAI;AAAA,MAC1B;AAAA,MACA;AAAA,MACA,IAAI,qBAAqB,EAAE,UAAU,CAAC,EAAE,OAAO;AAAA,MAC/C,MAAM,KAAK,WAAW,EAAE,cAAc,KAAK,CAAC;AAAA,IAC9C;AACA,WAAO,YAAY,SAAS,MAAM,EAAE,qBAAqB,KAAK,CAAC;AAAA,EACjE;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/IngressClient.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2024 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type { IngressAudioOptions, IngressInput, IngressVideoOptions } from '@livekit/protocol';\nimport {\n CreateIngressRequest,\n DeleteIngressRequest,\n IngressInfo,\n ListIngressRequest,\n ListIngressResponse,\n UpdateIngressRequest,\n} from '@livekit/protocol';\nimport type { ClientOptions } from './ClientOptions.js';\nimport { ServiceBase } from './ServiceBase.js';\nimport type { Rpc } from './TwirpRPC.js';\nimport { TwirpRpc, livekitPackage } from './TwirpRPC.js';\n\nconst svc = 'Ingress';\n\nexport interface CreateIngressOptions {\n /**\n * ingress name. optional\n */\n name?: string;\n /**\n * name of the room to send media to. required\n */\n roomName?: string;\n /**\n * unique identity of the participant. required\n */\n participantIdentity: string;\n /**\n * participant display name\n */\n participantName?: string;\n /**\n * metadata to attach to the participant\n */\n participantMetadata?: string;\n /**\n * @deprecated use `enableTranscoding` instead.\n * whether to skip transcoding and forward the input media directly. Only supported by WHIP\n */\n bypassTranscoding?: boolean;\n /**\n * whether to enable transcoding or forward the input media directly.\n * Transcoding is required for all input types except WHIP. For WHIP, the default is to not transcode.\n */\n enableTranscoding?: boolean | undefined;\n /**\n * url of the media to pull for ingresses of type URL\n */\n url?: string;\n /**\n * whether the ingress is enabled. When set to false, new connection attempts are rejected\n * while the stream key is preserved. The default is true.\n */\n enabled?: boolean;\n /**\n * custom audio encoding parameters. optional\n */\n audio?: IngressAudioOptions;\n /**\n * custom video encoding parameters. optional\n */\n video?: IngressVideoOptions;\n}\n\nexport interface UpdateIngressOptions {\n /**\n * ingress name. optional\n */\n name: string;\n /**\n * name of the room to send media to.\n */\n roomName?: string;\n /**\n * unique identity of the participant.\n */\n participantIdentity?: string;\n /**\n * participant display name\n */\n participantName?: string;\n /**\n * metadata to attach to the participant\n */\n participantMetadata?: string;\n /**\n * @deprecated use `enableTranscoding` instead\n * whether to skip transcoding and forward the input media directly. Only supported by WHIP\n */\n bypassTranscoding?: boolean | undefined;\n /**\n * whether to enable transcoding or forward the input media directly.\n * Transcoding is required for all input types except WHIP. For WHIP, the default is to not transcode.\n */\n enableTranscoding?: boolean | undefined;\n /**\n * whether the ingress is enabled. When set to false, new connection attempts are rejected\n * while the stream key is preserved. The default is true.\n */\n enabled?: boolean;\n /**\n * custom audio encoding parameters. optional\n */\n audio?: IngressAudioOptions;\n /**\n * custom video encoding parameters. optional\n */\n video?: IngressVideoOptions;\n}\n\nexport interface ListIngressOptions {\n /**\n * list ingress for one room only\n */\n roomName?: string;\n\n /**\n * list ingress by ID\n */\n ingressId?: string;\n}\n\n/**\n * Client to access Ingress APIs\n */\nexport class IngressClient extends ServiceBase {\n private readonly rpc: Rpc;\n\n /**\n * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'\n * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY\n * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET\n * @param options - client options\n */\n constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {\n super({ apiKey, secret, token: options?.token });\n this.rpc = new TwirpRpc(host, livekitPackage, {\n requestTimeout: options?.requestTimeout,\n failover: options?.failover,\n });\n }\n\n /**\n * @param inputType - protocol for the ingress\n * @param opts - CreateIngressOptions\n */\n async createIngress(inputType: IngressInput, opts: CreateIngressOptions): Promise<IngressInfo> {\n let name: string = '';\n let participantName: string = '';\n let participantIdentity: string = '';\n let bypassTranscoding: boolean = false;\n let url: string = '';\n\n if (opts == null) {\n throw new Error('options dictionary is required');\n }\n\n const roomName: string | undefined = opts.roomName;\n const enableTranscoding: boolean | undefined = opts.enableTranscoding;\n const enabled: boolean | undefined = opts.enabled;\n const audio: IngressAudioOptions | undefined = opts.audio;\n const video: IngressVideoOptions | undefined = opts.video;\n const participantMetadata: string | undefined = opts.participantMetadata;\n\n name = opts.name || '';\n participantName = opts.participantName || '';\n participantIdentity = opts.participantIdentity || '';\n bypassTranscoding = opts.bypassTranscoding || false;\n url = opts.url || '';\n\n if (typeof roomName == 'undefined') {\n throw new Error('required roomName option not provided');\n }\n\n if (participantIdentity == '') {\n throw new Error('required participantIdentity option not provided');\n }\n\n const req = new CreateIngressRequest({\n inputType,\n name,\n roomName,\n participantIdentity,\n participantMetadata,\n participantName,\n bypassTranscoding,\n enableTranscoding,\n url,\n enabled,\n audio,\n video,\n }).toJson();\n\n const data = await this.rpc.request(\n svc,\n 'CreateIngress',\n req,\n await this.authHeader({ ingressAdmin: true }),\n );\n return IngressInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * @param ingressId - ID of the ingress to update\n * @param opts - UpdateIngressOptions\n */\n async updateIngress(ingressId: string, opts: UpdateIngressOptions): Promise<IngressInfo> {\n const name: string = opts.name || '';\n const roomName: string = opts.roomName || '';\n const participantName: string = opts.participantName || '';\n const participantIdentity: string = opts.participantIdentity || '';\n const { participantMetadata } = opts;\n const { audio, video, bypassTranscoding, enableTranscoding, enabled } = opts;\n\n const req = new UpdateIngressRequest({\n ingressId,\n name,\n roomName,\n participantIdentity,\n participantName,\n participantMetadata,\n bypassTranscoding,\n enableTranscoding,\n enabled,\n audio,\n video,\n }).toJson();\n\n const data = await this.rpc.request(\n svc,\n 'UpdateIngress',\n req,\n await this.authHeader({ ingressAdmin: true }),\n );\n return IngressInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * @deprecated use `listIngress(opts)` or `listIngress(arg)` instead\n * @param roomName - list ingress for one room only\n */\n async listIngress(roomName?: string): Promise<Array<IngressInfo>>;\n /**\n * @param opts - list options\n */\n async listIngress(opts?: ListIngressOptions): Promise<Array<IngressInfo>>;\n /**\n * @param arg - list room name or options\n */\n async listIngress(arg?: string | ListIngressOptions): Promise<Array<IngressInfo>> {\n let req: Partial<ListIngressRequest> = {};\n if (typeof arg === 'string') {\n req.roomName = arg;\n } else if (arg) {\n req = arg;\n }\n const data = await this.rpc.request(\n svc,\n 'ListIngress',\n new ListIngressRequest(req).toJson(),\n await this.authHeader({ ingressAdmin: true }),\n );\n return ListIngressResponse.fromJson(data, { ignoreUnknownFields: true }).items ?? [];\n }\n\n /**\n * @param ingressId - ingress to delete\n */\n async deleteIngress(ingressId: string): Promise<IngressInfo> {\n const data = await this.rpc.request(\n svc,\n 'DeleteIngress',\n new DeleteIngressRequest({ ingressId }).toJson(),\n await this.authHeader({ ingressAdmin: true }),\n );\n return IngressInfo.fromJson(data, { ignoreUnknownFields: true });\n }\n}\n"],"mappings":"AAIA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,mBAAmB;AAE5B,SAAS,UAAU,sBAAsB;AAEzC,MAAM,MAAM;AAiHL,MAAM,sBAAsB,YAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS7C,YAAY,MAAc,QAAiB,QAAiB,SAAyB;AACnF,UAAM,EAAE,QAAQ,QAAQ,OAAO,mCAAS,MAAM,CAAC;AAC/C,SAAK,MAAM,IAAI,SAAS,MAAM,gBAAgB;AAAA,MAC5C,gBAAgB,mCAAS;AAAA,MACzB,UAAU,mCAAS;AAAA,IACrB,CAAC;AAAA,EACH;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,cAAc,WAAyB,MAAkD;AAC7F,QAAI,OAAe;AACnB,QAAI,kBAA0B;AAC9B,QAAI,sBAA8B;AAClC,QAAI,oBAA6B;AACjC,QAAI,MAAc;AAElB,QAAI,QAAQ,MAAM;AAChB,YAAM,IAAI,MAAM,gCAAgC;AAAA,IAClD;AAEA,UAAM,WAA+B,KAAK;AAC1C,UAAM,oBAAyC,KAAK;AACpD,UAAM,UAA+B,KAAK;AAC1C,UAAM,QAAyC,KAAK;AACpD,UAAM,QAAyC,KAAK;AACpD,UAAM,sBAA0C,KAAK;AAErD,WAAO,KAAK,QAAQ;AACpB,sBAAkB,KAAK,mBAAmB;AAC1C,0BAAsB,KAAK,uBAAuB;AAClD,wBAAoB,KAAK,qBAAqB;AAC9C,UAAM,KAAK,OAAO;AAElB,QAAI,OAAO,YAAY,aAAa;AAClC,YAAM,IAAI,MAAM,uCAAuC;AAAA,IACzD;AAEA,QAA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,UAAU;AAC3B,UAAI,WAAW;AAAA,IACjB,WAAW,KAAK;AACd,YAAM;AAAA,IACR;AACA,UAAM,OAAO,MAAM,KAAK,IAAI;AAAA,MAC1B;AAAA,MACA;AAAA,MACA,IAAI,mBAAmB,GAAG,EAAE,OAAO;AAAA,MACnC,MAAM,KAAK,WAAW,EAAE,cAAc,KAAK,CAAC;AAAA,IAC9C;AACA,WAAO,oBAAoB,SAAS,MAAM,EAAE,qBAAqB,KAAK,CAAC,EAAE,SAAS,CAAC;AAAA,EACrF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,cAAc,WAAyC;AAC3D,UAAM,OAAO,MAAM,KAAK,IAAI;AAAA,MAC1B;AAAA,MACA;AAAA,MACA,IAAI,qBAAqB,EAAE,UAAU,CAAC,EAAE,OAAO;AAAA,MAC/C,MAAM,KAAK,WAAW,EAAE,cAAc,KAAK,CAAC;AAAA,IAC9C;AACA,WAAO,YAAY,SAAS,MAAM,EAAE,qBAAqB,KAAK,CAAC;AAAA,EACjE;AACF;","names":[]}
|
package/dist/TwirpRPC.cjs
CHANGED
|
@@ -18,6 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var TwirpRPC_exports = {};
|
|
20
20
|
__export(TwirpRPC_exports, {
|
|
21
|
+
REQUEST_ID_HEADER: () => REQUEST_ID_HEADER,
|
|
21
22
|
ServerError: () => ServerError,
|
|
22
23
|
SipCallError: () => SipCallError,
|
|
23
24
|
TwirpError: () => TwirpError,
|
|
@@ -25,9 +26,11 @@ __export(TwirpRPC_exports, {
|
|
|
25
26
|
livekitPackage: () => livekitPackage
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(TwirpRPC_exports);
|
|
29
|
+
var import_uuid = require("./crypto/uuid.cjs");
|
|
28
30
|
var import_failover = require("./failover.cjs");
|
|
29
31
|
var import_version = require("./version.cjs");
|
|
30
32
|
const USER_AGENT = `livekit-server-sdk-node/${import_version.SDK_VERSION}`;
|
|
33
|
+
const REQUEST_ID_HEADER = "X-Livekit-Request-Id";
|
|
31
34
|
const defaultPrefix = "/twirp";
|
|
32
35
|
const defaultTimeoutSeconds = 10;
|
|
33
36
|
const livekitPackage = "livekit";
|
|
@@ -109,6 +112,7 @@ class TwirpRpc {
|
|
|
109
112
|
"User-Agent": USER_AGENT,
|
|
110
113
|
...headers
|
|
111
114
|
};
|
|
115
|
+
requestHeaders[REQUEST_ID_HEADER] = await (0, import_uuid.randomUUID)();
|
|
112
116
|
const origin = new URL(this.host);
|
|
113
117
|
const maxAttempts = (0, import_failover.failoverAttempts)(
|
|
114
118
|
this.failover,
|
|
@@ -187,6 +191,7 @@ async function toTwirpError(response) {
|
|
|
187
191
|
}
|
|
188
192
|
// Annotate the CommonJS export names for ESM import in node:
|
|
189
193
|
0 && (module.exports = {
|
|
194
|
+
REQUEST_ID_HEADER,
|
|
190
195
|
ServerError,
|
|
191
196
|
SipCallError,
|
|
192
197
|
TwirpError,
|
package/dist/TwirpRPC.cjs.map
CHANGED
|
@@ -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';\nimport {\n FAILOVER_BACKOFF_BASE_MS,\n failoverAttempts,\n hostKey,\n pickNext,\n regionOrigins,\n sleep,\n} from './failover.js';\nimport { SDK_VERSION } from './version.js';\n\n// Identifies the SDK and version to the server on every request. Browsers forbid\n// setting User-Agent via fetch and silently drop it; Node honors it.\nconst USER_AGENT = `livekit-server-sdk-node/${SDK_VERSION}`;\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 /** Whether region failover is enabled (LiveKit Cloud hosts only). Defaults to true. */\n failover?: boolean;\n /** @internal test-only: force failover regardless of host. */\n failoverForce?: boolean;\n /** @internal test-only: base retry backoff in ms. */\n failoverBackoffMs?: number;\n};\n\nconst defaultPrefix = '/twirp';\nconst defaultTimeoutSeconds = 10;\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 ServerError 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/** @deprecated use {@link ServerError} */\nexport const TwirpError = ServerError;\n/** @deprecated use {@link ServerError} */\nexport type TwirpError = ServerError;\n\n/**\n * A {@link ServerError} from a SIP dialing call (`createSipParticipant` /\n * `transferSipParticipant`) that failed with a SIP response status. The SIP code\n * and reason are exposed as getters; any other error metadata remains available\n * via {@link ServerError.metadata}.\n */\nexport class SipCallError extends ServerError {\n constructor(\n name: string,\n message: string,\n status: number,\n code?: string,\n metadata?: Record<string, string>,\n ) {\n super(name, SipCallError.describe(message, code, metadata), status, code, metadata);\n this.name = 'SipCallError';\n }\n\n /** The SIP response code of the failed call, e.g. 486 (Busy Here). */\n get sipStatusCode(): number | undefined {\n const raw = this.metadata?.sip_status_code;\n return raw !== undefined ? Number(raw) : undefined;\n }\n\n /** The SIP reason phrase of the failed call, e.g. \"Busy Here\". */\n get sipStatus(): string | undefined {\n return this.metadata?.sip_status;\n }\n\n /** Builds a SipCallError from a ServerError, preserving its code and metadata. */\n static fromServerError(err: ServerError): SipCallError {\n return new SipCallError(err.name, err.message, err.status, err.code, err.metadata);\n }\n\n // describe renders a clear message: the SIP status, the error code, and any\n // other metadata the server attached. Falls back to the raw message when the\n // error carries no SIP status.\n private static describe(fallback: string, code?: string, metadata?: Record<string, string>) {\n const sipCode = metadata?.sip_status_code;\n if (!sipCode) {\n return fallback;\n }\n const reason = metadata?.sip_status;\n let msg = `SIP call failed: ${sipCode}${reason ? ` ${reason}` : ''}`;\n if (code) {\n msg += ` (${code})`;\n }\n const extra = Object.entries(metadata ?? {})\n .filter(([k]) => k !== 'sip_status_code' && k !== 'sip_status' && k !== 'error_details')\n .map(([k, v]) => `${k}=${v}`);\n if (extra.length) {\n msg += ` [${extra.join(', ')}]`;\n }\n return msg;\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 failover: boolean;\n\n private failoverForce: boolean;\n\n private failoverBackoffMs: 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 this.failover = options?.failover ?? true;\n this.failoverForce = options?.failoverForce ?? false;\n this.failoverBackoffMs = options?.failoverBackoffMs ?? FAILOVER_BACKOFF_BASE_MS;\n }\n\n /**\n * Issues a Twirp request, failing over to alternative regions on retryable\n * errors. On any transport error or HTTP 5xx it discovers regions via\n * /settings/regions and replays the request — body and headers intact —\n * against the next untried region, with exponential backoff. A 4xx is\n * returned immediately.\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 body = JSON.stringify(data);\n const requestHeaders = {\n 'Content-Type': 'application/json;charset=UTF-8',\n 'User-Agent': USER_AGENT,\n ...headers,\n };\n\n const origin = new URL(this.host);\n const maxAttempts = failoverAttempts(\n this.failover,\n origin.hostname,\n this.failoverForce,\n timeout,\n );\n const attempted = new Set([hostKey(origin)]);\n let regions: string[] | undefined;\n let current = this.host;\n\n for (let attempt = 0; attempt < maxAttempts; attempt += 1) {\n const isLast = attempt + 1 >= maxAttempts;\n const init: RequestInit = { method: 'POST', headers: requestHeaders, body };\n if (timeout) {\n init.signal = AbortSignal.timeout(timeout * 1000);\n }\n\n let response: Response | undefined;\n let transportError: unknown;\n try {\n response = await fetch(new URL(path, current), init);\n } catch (e) {\n transportError = e;\n }\n\n if (response?.ok) {\n // Return the raw JSON. Every caller parses it with protobuf-es\n // fromJson(), which per the proto3 JSON spec accepts both the proto\n // field names (snake_case) and their json_name (camelCase), so no key\n // conversion is needed. Converting keys would also corrupt map<string,…>\n // entries (e.g. participant attributes), whose keys are user data.\n return (await response.json()) as Record<string, unknown>;\n }\n\n // Only retryable failures (a transport error or HTTP 5xx) continue;\n // a 4xx is terminal.\n const retryable = transportError !== undefined || (!!response && response.status >= 500);\n let next: string | undefined;\n if (retryable && !isLast) {\n if (!regions) {\n regions = await regionOrigins(origin, headers);\n }\n next = pickNext(regions, attempted);\n }\n\n if (!retryable || next === undefined) {\n if (response) {\n throw await toTwirpError(response);\n }\n throw transportError;\n }\n\n const reason = response ? `status ${response.status}` : transportError;\n console.warn(\n `livekit API request to ${new URL(current).host} failed (${reason}), retrying with fallback url ${next}`,\n );\n await sleep(this.failoverBackoffMs * 2 ** attempt);\n attempted.add(hostKey(new URL(next)));\n current = next;\n }\n\n throw new Error('failover loop exited without returning'); // unreachable\n }\n}\n\n/** Builds a TwirpError from a non-2xx response, mirroring Twirp's JSON error shape. */\nasync function toTwirpError(response: Response): Promise<TwirpError> {\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 return new TwirpError(response.statusText, errorMessage, response.status, errorCode, metadata);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,sBAOO;AACP,qBAA4B;AAI5B,MAAM,aAAa,2BAA2B,0BAAW;AAiBzD,MAAM,gBAAgB;AACtB,MAAM,wBAAwB;AAEvB,MAAM,iBAAiB;AAWvB,MAAM,oBAAoB,MAAM;AAAA,EAKrC,YACE,MACA,SACA,QACA,MACA,UACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EAClB;AACF;AAGO,MAAM,aAAa;AAUnB,MAAM,qBAAqB,YAAY;AAAA,EAC5C,YACE,MACA,SACA,QACA,MACA,UACA;AACA,UAAM,MAAM,aAAa,SAAS,SAAS,MAAM,QAAQ,GAAG,QAAQ,MAAM,QAAQ;AAClF,SAAK,OAAO;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,gBAAoC;AA3F1C;AA4FI,UAAM,OAAM,UAAK,aAAL,mBAAe;AAC3B,WAAO,QAAQ,SAAY,OAAO,GAAG,IAAI;AAAA,EAC3C;AAAA;AAAA,EAGA,IAAI,YAAgC;AAjGtC;AAkGI,YAAO,UAAK,aAAL,mBAAe;AAAA,EACxB;AAAA;AAAA,EAGA,OAAO,gBAAgB,KAAgC;AACrD,WAAO,IAAI,aAAa,IAAI,MAAM,IAAI,SAAS,IAAI,QAAQ,IAAI,MAAM,IAAI,QAAQ;AAAA,EACnF;AAAA;AAAA;AAAA;AAAA,EAKA,OAAe,SAAS,UAAkB,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C;AACpC,gBAAU;AAAA,IACZ;AAEA,UAAM,IAAI,MAAM,wCAAwC;AAAA,EAC1D;AACF;AAGA,eAAe,aAAa,UAAyC;AACnE,QAAM,SAAS,SAAS,QAAQ,IAAI,cAAc,MAAM;AACxD,MAAI,eAAe;AACnB,MAAI,YAAgC;AACpC,MAAI,WAA+C;AACnD,MAAI;AACF,QAAI,QAAQ;AACV,YAAM,cAAe,MAAM,SAAS,KAAK;AACzC,UAAI,SAAS,aAAa;AACxB,uBAAuB,YAAY;AAAA,MACrC;AACA,UAAI,UAAU,aAAa;AACzB,oBAAoB,YAAY;AAAA,MAClC;AACA,UAAI,UAAU,aAAa;AACzB,mBAAmC,YAAY;AAAA,MACjD;AAAA,IACF,OAAO;AACL,qBAAe,MAAM,SAAS,KAAK;AAAA,IACrC;AAAA,EACF,SAAS,GAAG;AAEV,YAAQ,MAAM,4DAA4D,CAAC;AAAA,EAC7E;AACA,SAAO,IAAI,WAAW,SAAS,YAAY,cAAc,SAAS,QAAQ,WAAW,QAAQ;AAC/F;","names":[]}
|
|
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';\nimport { randomUUID } from './crypto/uuid.js';\nimport {\n FAILOVER_BACKOFF_BASE_MS,\n failoverAttempts,\n hostKey,\n pickNext,\n regionOrigins,\n sleep,\n} from './failover.js';\nimport { SDK_VERSION } from './version.js';\n\n// Identifies the SDK and version to the server on every request. Browsers forbid\n// setting User-Agent via fetch and silently drop it; Node honors it.\nconst USER_AGENT = `livekit-server-sdk-node/${SDK_VERSION}`;\n\n// Carries a per-request idempotency key. The SDK's auto-retries (see failover)\n// keep the same key across attempts, so the server can identify and deduplicate\n// repeated requests.\nexport const REQUEST_ID_HEADER = 'X-Livekit-Request-Id';\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 /** Whether region failover is enabled (LiveKit Cloud hosts only). Defaults to true. */\n failover?: boolean;\n /** @internal test-only: force failover regardless of host. */\n failoverForce?: boolean;\n /** @internal test-only: base retry backoff in ms. */\n failoverBackoffMs?: number;\n};\n\nconst defaultPrefix = '/twirp';\nconst defaultTimeoutSeconds = 10;\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 ServerError 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/** @deprecated use {@link ServerError} */\nexport const TwirpError = ServerError;\n/** @deprecated use {@link ServerError} */\nexport type TwirpError = ServerError;\n\n/**\n * A {@link ServerError} from a SIP dialing call (`createSipParticipant` /\n * `transferSipParticipant`) that failed with a SIP response status. The SIP code\n * and reason are exposed as getters; any other error metadata remains available\n * via {@link ServerError.metadata}.\n */\nexport class SipCallError extends ServerError {\n constructor(\n name: string,\n message: string,\n status: number,\n code?: string,\n metadata?: Record<string, string>,\n ) {\n super(name, SipCallError.describe(message, code, metadata), status, code, metadata);\n this.name = 'SipCallError';\n }\n\n /** The SIP response code of the failed call, e.g. 486 (Busy Here). */\n get sipStatusCode(): number | undefined {\n const raw = this.metadata?.sip_status_code;\n return raw !== undefined ? Number(raw) : undefined;\n }\n\n /** The SIP reason phrase of the failed call, e.g. \"Busy Here\". */\n get sipStatus(): string | undefined {\n return this.metadata?.sip_status;\n }\n\n /** Builds a SipCallError from a ServerError, preserving its code and metadata. */\n static fromServerError(err: ServerError): SipCallError {\n return new SipCallError(err.name, err.message, err.status, err.code, err.metadata);\n }\n\n // describe renders a clear message: the SIP status, the error code, and any\n // other metadata the server attached. Falls back to the raw message when the\n // error carries no SIP status.\n private static describe(fallback: string, code?: string, metadata?: Record<string, string>) {\n const sipCode = metadata?.sip_status_code;\n if (!sipCode) {\n return fallback;\n }\n const reason = metadata?.sip_status;\n let msg = `SIP call failed: ${sipCode}${reason ? ` ${reason}` : ''}`;\n if (code) {\n msg += ` (${code})`;\n }\n const extra = Object.entries(metadata ?? {})\n .filter(([k]) => k !== 'sip_status_code' && k !== 'sip_status' && k !== 'error_details')\n .map(([k, v]) => `${k}=${v}`);\n if (extra.length) {\n msg += ` [${extra.join(', ')}]`;\n }\n return msg;\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 failover: boolean;\n\n private failoverForce: boolean;\n\n private failoverBackoffMs: 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 this.failover = options?.failover ?? true;\n this.failoverForce = options?.failoverForce ?? false;\n this.failoverBackoffMs = options?.failoverBackoffMs ?? FAILOVER_BACKOFF_BASE_MS;\n }\n\n /**\n * Issues a Twirp request, failing over to alternative regions on retryable\n * errors. On any transport error or HTTP 5xx it discovers regions via\n * /settings/regions and replays the request — body and headers intact —\n * against the next untried region, with exponential backoff. A 4xx is\n * returned immediately.\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 body = JSON.stringify(data);\n const requestHeaders: Record<string, string> = {\n 'Content-Type': 'application/json;charset=UTF-8',\n 'User-Agent': USER_AGENT,\n ...headers,\n };\n requestHeaders[REQUEST_ID_HEADER] = await randomUUID();\n\n const origin = new URL(this.host);\n const maxAttempts = failoverAttempts(\n this.failover,\n origin.hostname,\n this.failoverForce,\n timeout,\n );\n const attempted = new Set([hostKey(origin)]);\n let regions: string[] | undefined;\n let current = this.host;\n\n for (let attempt = 0; attempt < maxAttempts; attempt += 1) {\n const isLast = attempt + 1 >= maxAttempts;\n const init: RequestInit = { method: 'POST', headers: requestHeaders, body };\n if (timeout) {\n init.signal = AbortSignal.timeout(timeout * 1000);\n }\n\n let response: Response | undefined;\n let transportError: unknown;\n try {\n response = await fetch(new URL(path, current), init);\n } catch (e) {\n transportError = e;\n }\n\n if (response?.ok) {\n // Return the raw JSON. Every caller parses it with protobuf-es\n // fromJson(), which per the proto3 JSON spec accepts both the proto\n // field names (snake_case) and their json_name (camelCase), so no key\n // conversion is needed. Converting keys would also corrupt map<string,…>\n // entries (e.g. participant attributes), whose keys are user data.\n return (await response.json()) as Record<string, unknown>;\n }\n\n // Only retryable failures (a transport error or HTTP 5xx) continue;\n // a 4xx is terminal.\n const retryable = transportError !== undefined || (!!response && response.status >= 500);\n let next: string | undefined;\n if (retryable && !isLast) {\n if (!regions) {\n regions = await regionOrigins(origin, headers);\n }\n next = pickNext(regions, attempted);\n }\n\n if (!retryable || next === undefined) {\n if (response) {\n throw await toTwirpError(response);\n }\n throw transportError;\n }\n\n const reason = response ? `status ${response.status}` : transportError;\n console.warn(\n `livekit API request to ${new URL(current).host} failed (${reason}), retrying with fallback url ${next}`,\n );\n await sleep(this.failoverBackoffMs * 2 ** attempt);\n attempted.add(hostKey(new URL(next)));\n current = next;\n }\n\n throw new Error('failover loop exited without returning'); // unreachable\n }\n}\n\n/** Builds a TwirpError from a non-2xx response, mirroring Twirp's JSON error shape. */\nasync function toTwirpError(response: Response): Promise<TwirpError> {\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 return new TwirpError(response.statusText, errorMessage, response.status, errorCode, metadata);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,kBAA2B;AAC3B,sBAOO;AACP,qBAA4B;AAI5B,MAAM,aAAa,2BAA2B,0BAAW;AAKlD,MAAM,oBAAoB;AAiBjC,MAAM,gBAAgB;AACtB,MAAM,wBAAwB;AAEvB,MAAM,iBAAiB;AAWvB,MAAM,oBAAoB,MAAM;AAAA,EAKrC,YACE,MACA,SACA,QACA,MACA,UACA;AACA,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,OAAO;AACZ,SAAK,WAAW;AAAA,EAClB;AACF;AAGO,MAAM,aAAa;AAUnB,MAAM,qBAAqB,YAAY;AAAA,EAC5C,YACE,MACA,SACA,QACA,MACA,UACA;AACA,UAAM,MAAM,aAAa,SAAS,SAAS,MAAM,QAAQ,GAAG,QAAQ,MAAM,QAAQ;AAClF,SAAK,OAAO;AAAA,EACd;AAAA;AAAA,EAGA,IAAI,gBAAoC;AAjG1C;AAkGI,UAAM,OAAM,UAAK,aAAL,mBAAe;AAC3B,WAAO,QAAQ,SAAY,OAAO,GAAG,IAAI;AAAA,EAC3C;AAAA;AAAA,EAGA,IAAI,YAAgC;AAvGtC;AAwGI,YAAO,UAAK,aAAL,mBAAe;AAAA,EACxB;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W,UAAU,SAAS,MAAM,KAAK;AACxD,cAAQ;AAAA,QACN,0BAA0B,IAAI,IAAI,OAAO,EAAE,IAAI,YAAY,MAAM,iCAAiC,IAAI;AAAA,MACxG;AACA,gBAAM,uBAAM,KAAK,oBAAoB,KAAK,OAAO;AACjD,gBAAU,QAAI,yBAAQ,IAAI,IAAI,IAAI,CAAC,CAAC;AACpC,gBAAU;AAAA,IACZ;AAEA,UAAM,IAAI,MAAM,wCAAwC;AAAA,EAC1D;AACF;AAGA,eAAe,aAAa,UAAyC;AACnE,QAAM,SAAS,SAAS,QAAQ,IAAI,cAAc,MAAM;AACxD,MAAI,eAAe;AACnB,MAAI,YAAgC;AACpC,MAAI,WAA+C;AACnD,MAAI;AACF,QAAI,QAAQ;AACV,YAAM,cAAe,MAAM,SAAS,KAAK;AACzC,UAAI,SAAS,aAAa;AACxB,uBAAuB,YAAY;AAAA,MACrC;AACA,UAAI,UAAU,aAAa;AACzB,oBAAoB,YAAY;AAAA,MAClC;AACA,UAAI,UAAU,aAAa;AACzB,mBAAmC,YAAY;AAAA,MACjD;AAAA,IACF,OAAO;AACL,qBAAe,MAAM,SAAS,KAAK;AAAA,IACrC;AAAA,EACF,SAAS,GAAG;AAEV,YAAQ,MAAM,4DAA4D,CAAC;AAAA,EAC7E;AACA,SAAO,IAAI,WAAW,SAAS,YAAY,cAAc,SAAS,QAAQ,WAAW,QAAQ;AAC/F;","names":[]}
|
package/dist/TwirpRPC.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JsonValue } from '@bufbuild/protobuf';
|
|
2
2
|
|
|
3
|
+
declare const REQUEST_ID_HEADER = "X-Livekit-Request-Id";
|
|
3
4
|
type Options = {
|
|
4
5
|
/** Prefix for the RPC requests */
|
|
5
6
|
prefix?: string;
|
|
@@ -67,4 +68,4 @@ declare class TwirpRpc {
|
|
|
67
68
|
timeout?: number): Promise<any>;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
export { type Rpc, ServerError, SipCallError, TwirpError, TwirpRpc, livekitPackage };
|
|
71
|
+
export { REQUEST_ID_HEADER, type Rpc, ServerError, SipCallError, TwirpError, TwirpRpc, livekitPackage };
|
package/dist/TwirpRPC.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { JsonValue } from '@bufbuild/protobuf';
|
|
2
2
|
|
|
3
|
+
declare const REQUEST_ID_HEADER = "X-Livekit-Request-Id";
|
|
3
4
|
type Options = {
|
|
4
5
|
/** Prefix for the RPC requests */
|
|
5
6
|
prefix?: string;
|
|
@@ -67,4 +68,4 @@ declare class TwirpRpc {
|
|
|
67
68
|
timeout?: number): Promise<any>;
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
export { type Rpc, ServerError, SipCallError, TwirpError, TwirpRpc, livekitPackage };
|
|
71
|
+
export { REQUEST_ID_HEADER, type Rpc, ServerError, SipCallError, TwirpError, TwirpRpc, livekitPackage };
|
package/dist/TwirpRPC.d.ts.map
CHANGED
|
@@ -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;
|
|
1
|
+
{"version":3,"file":"TwirpRPC.d.ts","sourceRoot":"","sources":["../src/TwirpRPC.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAmBpD,eAAO,MAAM,iBAAiB,yBAAyB,CAAC;AAIxD,KAAK,OAAO,GAAG;IACb,kCAAkC;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,wGAAwG;IACxG,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,uFAAuF;IACvF,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,8DAA8D;IAC9D,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,qDAAqD;IACrD,iBAAiB,CAAC,EAA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AAC;IAEb,GAAG,EAAE,MAAM,CAAC;IAEZ,MAAM,EAAE,MAAM,CAAC;IAEf,cAAc,EAAE,MAAM,CAAC;IAEvB,QAAQ,EAAE,OAAO,CAAC;IAElB,OAAO,CAAC,aAAa,CAAU;IAE/B,OAAO,CAAC,iBAAiB,CAAS;gBAEtB,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO;IAaxD;;;;;;OAMG;IACG,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;CA0EhB"}
|
package/dist/TwirpRPC.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { randomUUID } from "./crypto/uuid.js";
|
|
1
2
|
import {
|
|
2
3
|
FAILOVER_BACKOFF_BASE_MS,
|
|
3
4
|
failoverAttempts,
|
|
@@ -8,6 +9,7 @@ import {
|
|
|
8
9
|
} from "./failover.js";
|
|
9
10
|
import { SDK_VERSION } from "./version.js";
|
|
10
11
|
const USER_AGENT = `livekit-server-sdk-node/${SDK_VERSION}`;
|
|
12
|
+
const REQUEST_ID_HEADER = "X-Livekit-Request-Id";
|
|
11
13
|
const defaultPrefix = "/twirp";
|
|
12
14
|
const defaultTimeoutSeconds = 10;
|
|
13
15
|
const livekitPackage = "livekit";
|
|
@@ -89,6 +91,7 @@ class TwirpRpc {
|
|
|
89
91
|
"User-Agent": USER_AGENT,
|
|
90
92
|
...headers
|
|
91
93
|
};
|
|
94
|
+
requestHeaders[REQUEST_ID_HEADER] = await randomUUID();
|
|
92
95
|
const origin = new URL(this.host);
|
|
93
96
|
const maxAttempts = failoverAttempts(
|
|
94
97
|
this.failover,
|
|
@@ -166,6 +169,7 @@ async function toTwirpError(response) {
|
|
|
166
169
|
return new TwirpError(response.statusText, errorMessage, response.status, errorCode, metadata);
|
|
167
170
|
}
|
|
168
171
|
export {
|
|
172
|
+
REQUEST_ID_HEADER,
|
|
169
173
|
ServerError,
|
|
170
174
|
SipCallError,
|
|
171
175
|
TwirpError,
|