Skip to content

Commit fbd0aba

Browse files
committed
refactor: update tokensource method names
1 parent 3aedcd0 commit fbd0aba

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

packages/react/src/TokenSource.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type RoomConfigurationPayload = ValueToSnakeCase<
3636

3737

3838
export abstract class TokenSourceBase {
39-
abstract getTokenValue(): Promise<TokenSourceResponseObject>;
39+
abstract generate(): Promise<TokenSourceResponseObject>;
4040
}
4141

4242
export abstract class TokenSourceInFlexible extends TokenSourceBase {}
@@ -52,8 +52,6 @@ export type TokenSourceOptions = {
5252
};
5353

5454
export abstract class TokenSourceFlexible extends TokenSourceBase {
55-
abstract getTokenValue(): Promise<TokenSourceResponseObject>;
56-
5755
abstract setOptions(options: TokenSourceOptions): void;
5856
abstract clearOptions(): void;
5957
}
@@ -139,22 +137,22 @@ export abstract class TokenSourceRefreshable extends TokenSourceFlexible {
139137
this.cachedResponse = null;
140138
}
141139

142-
async getTokenValue(): Promise<TokenSourceResponseObject> {
140+
async generate(): Promise<TokenSourceResponseObject> {
143141
if (this.cachedResponse && !isResponseExpired(this.cachedResponse)) {
144142
return this.cachedResponse!.toJson() as TokenSourceResponseObject;
145143
}
146144

147145
const unlock = await this.fetchMutex.lock();
148146
try {
149-
const tokenResponse = await this.generate(this.options);
147+
const tokenResponse = await this.update(this.options);
150148
this.cachedResponse = tokenResponse;
151149
return tokenResponse;
152150
} finally {
153151
unlock();
154152
}
155153
}
156154

157-
abstract generate(options: TokenSourceOptions): Promise<TokenSourceResponse>;
155+
abstract update(options: TokenSourceOptions): Promise<TokenSourceResponse>;
158156
}
159157

160158

@@ -170,7 +168,7 @@ export class TokenSourceLiteral extends TokenSourceInFlexible {
170168
this.literalOrFn = literalOrFn;
171169
}
172170

173-
async getTokenValue(): Promise<TokenSourceResponseObject> {
171+
async generate(): Promise<TokenSourceResponseObject> {
174172
if (typeof this.literalOrFn === 'function') {
175173
return this.literalOrFn();
176174
} else {
@@ -189,7 +187,7 @@ class TokenSourceCustom extends TokenSourceRefreshable {
189187
this.customFn = customFn;
190188
}
191189

192-
async generate(options: TokenSourceOptions) {
190+
async update(options: TokenSourceOptions) {
193191
const resultMaybePromise = this.customFn(options);
194192

195193
let result;
@@ -220,7 +218,7 @@ class TokenSourceEndpoint extends TokenSourceRefreshable {
220218
this.endpointOptions = options;
221219
}
222220

223-
async generate(options: TokenSourceOptions) {
221+
async update(options: TokenSourceOptions) {
224222
// NOTE: I don't like the repetitive nature of this, `options` shouldn't be a thing,
225223
// `request` should just be passed through instead...
226224
const request = new TokenSourceRequest();

packages/react/src/hooks/useSession.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ export function useSession(
346346
await Promise.all([
347347
// FIXME: swap the below line in once the new `livekit-client` changes are published
348348
// room.connect(options.credentials),
349-
tokenSource.getTokenValue().then(({ serverUrl, participantToken }) => (
349+
tokenSource.generate().then(({ serverUrl, participantToken }) => (
350350
room.connect(serverUrl, participantToken)
351351
)),
352352

@@ -367,7 +367,7 @@ export function useSession(
367367
}, [room]);
368368

369369
const prepareConnection = useCallback(async () => {
370-
const credentials = await tokenSource.getTokenValue();
370+
const credentials = await tokenSource.generate();
371371
await room.prepareConnection(credentials.serverUrl, credentials.participantToken);
372372
}, [tokenSource, room]);
373373
useEffect(() => {

0 commit comments

Comments
 (0)