11import { Mutex } from '@livekit/mutex' ;
2- import { RoomAgentDispatch , RoomConfiguration , TokenSourceRequest , TokenSourceResponse } from '@livekit/protocol' ;
3- import { TokenSourceConfigurable , TokenSourceFixed , type TokenSourceOptions , type TokenSourceResponseObject } from './types' ;
2+ import {
3+ RoomAgentDispatch ,
4+ RoomConfiguration ,
5+ TokenSourceRequest ,
6+ TokenSourceResponse ,
7+ } from '@livekit/protocol' ;
8+ import {
9+ TokenSourceConfigurable ,
10+ TokenSourceFixed ,
11+ type TokenSourceOptions ,
12+ type TokenSourceResponseObject ,
13+ } from './types' ;
414import { decodeTokenPayload , isResponseExpired } from './utils' ;
515
616/** A TokenSourceCached is a TokenSource which caches the last {@link TokenSourceResponseObject} value and returns it
7- * until a) it expires or b) the {@link TokenSourceOptions} provided to .fetch(...) change. */
17+ * until a) it expires or b) the {@link TokenSourceOptions} provided to .fetch(...) change. */
818abstract class TokenSourceCached extends TokenSourceConfigurable {
919 private cachedOptions : TokenSourceOptions | null = null ;
1020
@@ -78,8 +88,9 @@ abstract class TokenSourceCached extends TokenSourceConfigurable {
7888 protected abstract update ( options : TokenSourceOptions ) : Promise < TokenSourceResponse > ;
7989}
8090
81-
82- type LiteralOrFn = TokenSourceResponseObject | ( ( ) => TokenSourceResponseObject | Promise < TokenSourceResponseObject > ) ;
91+ type LiteralOrFn =
92+ | TokenSourceResponseObject
93+ | ( ( ) => TokenSourceResponseObject | Promise < TokenSourceResponseObject > ) ;
8394export class TokenSourceLiteral extends TokenSourceFixed {
8495 private literalOrFn : LiteralOrFn ;
8596
@@ -97,8 +108,9 @@ export class TokenSourceLiteral extends TokenSourceFixed {
97108 }
98109}
99110
100-
101- type CustomFn = ( options : TokenSourceOptions ) => TokenSourceResponseObject | Promise < TokenSourceResponseObject > ;
111+ type CustomFn = (
112+ options : TokenSourceOptions ,
113+ ) => TokenSourceResponseObject | Promise < TokenSourceResponseObject > ;
102114export class TokenSourceCustom extends TokenSourceCached {
103115 private customFn : CustomFn ;
104116
@@ -125,7 +137,6 @@ export class TokenSourceCustom extends TokenSourceCached {
125137 }
126138}
127139
128-
129140export type EndpointOptions = Omit < RequestInit , 'body' > ;
130141
131142export class TokenSourceEndpoint extends TokenSourceCached {
@@ -157,16 +168,20 @@ export class TokenSourceEndpoint extends TokenSourceCached {
157168
158169 case 'agentName' :
159170 request . roomConfig = request . roomConfig ?? new RoomConfiguration ( ) ;
160- request . roomConfig . agents . push ( new RoomAgentDispatch ( {
161- agentName : options . agentName ,
162- metadata : '' , // FIXME: how do I support this? Maybe make agentName -> agentToDispatch?
163- } ) ) ;
171+ request . roomConfig . agents . push (
172+ new RoomAgentDispatch ( {
173+ agentName : options . agentName ,
174+ metadata : '' , // FIXME: how do I support this? Maybe make agentName -> agentToDispatch?
175+ } ) ,
176+ ) ;
164177 break ;
165178
166179 default :
167180 // ref: https://stackoverflow.com/a/58009992
168181 const exhaustiveCheckedKey : never = key ;
169- throw new Error ( `Options key ${ exhaustiveCheckedKey } not being included in forming request!` ) ;
182+ throw new Error (
183+ `Options key ${ exhaustiveCheckedKey } not being included in forming request!` ,
184+ ) ;
170185 }
171186 }
172187
@@ -184,7 +199,7 @@ export class TokenSourceEndpoint extends TokenSourceCached {
184199 ...this . endpointOptions . headers ,
185200 } ,
186201 body : request . toJsonString ( {
187- useProtoFieldName : true
202+ useProtoFieldName : true ,
188203 } ) ,
189204 } ) ;
190205
@@ -222,7 +237,7 @@ export class TokenSourceSandboxTokenServer extends TokenSourceEndpoint {
222237
223238export const TokenSource = {
224239 /** TokenSource.literal contains a single, literal set of {@link TokenSourceResponseObject}
225- * credentials, either provided directly or returned from a provided function. */
240+ * credentials, either provided directly or returned from a provided function. */
226241 literal ( literalOrFn : LiteralOrFn ) {
227242 return new TokenSourceLiteral ( literalOrFn ) ;
228243 } ,
0 commit comments