Skip to content

Commit 44509bd

Browse files
committed
fix: run npm run format
1 parent e1bdbfc commit 44509bd

File tree

3 files changed

+62
-40
lines changed

3 files changed

+62
-40
lines changed

src/room/token-source/TokenSource.ts

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import { 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';
414
import { 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. */
818
abstract 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>);
8394
export 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>;
102114
export class TokenSourceCustom extends TokenSourceCached {
103115
private customFn: CustomFn;
104116

@@ -125,7 +137,6 @@ export class TokenSourceCustom extends TokenSourceCached {
125137
}
126138
}
127139

128-
129140
export type EndpointOptions = Omit<RequestInit, 'body'>;
130141

131142
export 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

223238
export 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
},

src/room/token-source/types.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import { RoomConfiguration, TokenSourceRequest, TokenSourceResponse } from '@livekit/protocol';
22
import type { JWTPayload } from 'jose';
3+
import type { ValueToSnakeCase } from '../../utils/camelToSnakeCase';
34
// The below imports are being linked in tsdoc comments, so they have to be imported even if they
45
// aren't being used.
56
// eslint-disable-next-line @typescript-eslint/no-unused-vars
6-
import type { TokenSourceLiteral, TokenSourceEndpoint, TokenSourceCustom } from './TokenSource';
7-
import type { ValueToSnakeCase } from '../../utils/camelToSnakeCase';
7+
import type { TokenSourceCustom, TokenSourceEndpoint, TokenSourceLiteral } from './TokenSource';
88

9-
export type TokenSourceRequestObject = Required<NonNullable<ConstructorParameters<typeof TokenSourceRequest>[0]>>;
10-
export type TokenSourceResponseObject = Required<NonNullable<ConstructorParameters<typeof TokenSourceResponse>[0]>>;
9+
export type TokenSourceRequestObject = Required<
10+
NonNullable<ConstructorParameters<typeof TokenSourceRequest>[0]>
11+
>;
12+
export type TokenSourceResponseObject = Required<
13+
NonNullable<ConstructorParameters<typeof TokenSourceResponse>[0]>
14+
>;
1115

1216
/** The `TokenSource` request object sent to the server as part of fetching a configurable
1317
* `TokenSource` like {@link TokenSourceEndpoint}.
@@ -35,16 +39,17 @@ export type TokenPayload = JWTPayload & {
3539
canPublishData?: boolean;
3640
canSubscribe?: boolean;
3741
};
38-
roomConfig?: RoomConfigurationObject,
42+
roomConfig?: RoomConfigurationObject;
3943
};
40-
export type RoomConfigurationObject = NonNullable<ConstructorParameters<typeof RoomConfiguration>[0]>;
41-
44+
export type RoomConfigurationObject = NonNullable<
45+
ConstructorParameters<typeof RoomConfiguration>[0]
46+
>;
4247

4348
/** A Fixed TokenSource is a token source that takes no parameters and returns a completely
44-
* independant value on each fetch() call.
45-
*
46-
* The most common downstream implementer is {@link TokenSourceLiteral}.
47-
*/
49+
* independently derived value on each fetch() call.
50+
*
51+
* The most common downstream implementer is {@link TokenSourceLiteral}.
52+
*/
4853
export abstract class TokenSourceFixed {
4954
abstract fetch(): Promise<TokenSourceResponseObject>;
5055
}
@@ -60,16 +65,16 @@ export type TokenSourceOptions = {
6065
};
6166

6267
/** A Configurable TokenSource is a token source that takes a
63-
* {@link TokenSourceOptions} object as input and returns a deterministic
64-
* {@link TokenSourceResponseObject} output based on the options specified.
65-
*
66-
* For example, if options.participantName is set, it should be expected that
67-
* all tokens that are generated will have participant name field set to the
68-
* provided value.
69-
*
70-
* A few common downstream implementers are {@link TokenSourceEndpoint}
71-
* and {@link TokenSourceCustom}.
72-
*/
68+
* {@link TokenSourceOptions} object as input and returns a deterministic
69+
* {@link TokenSourceResponseObject} output based on the options specified.
70+
*
71+
* For example, if options.participantName is set, it should be expected that
72+
* all tokens that are generated will have participant name field set to the
73+
* provided value.
74+
*
75+
* A few common downstream implementers are {@link TokenSourceEndpoint}
76+
* and {@link TokenSourceCustom}.
77+
*/
7378
export abstract class TokenSourceConfigurable {
7479
abstract fetch(options: TokenSourceOptions): Promise<TokenSourceResponseObject>;
7580
}

src/room/token-source/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { decodeJwt } from "jose";
2-
import { RoomConfiguration, type TokenSourceResponse } from "@livekit/protocol";
3-
import type { RoomConfigurationObject, TokenPayload } from "./types";
1+
import { RoomConfiguration, type TokenSourceResponse } from '@livekit/protocol';
2+
import { decodeJwt } from 'jose';
3+
import type { RoomConfigurationObject, TokenPayload } from './types';
44

55
const ONE_SECOND_IN_MILLISECONDS = 1000;
66
const ONE_MINUTE_IN_MILLISECONDS = 60 * ONE_SECOND_IN_MILLISECONDS;
@@ -25,7 +25,9 @@ export function decodeTokenPayload(token: string) {
2525
const mappedPayload: TokenPayload = {
2626
...rest,
2727
roomConfig: payload.roomConfig
28-
? RoomConfiguration.fromJson(payload.roomConfig as Record<string, any>) as RoomConfigurationObject
28+
? (RoomConfiguration.fromJson(
29+
payload.roomConfig as Record<string, any>,
30+
) as RoomConfigurationObject)
2931
: undefined,
3032
};
3133

0 commit comments

Comments
 (0)