Skip to content

Commit c497f25

Browse files
authored
Add deployment to TokenSourceFetch options (#1971)
1 parent 5a1d649 commit c497f25

6 files changed

Lines changed: 22 additions & 29 deletions

File tree

.changeset/lazy-cougars-behave.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"livekit-client": patch
3+
---
4+
5+
Add deployment to TokenSourceFetch options

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
},
6767
"dependencies": {
6868
"@livekit/mutex": "1.1.1",
69-
"@livekit/protocol": "1.45.8",
69+
"@livekit/protocol": "1.46.6",
7070
"events": "^3.3.0",
7171
"jose": "^6.1.0",
7272
"loglevel": "^1.9.2",

pnpm-lock.yaml

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/room/token-source/TokenSource.ts

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,7 @@ abstract class TokenSourceCached extends TokenSourceConfigurable {
2727
return false;
2828
}
2929

30-
for (const key of Object.keys(this.cachedFetchOptions) as Array<
31-
keyof TokenSourceFetchOptions
32-
>) {
33-
switch (key) {
34-
case 'roomName':
35-
case 'participantName':
36-
case 'participantIdentity':
37-
case 'participantMetadata':
38-
case 'participantAttributes':
39-
case 'agentName':
40-
case 'agentMetadata':
41-
if (this.cachedFetchOptions[key] !== options[key]) {
42-
return false;
43-
}
44-
break;
45-
default:
46-
// ref: https://stackoverflow.com/a/58009992
47-
const exhaustiveCheckedKey: never = key;
48-
throw new Error(`Options key ${exhaustiveCheckedKey} not being checked for equality!`);
49-
}
50-
}
51-
52-
return true;
30+
return areTokenSourceFetchOptionsEqual(options, this.cachedFetchOptions);
5331
}
5432

5533
private shouldReturnCachedValueFromFetch(fetchOptions: TokenSourceFetchOptions) {
@@ -191,6 +169,14 @@ class TokenSourceEndpoint extends TokenSourceCached {
191169
request.roomConfig.agents[0].metadata = options.agentMetadata!;
192170
break;
193171

172+
case 'deployment':
173+
request.roomConfig = request.roomConfig ?? new RoomConfiguration();
174+
if (request.roomConfig.agents.length === 0) {
175+
request.roomConfig.agents.push(new RoomAgentDispatch());
176+
}
177+
request.roomConfig.agents[0].deployment = options.deployment!;
178+
break;
179+
194180
default:
195181
// ref: https://stackoverflow.com/a/58009992
196182
const exhaustiveCheckedKey: never = key;

src/room/token-source/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export type TokenSourceFetchOptions = {
6363

6464
agentName?: string;
6565
agentMetadata?: string;
66+
deployment?: string;
6667
};
6768

6869
/** A Configurable TokenSource is a token source that takes a

src/room/token-source/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export function areTokenSourceFetchOptionsEqual(
5858
case 'participantAttributes':
5959
case 'agentName':
6060
case 'agentMetadata':
61+
case 'deployment':
6162
if (a[key] !== b[key]) {
6263
return false;
6364
}

0 commit comments

Comments
 (0)