livekit-server-sdk 2.14.2 → 2.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AccessToken.cjs +1 -1
- package/dist/AccessToken.cjs.map +1 -1
- package/dist/AccessToken.d.ts +9 -6
- package/dist/AccessToken.js +1 -1
- package/dist/AccessToken.js.map +1 -1
- package/dist/AgentDispatchClient.d.ts +7 -4
- package/dist/ClientOptions.d.ts +3 -2
- package/dist/ConnectorClient.cjs +183 -0
- package/dist/ConnectorClient.cjs.map +1 -0
- package/dist/ConnectorClient.d.cts +134 -0
- package/dist/ConnectorClient.d.ts +134 -0
- package/dist/ConnectorClient.d.ts.map +1 -0
- package/dist/ConnectorClient.js +170 -0
- package/dist/ConnectorClient.js.map +1 -0
- package/dist/EgressClient.d.ts +15 -12
- package/dist/IngressClient.d.ts +11 -8
- package/dist/RoomServiceClient.d.ts +11 -8
- package/dist/ServiceBase.d.ts +7 -3
- package/dist/SipClient.cjs +2 -1
- package/dist/SipClient.cjs.map +1 -1
- package/dist/SipClient.d.cts +2 -0
- package/dist/SipClient.d.ts +23 -18
- package/dist/SipClient.d.ts.map +1 -1
- package/dist/SipClient.js +2 -1
- package/dist/SipClient.js.map +1 -1
- package/dist/TwirpRPC.d.ts +8 -7
- package/dist/WebhookReceiver.d.ts +9 -7
- package/dist/crypto/digest.d.ts +3 -2
- package/dist/crypto/uuid.d.ts +3 -2
- package/dist/grants.d.ts +12 -11
- package/dist/index.cjs +16 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +14 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
- package/src/AccessToken.test.ts +1 -3
- package/src/AccessToken.ts +1 -1
- package/src/ConnectorClient.ts +282 -0
- package/src/SipClient.ts +5 -0
- package/src/index.ts +8 -0
package/dist/AccessToken.cjs
CHANGED
|
@@ -153,7 +153,7 @@ class AccessToken {
|
|
|
153
153
|
async toJwt() {
|
|
154
154
|
var _a;
|
|
155
155
|
const secret = new TextEncoder().encode(this.apiSecret);
|
|
156
|
-
const jwt = new jose.SignJWT((0, import_grants.claimsToJwtPayload)(this.grants)).setProtectedHeader({ alg: "HS256" }).setIssuer(this.apiKey).setExpirationTime(this.ttl).setNotBefore(
|
|
156
|
+
const jwt = new jose.SignJWT((0, import_grants.claimsToJwtPayload)(this.grants)).setProtectedHeader({ alg: "HS256" }).setIssuer(this.apiKey).setExpirationTime(this.ttl).setNotBefore(/* @__PURE__ */ new Date());
|
|
157
157
|
if (this.identity) {
|
|
158
158
|
jwt.setSubject(this.identity);
|
|
159
159
|
} else if ((_a = this.grants.video) == null ? void 0 : _a.roomJoin) {
|
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(
|
|
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,SAAS,CAAC,GAAI,GAAG,MAAM;AAAA,EAC/D;AAAA;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,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,IACF,CAAC;AACD,QAAI,CAAC,SAAS;AACZ,YAAM,MAAM,eAAe;AAAA,IAC7B;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
package/dist/AccessToken.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import { RoomConfiguration } from '@livekit/protocol';
|
|
2
|
+
import { VideoGrant, InferenceGrant, SIPGrant, ObservabilityGrant, ClaimGrants } from './grants.js';
|
|
3
|
+
import 'jose';
|
|
4
|
+
|
|
5
|
+
interface AccessTokenOptions {
|
|
4
6
|
/**
|
|
5
7
|
* amount of time before expiration
|
|
6
8
|
* expressed in seconds or a string describing a time span zeit/ms.
|
|
@@ -24,7 +26,7 @@ export interface AccessTokenOptions {
|
|
|
24
26
|
*/
|
|
25
27
|
attributes?: Record<string, string>;
|
|
26
28
|
}
|
|
27
|
-
|
|
29
|
+
declare class AccessToken {
|
|
28
30
|
private apiKey;
|
|
29
31
|
private apiSecret;
|
|
30
32
|
private grants;
|
|
@@ -78,10 +80,11 @@ export declare class AccessToken {
|
|
|
78
80
|
*/
|
|
79
81
|
toJwt(): Promise<string>;
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
declare class TokenVerifier {
|
|
82
84
|
private apiKey;
|
|
83
85
|
private apiSecret;
|
|
84
86
|
constructor(apiKey: string, apiSecret: string);
|
|
85
87
|
verify(token: string, clockTolerance?: string | number): Promise<ClaimGrants>;
|
|
86
88
|
}
|
|
87
|
-
|
|
89
|
+
|
|
90
|
+
export { AccessToken, type AccessTokenOptions, TokenVerifier };
|
package/dist/AccessToken.js
CHANGED
|
@@ -119,7 +119,7 @@ class AccessToken {
|
|
|
119
119
|
async toJwt() {
|
|
120
120
|
var _a;
|
|
121
121
|
const secret = new TextEncoder().encode(this.apiSecret);
|
|
122
|
-
const jwt = new jose.SignJWT(claimsToJwtPayload(this.grants)).setProtectedHeader({ alg: "HS256" }).setIssuer(this.apiKey).setExpirationTime(this.ttl).setNotBefore(
|
|
122
|
+
const jwt = new jose.SignJWT(claimsToJwtPayload(this.grants)).setProtectedHeader({ alg: "HS256" }).setIssuer(this.apiKey).setExpirationTime(this.ttl).setNotBefore(/* @__PURE__ */ new Date());
|
|
123
123
|
if (this.identity) {
|
|
124
124
|
jwt.setSubject(this.identity);
|
|
125
125
|
} else if ((_a = this.grants.video) == null ? void 0 : _a.roomJoin) {
|
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(
|
|
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,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,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,IACF,CAAC;AACD,QAAI,CAAC,SAAS;AACZ,YAAM,MAAM,eAAe;AAAA,IAC7B;AAEA,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { AgentDispatch } from '@livekit/protocol';
|
|
2
|
-
import
|
|
2
|
+
import { ClientOptions } from './ClientOptions.js';
|
|
3
3
|
import { ServiceBase } from './ServiceBase.js';
|
|
4
|
+
import './grants.js';
|
|
5
|
+
import 'jose';
|
|
6
|
+
|
|
4
7
|
interface CreateDispatchOptions {
|
|
5
8
|
metadata?: string;
|
|
6
9
|
}
|
|
7
10
|
/**
|
|
8
11
|
* Client to access Agent APIs
|
|
9
12
|
*/
|
|
10
|
-
|
|
13
|
+
declare class AgentDispatchClient extends ServiceBase {
|
|
11
14
|
private readonly rpc;
|
|
12
15
|
/**
|
|
13
16
|
* @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
|
|
@@ -45,5 +48,5 @@ export declare class AgentDispatchClient extends ServiceBase {
|
|
|
45
48
|
*/
|
|
46
49
|
listDispatch(roomName: string): Promise<AgentDispatch[]>;
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
|
|
52
|
+
export { AgentDispatchClient };
|
package/dist/ClientOptions.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Options common to all clients
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
type ClientOptions = {
|
|
5
5
|
/**
|
|
6
6
|
* Optional timeout, in seconds, for all server requests
|
|
7
7
|
*/
|
|
8
8
|
requestTimeout?: number;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
|
|
11
|
+
export type { ClientOptions };
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var ConnectorClient_exports = {};
|
|
20
|
+
__export(ConnectorClient_exports, {
|
|
21
|
+
ConnectorClient: () => ConnectorClient
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(ConnectorClient_exports);
|
|
24
|
+
var import_protocol = require("@livekit/protocol");
|
|
25
|
+
var import_ServiceBase = require("./ServiceBase.cjs");
|
|
26
|
+
var import_TwirpRPC = require("./TwirpRPC.cjs");
|
|
27
|
+
const svc = "Connector";
|
|
28
|
+
class ConnectorClient extends import_ServiceBase.ServiceBase {
|
|
29
|
+
/**
|
|
30
|
+
* @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
|
|
31
|
+
* @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
|
|
32
|
+
* @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
|
|
33
|
+
* @param options - client options
|
|
34
|
+
*/
|
|
35
|
+
constructor(host, apiKey, secret, options) {
|
|
36
|
+
super(apiKey, secret);
|
|
37
|
+
const rpcOptions = (options == null ? void 0 : options.requestTimeout) ? { requestTimeout: options.requestTimeout } : void 0;
|
|
38
|
+
this.rpc = new import_TwirpRPC.TwirpRpc(host, import_TwirpRPC.livekitPackage, rpcOptions);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Initiate an outbound WhatsApp call
|
|
42
|
+
*
|
|
43
|
+
* @param options - WhatsApp call options
|
|
44
|
+
* @returns Promise containing the WhatsApp call ID and room name
|
|
45
|
+
*/
|
|
46
|
+
async dialWhatsAppCall(options) {
|
|
47
|
+
const whatsappBizOpaqueCallbackData = options.whatsappBizOpaqueCallbackData || "";
|
|
48
|
+
const roomName = options.roomName || "";
|
|
49
|
+
const participantIdentity = options.participantIdentity || "";
|
|
50
|
+
const participantName = options.participantName || "";
|
|
51
|
+
const participantMetadata = options.participantMetadata || "";
|
|
52
|
+
const destinationCountry = options.destinationCountry || "";
|
|
53
|
+
const req = new import_protocol.DialWhatsAppCallRequest({
|
|
54
|
+
whatsappPhoneNumberId: options.whatsappPhoneNumberId,
|
|
55
|
+
whatsappToPhoneNumber: options.whatsappToPhoneNumber,
|
|
56
|
+
whatsappApiKey: options.whatsappApiKey,
|
|
57
|
+
whatsappCloudApiVersion: options.whatsappCloudApiVersion,
|
|
58
|
+
whatsappBizOpaqueCallbackData,
|
|
59
|
+
roomName,
|
|
60
|
+
agents: options.agents,
|
|
61
|
+
participantIdentity,
|
|
62
|
+
participantName,
|
|
63
|
+
participantMetadata,
|
|
64
|
+
participantAttributes: options.participantAttributes,
|
|
65
|
+
destinationCountry
|
|
66
|
+
}).toJson();
|
|
67
|
+
const data = await this.rpc.request(
|
|
68
|
+
svc,
|
|
69
|
+
"DialWhatsAppCall",
|
|
70
|
+
req,
|
|
71
|
+
await this.authHeader({ roomCreate: true })
|
|
72
|
+
);
|
|
73
|
+
return import_protocol.DialWhatsAppCallResponse.fromJson(data, { ignoreUnknownFields: true });
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Accept an inbound WhatsApp call
|
|
77
|
+
*
|
|
78
|
+
* @param options - WhatsApp call accept options
|
|
79
|
+
* @returns Promise containing the room name
|
|
80
|
+
*/
|
|
81
|
+
async acceptWhatsAppCall(options) {
|
|
82
|
+
const whatsappBizOpaqueCallbackData = options.whatsappBizOpaqueCallbackData || "";
|
|
83
|
+
const roomName = options.roomName || "";
|
|
84
|
+
const participantIdentity = options.participantIdentity || "";
|
|
85
|
+
const participantName = options.participantName || "";
|
|
86
|
+
const participantMetadata = options.participantMetadata || "";
|
|
87
|
+
const destinationCountry = options.destinationCountry || "";
|
|
88
|
+
const req = new import_protocol.AcceptWhatsAppCallRequest({
|
|
89
|
+
whatsappPhoneNumberId: options.whatsappPhoneNumberId,
|
|
90
|
+
whatsappApiKey: options.whatsappApiKey,
|
|
91
|
+
whatsappCloudApiVersion: options.whatsappCloudApiVersion,
|
|
92
|
+
whatsappCallId: options.whatsappCallId,
|
|
93
|
+
whatsappBizOpaqueCallbackData,
|
|
94
|
+
sdp: options.sdp,
|
|
95
|
+
roomName,
|
|
96
|
+
agents: options.agents,
|
|
97
|
+
participantIdentity,
|
|
98
|
+
participantName,
|
|
99
|
+
participantMetadata,
|
|
100
|
+
participantAttributes: options.participantAttributes,
|
|
101
|
+
destinationCountry
|
|
102
|
+
}).toJson();
|
|
103
|
+
const data = await this.rpc.request(
|
|
104
|
+
svc,
|
|
105
|
+
"AcceptWhatsAppCall",
|
|
106
|
+
req,
|
|
107
|
+
await this.authHeader({ roomCreate: true })
|
|
108
|
+
);
|
|
109
|
+
return import_protocol.AcceptWhatsAppCallResponse.fromJson(data, { ignoreUnknownFields: true });
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Connect an established WhatsApp call (used for business-initiated calls)
|
|
113
|
+
*
|
|
114
|
+
* @param whatsappCallId - Call ID sent by Meta
|
|
115
|
+
* @param sdp - Session description from Meta
|
|
116
|
+
*/
|
|
117
|
+
async connectWhatsAppCall(whatsappCallId, sdp) {
|
|
118
|
+
const req = new import_protocol.ConnectWhatsAppCallRequest({
|
|
119
|
+
whatsappCallId,
|
|
120
|
+
sdp
|
|
121
|
+
}).toJson();
|
|
122
|
+
const data = await this.rpc.request(
|
|
123
|
+
svc,
|
|
124
|
+
"ConnectWhatsAppCall",
|
|
125
|
+
req,
|
|
126
|
+
await this.authHeader({ roomCreate: true })
|
|
127
|
+
);
|
|
128
|
+
return import_protocol.ConnectWhatsAppCallResponse.fromJson(data, { ignoreUnknownFields: true });
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Disconnect an active WhatsApp call
|
|
132
|
+
*
|
|
133
|
+
* @param whatsappCallId - Call ID sent by Meta
|
|
134
|
+
* @param whatsappApiKey - The API key of the business that is disconnecting the call
|
|
135
|
+
*/
|
|
136
|
+
async disconnectWhatsAppCall(whatsappCallId, whatsappApiKey) {
|
|
137
|
+
const req = new import_protocol.DisconnectWhatsAppCallRequest({
|
|
138
|
+
whatsappCallId,
|
|
139
|
+
whatsappApiKey
|
|
140
|
+
}).toJson();
|
|
141
|
+
const data = await this.rpc.request(
|
|
142
|
+
svc,
|
|
143
|
+
"DisconnectWhatsAppCall",
|
|
144
|
+
req,
|
|
145
|
+
await this.authHeader({ roomCreate: true })
|
|
146
|
+
);
|
|
147
|
+
return import_protocol.DisconnectWhatsAppCallResponse.fromJson(data, { ignoreUnknownFields: true });
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Connect a Twilio call to a LiveKit room
|
|
151
|
+
*
|
|
152
|
+
* @param options - Twilio call connection options
|
|
153
|
+
* @returns Promise containing the WebSocket connect URL for Twilio media stream
|
|
154
|
+
*/
|
|
155
|
+
async connectTwilioCall(options) {
|
|
156
|
+
const participantIdentity = options.participantIdentity || "";
|
|
157
|
+
const participantName = options.participantName || "";
|
|
158
|
+
const participantMetadata = options.participantMetadata || "";
|
|
159
|
+
const destinationCountry = options.destinationCountry || "";
|
|
160
|
+
const req = new import_protocol.ConnectTwilioCallRequest({
|
|
161
|
+
twilioCallDirection: options.twilioCallDirection,
|
|
162
|
+
roomName: options.roomName,
|
|
163
|
+
agents: options.agents,
|
|
164
|
+
participantIdentity,
|
|
165
|
+
participantName,
|
|
166
|
+
participantMetadata,
|
|
167
|
+
participantAttributes: options.participantAttributes,
|
|
168
|
+
destinationCountry
|
|
169
|
+
}).toJson();
|
|
170
|
+
const data = await this.rpc.request(
|
|
171
|
+
svc,
|
|
172
|
+
"ConnectTwilioCall",
|
|
173
|
+
req,
|
|
174
|
+
await this.authHeader({ roomCreate: true })
|
|
175
|
+
);
|
|
176
|
+
return import_protocol.ConnectTwilioCallResponse.fromJson(data, { ignoreUnknownFields: true });
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
180
|
+
0 && (module.exports = {
|
|
181
|
+
ConnectorClient
|
|
182
|
+
});
|
|
183
|
+
//# sourceMappingURL=ConnectorClient.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ConnectorClient.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type {\n ConnectTwilioCallRequest_TwilioCallDirection,\n RoomAgentDispatch,\n SessionDescription,\n} from '@livekit/protocol';\nimport {\n AcceptWhatsAppCallRequest,\n AcceptWhatsAppCallResponse,\n ConnectTwilioCallRequest,\n ConnectTwilioCallResponse,\n ConnectWhatsAppCallRequest,\n ConnectWhatsAppCallResponse,\n DialWhatsAppCallRequest,\n DialWhatsAppCallResponse,\n DisconnectWhatsAppCallRequest,\n DisconnectWhatsAppCallResponse,\n} from '@livekit/protocol';\nimport type { ClientOptions } from './ClientOptions.js';\nimport { ServiceBase } from './ServiceBase.js';\nimport { type Rpc, TwirpRpc, livekitPackage } from './TwirpRPC.js';\n\nconst svc = 'Connector';\n\n// WhatsApp types\nexport interface DialWhatsAppCallOptions {\n /** Required - The identifier of the WhatsApp phone number that is initiating the call */\n whatsappPhoneNumberId: string;\n /** Required - The number of the user that is supposed to receive the call */\n whatsappToPhoneNumber: string;\n /** Required - The API key of the business that is initiating the call */\n whatsappApiKey: string;\n /** Required - WhatsApp Cloud API version, eg: 23.0, 24.0, etc. */\n whatsappCloudApiVersion: string;\n /** Optional - An arbitrary string you can pass in that is useful for tracking and logging purposes */\n whatsappBizOpaqueCallbackData?: string;\n /** Optional - What LiveKit room should this participant be connected to */\n roomName?: string;\n /** Optional - Agents to dispatch the call to */\n agents?: RoomAgentDispatch[];\n /** Optional - Identity of the participant in LiveKit room */\n participantIdentity?: string;\n /** Optional - Name of the participant in LiveKit room */\n participantName?: string;\n /** Optional - User-defined metadata. Will be attached to a created Participant in the room. */\n participantMetadata?: string;\n /** Optional - User-defined attributes. Will be attached to a created Participant in the room. */\n participantAttributes?: { [key: string]: string };\n /** Optional - Country where the call terminates as ISO 3166-1 alpha-2 */\n destinationCountry?: string;\n}\n\nexport interface AcceptWhatsAppCallOptions {\n /** Required - The identifier of the WhatsApp phone number that is connecting the call */\n whatsappPhoneNumberId: string;\n /** Required - The API key of the business that is connecting the call */\n whatsappApiKey: string;\n /** Required - WhatsApp Cloud API version, eg: 23.0, 24.0, etc. */\n whatsappCloudApiVersion: string;\n /** Required - Call ID sent by Meta */\n whatsappCallId: string;\n /** Optional - An arbitrary string you can pass in that is useful for tracking and logging purposes */\n whatsappBizOpaqueCallbackData?: string;\n /** Required - The call accept webhook comes with SDP from Meta */\n sdp: SessionDescription;\n /** Optional - What LiveKit room should this participant be connected to */\n roomName?: string;\n /** Optional - Agents to dispatch the call to */\n agents?: RoomAgentDispatch[];\n /** Optional - Identity of the participant in LiveKit room */\n participantIdentity?: string;\n /** Optional - Name of the participant in LiveKit room */\n participantName?: string;\n /** Optional - User-defined metadata. Will be attached to a created Participant in the room. */\n participantMetadata?: string;\n /** Optional - User-defined attributes. Will be attached to a created Participant in the room. */\n participantAttributes?: { [key: string]: string };\n /** Optional - Country where the call terminates as ISO 3166-1 alpha-2 */\n destinationCountry?: string;\n}\n\n// Twilio types\nexport interface ConnectTwilioCallOptions {\n /** The direction of the call */\n twilioCallDirection: ConnectTwilioCallRequest_TwilioCallDirection;\n /** What LiveKit room should this call be connected to */\n roomName: string;\n /** Optional agents to dispatch the call to */\n agents?: RoomAgentDispatch[];\n /** Optional identity of the participant in LiveKit room */\n participantIdentity?: string;\n /** Optional name of the participant in LiveKit room */\n participantName?: string;\n /** Optional user-defined metadata. Will be attached to a created Participant in the room. */\n participantMetadata?: string;\n /** Optional user-defined attributes. Will be attached to a created Participant in the room. */\n participantAttributes?: { [key: string]: string };\n /** Country where the call terminates as ISO 3166-1 alpha-2 */\n destinationCountry?: string;\n}\n\n/**\n * Client to access Connector APIs for WhatsApp and Twilio integrations\n */\nexport class ConnectorClient 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);\n const rpcOptions = options?.requestTimeout\n ? { requestTimeout: options.requestTimeout }\n : undefined;\n this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);\n }\n\n /**\n * Initiate an outbound WhatsApp call\n *\n * @param options - WhatsApp call options\n * @returns Promise containing the WhatsApp call ID and room name\n */\n async dialWhatsAppCall(options: DialWhatsAppCallOptions): Promise<DialWhatsAppCallResponse> {\n const whatsappBizOpaqueCallbackData = options.whatsappBizOpaqueCallbackData || '';\n const roomName = options.roomName || '';\n const participantIdentity = options.participantIdentity || '';\n const participantName = options.participantName || '';\n const participantMetadata = options.participantMetadata || '';\n const destinationCountry = options.destinationCountry || '';\n\n const req = new DialWhatsAppCallRequest({\n whatsappPhoneNumberId: options.whatsappPhoneNumberId,\n whatsappToPhoneNumber: options.whatsappToPhoneNumber,\n whatsappApiKey: options.whatsappApiKey,\n whatsappCloudApiVersion: options.whatsappCloudApiVersion,\n whatsappBizOpaqueCallbackData,\n roomName,\n agents: options.agents,\n participantIdentity,\n participantName,\n participantMetadata,\n participantAttributes: options.participantAttributes,\n destinationCountry,\n }).toJson();\n\n const data = await this.rpc.request(\n svc,\n 'DialWhatsAppCall',\n req,\n await this.authHeader({ roomCreate: true }),\n );\n return DialWhatsAppCallResponse.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * Accept an inbound WhatsApp call\n *\n * @param options - WhatsApp call accept options\n * @returns Promise containing the room name\n */\n async acceptWhatsAppCall(\n options: AcceptWhatsAppCallOptions,\n ): Promise<AcceptWhatsAppCallResponse> {\n const whatsappBizOpaqueCallbackData = options.whatsappBizOpaqueCallbackData || '';\n const roomName = options.roomName || '';\n const participantIdentity = options.participantIdentity || '';\n const participantName = options.participantName || '';\n const participantMetadata = options.participantMetadata || '';\n const destinationCountry = options.destinationCountry || '';\n\n const req = new AcceptWhatsAppCallRequest({\n whatsappPhoneNumberId: options.whatsappPhoneNumberId,\n whatsappApiKey: options.whatsappApiKey,\n whatsappCloudApiVersion: options.whatsappCloudApiVersion,\n whatsappCallId: options.whatsappCallId,\n whatsappBizOpaqueCallbackData,\n sdp: options.sdp,\n roomName,\n agents: options.agents,\n participantIdentity,\n participantName,\n participantMetadata,\n participantAttributes: options.participantAttributes,\n destinationCountry,\n }).toJson();\n\n const data = await this.rpc.request(\n svc,\n 'AcceptWhatsAppCall',\n req,\n await this.authHeader({ roomCreate: true }),\n );\n return AcceptWhatsAppCallResponse.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * Connect an established WhatsApp call (used for business-initiated calls)\n *\n * @param whatsappCallId - Call ID sent by Meta\n * @param sdp - Session description from Meta\n */\n async connectWhatsAppCall(\n whatsappCallId: string,\n sdp: SessionDescription,\n ): Promise<ConnectWhatsAppCallResponse> {\n const req = new ConnectWhatsAppCallRequest({\n whatsappCallId,\n sdp,\n }).toJson();\n\n const data = await this.rpc.request(\n svc,\n 'ConnectWhatsAppCall',\n req,\n await this.authHeader({ roomCreate: true }),\n );\n return ConnectWhatsAppCallResponse.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * Disconnect an active WhatsApp call\n *\n * @param whatsappCallId - Call ID sent by Meta\n * @param whatsappApiKey - The API key of the business that is disconnecting the call\n */\n async disconnectWhatsAppCall(\n whatsappCallId: string,\n whatsappApiKey: string,\n ): Promise<DisconnectWhatsAppCallResponse> {\n const req = new DisconnectWhatsAppCallRequest({\n whatsappCallId,\n whatsappApiKey,\n }).toJson();\n\n const data = await this.rpc.request(\n svc,\n 'DisconnectWhatsAppCall',\n req,\n await this.authHeader({ roomCreate: true }),\n );\n return DisconnectWhatsAppCallResponse.fromJson(data, { ignoreUnknownFields: true });\n }\n\n /**\n * Connect a Twilio call to a LiveKit room\n *\n * @param options - Twilio call connection options\n * @returns Promise containing the WebSocket connect URL for Twilio media stream\n */\n async connectTwilioCall(options: ConnectTwilioCallOptions): Promise<ConnectTwilioCallResponse> {\n const participantIdentity = options.participantIdentity || '';\n const participantName = options.participantName || '';\n const participantMetadata = options.participantMetadata || '';\n const destinationCountry = options.destinationCountry || '';\n\n const req = new ConnectTwilioCallRequest({\n twilioCallDirection: options.twilioCallDirection,\n roomName: options.roomName,\n agents: options.agents,\n participantIdentity,\n participantName,\n participantMetadata,\n participantAttributes: options.participantAttributes,\n destinationCountry,\n }).toJson();\n\n const data = await this.rpc.request(\n svc,\n 'ConnectTwilioCall',\n req,\n await this.authHeader({ roomCreate: true }),\n );\n return ConnectTwilioCallResponse.fromJson(data, { ignoreUnknownFields: true });\n }\n}\n"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AAA,MAC5C;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,YAAY,KAAK,CAAC;AAAA,IAC5C;AACA,WAAO,+CAA+B,SAAS,MAAM,EAAE,qBAAqB,KAAK,CAAC;AAAA,EACpF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,kBAAkB,SAAuE;AAC7F,UAAM,sBAAsB,QAAQ,uBAAuB;AAC3D,UAAM,kBAAkB,QAAQ,mBAAmB;AACnD,UAAM,sBAAsB,QAAQ,uBAAuB;AAC3D,UAAM,qBAAqB,QAAQ,sBAAsB;AAEzD,UAAM,MAAM,IAAI,yCAAyB;AAAA,MACvC,qBAAqB,QAAQ;AAAA,MAC7B,UAAU,QAAQ;AAAA,MAClB,QAAQ,QAAQ;AAAA,MAChB;AAAA,MACA;AAAA,MACA;AAAA,MACA,uBAAuB,QAAQ;AAAA,MAC/B;AAAA,IACF,CAAC,EAAE,OAAO;AAEV,UAAM,OAAO,MAAM,KAAK,IAAI;AAAA,MAC1B;AAAA,MACA;AAAA,MACA;AAAA,MACA,MAAM,KAAK,WAAW,EAAE,YAAY,KAAK,CAAC;AAAA,IAC5C;AACA,WAAO,0CAA0B,SAAS,MAAM,EAAE,qBAAqB,KAAK,CAAC;AAAA,EAC/E;AACF;","names":[]}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { RoomAgentDispatch, SessionDescription, ConnectTwilioCallRequest_TwilioCallDirection, DialWhatsAppCallResponse, AcceptWhatsAppCallResponse, ConnectWhatsAppCallResponse, DisconnectWhatsAppCallResponse, ConnectTwilioCallResponse } from '@livekit/protocol';
|
|
2
|
+
import { ClientOptions } from './ClientOptions.cjs';
|
|
3
|
+
import { ServiceBase } from './ServiceBase.cjs';
|
|
4
|
+
import './grants.cjs';
|
|
5
|
+
import 'jose';
|
|
6
|
+
|
|
7
|
+
interface DialWhatsAppCallOptions {
|
|
8
|
+
/** Required - The identifier of the WhatsApp phone number that is initiating the call */
|
|
9
|
+
whatsappPhoneNumberId: string;
|
|
10
|
+
/** Required - The number of the user that is supposed to receive the call */
|
|
11
|
+
whatsappToPhoneNumber: string;
|
|
12
|
+
/** Required - The API key of the business that is initiating the call */
|
|
13
|
+
whatsappApiKey: string;
|
|
14
|
+
/** Required - WhatsApp Cloud API version, eg: 23.0, 24.0, etc. */
|
|
15
|
+
whatsappCloudApiVersion: string;
|
|
16
|
+
/** Optional - An arbitrary string you can pass in that is useful for tracking and logging purposes */
|
|
17
|
+
whatsappBizOpaqueCallbackData?: string;
|
|
18
|
+
/** Optional - What LiveKit room should this participant be connected to */
|
|
19
|
+
roomName?: string;
|
|
20
|
+
/** Optional - Agents to dispatch the call to */
|
|
21
|
+
agents?: RoomAgentDispatch[];
|
|
22
|
+
/** Optional - Identity of the participant in LiveKit room */
|
|
23
|
+
participantIdentity?: string;
|
|
24
|
+
/** Optional - Name of the participant in LiveKit room */
|
|
25
|
+
participantName?: string;
|
|
26
|
+
/** Optional - User-defined metadata. Will be attached to a created Participant in the room. */
|
|
27
|
+
participantMetadata?: string;
|
|
28
|
+
/** Optional - User-defined attributes. Will be attached to a created Participant in the room. */
|
|
29
|
+
participantAttributes?: {
|
|
30
|
+
[key: string]: string;
|
|
31
|
+
};
|
|
32
|
+
/** Optional - Country where the call terminates as ISO 3166-1 alpha-2 */
|
|
33
|
+
destinationCountry?: string;
|
|
34
|
+
}
|
|
35
|
+
interface AcceptWhatsAppCallOptions {
|
|
36
|
+
/** Required - The identifier of the WhatsApp phone number that is connecting the call */
|
|
37
|
+
whatsappPhoneNumberId: string;
|
|
38
|
+
/** Required - The API key of the business that is connecting the call */
|
|
39
|
+
whatsappApiKey: string;
|
|
40
|
+
/** Required - WhatsApp Cloud API version, eg: 23.0, 24.0, etc. */
|
|
41
|
+
whatsappCloudApiVersion: string;
|
|
42
|
+
/** Required - Call ID sent by Meta */
|
|
43
|
+
whatsappCallId: string;
|
|
44
|
+
/** Optional - An arbitrary string you can pass in that is useful for tracking and logging purposes */
|
|
45
|
+
whatsappBizOpaqueCallbackData?: string;
|
|
46
|
+
/** Required - The call accept webhook comes with SDP from Meta */
|
|
47
|
+
sdp: SessionDescription;
|
|
48
|
+
/** Optional - What LiveKit room should this participant be connected to */
|
|
49
|
+
roomName?: string;
|
|
50
|
+
/** Optional - Agents to dispatch the call to */
|
|
51
|
+
agents?: RoomAgentDispatch[];
|
|
52
|
+
/** Optional - Identity of the participant in LiveKit room */
|
|
53
|
+
participantIdentity?: string;
|
|
54
|
+
/** Optional - Name of the participant in LiveKit room */
|
|
55
|
+
participantName?: string;
|
|
56
|
+
/** Optional - User-defined metadata. Will be attached to a created Participant in the room. */
|
|
57
|
+
participantMetadata?: string;
|
|
58
|
+
/** Optional - User-defined attributes. Will be attached to a created Participant in the room. */
|
|
59
|
+
participantAttributes?: {
|
|
60
|
+
[key: string]: string;
|
|
61
|
+
};
|
|
62
|
+
/** Optional - Country where the call terminates as ISO 3166-1 alpha-2 */
|
|
63
|
+
destinationCountry?: string;
|
|
64
|
+
}
|
|
65
|
+
interface ConnectTwilioCallOptions {
|
|
66
|
+
/** The direction of the call */
|
|
67
|
+
twilioCallDirection: ConnectTwilioCallRequest_TwilioCallDirection;
|
|
68
|
+
/** What LiveKit room should this call be connected to */
|
|
69
|
+
roomName: string;
|
|
70
|
+
/** Optional agents to dispatch the call to */
|
|
71
|
+
agents?: RoomAgentDispatch[];
|
|
72
|
+
/** Optional identity of the participant in LiveKit room */
|
|
73
|
+
participantIdentity?: string;
|
|
74
|
+
/** Optional name of the participant in LiveKit room */
|
|
75
|
+
participantName?: string;
|
|
76
|
+
/** Optional user-defined metadata. Will be attached to a created Participant in the room. */
|
|
77
|
+
participantMetadata?: string;
|
|
78
|
+
/** Optional user-defined attributes. Will be attached to a created Participant in the room. */
|
|
79
|
+
participantAttributes?: {
|
|
80
|
+
[key: string]: string;
|
|
81
|
+
};
|
|
82
|
+
/** Country where the call terminates as ISO 3166-1 alpha-2 */
|
|
83
|
+
destinationCountry?: string;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Client to access Connector APIs for WhatsApp and Twilio integrations
|
|
87
|
+
*/
|
|
88
|
+
declare class ConnectorClient extends ServiceBase {
|
|
89
|
+
private readonly rpc;
|
|
90
|
+
/**
|
|
91
|
+
* @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'
|
|
92
|
+
* @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY
|
|
93
|
+
* @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET
|
|
94
|
+
* @param options - client options
|
|
95
|
+
*/
|
|
96
|
+
constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions);
|
|
97
|
+
/**
|
|
98
|
+
* Initiate an outbound WhatsApp call
|
|
99
|
+
*
|
|
100
|
+
* @param options - WhatsApp call options
|
|
101
|
+
* @returns Promise containing the WhatsApp call ID and room name
|
|
102
|
+
*/
|
|
103
|
+
dialWhatsAppCall(options: DialWhatsAppCallOptions): Promise<DialWhatsAppCallResponse>;
|
|
104
|
+
/**
|
|
105
|
+
* Accept an inbound WhatsApp call
|
|
106
|
+
*
|
|
107
|
+
* @param options - WhatsApp call accept options
|
|
108
|
+
* @returns Promise containing the room name
|
|
109
|
+
*/
|
|
110
|
+
acceptWhatsAppCall(options: AcceptWhatsAppCallOptions): Promise<AcceptWhatsAppCallResponse>;
|
|
111
|
+
/**
|
|
112
|
+
* Connect an established WhatsApp call (used for business-initiated calls)
|
|
113
|
+
*
|
|
114
|
+
* @param whatsappCallId - Call ID sent by Meta
|
|
115
|
+
* @param sdp - Session description from Meta
|
|
116
|
+
*/
|
|
117
|
+
connectWhatsAppCall(whatsappCallId: string, sdp: SessionDescription): Promise<ConnectWhatsAppCallResponse>;
|
|
118
|
+
/**
|
|
119
|
+
* Disconnect an active WhatsApp call
|
|
120
|
+
*
|
|
121
|
+
* @param whatsappCallId - Call ID sent by Meta
|
|
122
|
+
* @param whatsappApiKey - The API key of the business that is disconnecting the call
|
|
123
|
+
*/
|
|
124
|
+
disconnectWhatsAppCall(whatsappCallId: string, whatsappApiKey: string): Promise<DisconnectWhatsAppCallResponse>;
|
|
125
|
+
/**
|
|
126
|
+
* Connect a Twilio call to a LiveKit room
|
|
127
|
+
*
|
|
128
|
+
* @param options - Twilio call connection options
|
|
129
|
+
* @returns Promise containing the WebSocket connect URL for Twilio media stream
|
|
130
|
+
*/
|
|
131
|
+
connectTwilioCall(options: ConnectTwilioCallOptions): Promise<ConnectTwilioCallResponse>;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export { type AcceptWhatsAppCallOptions, type ConnectTwilioCallOptions, ConnectorClient, type DialWhatsAppCallOptions };
|