make logger mandatory add some logs

This commit is contained in:
Valere
2026-03-20 08:05:22 +01:00
parent f244a00d6c
commit 29720d4376
6 changed files with 28 additions and 12 deletions

View File

@@ -15,6 +15,7 @@ import {
vitest,
} from "vitest";
import fetchMock from "fetch-mock";
import { logger } from "matrix-js-sdk/lib/logger";
import { getSFUConfigWithOpenID, type OpenIDClientParts } from "./openIDSFU";
import { testJWTToken } from "../utils/test-fixtures";
@@ -47,6 +48,7 @@ describe("getSFUConfigWithOpenID", () => {
ownMemberMock,
"https://sfu.example.org",
"!example_room_id",
logger,
);
expect(config).toEqual({
jwt: testJWTToken,
@@ -70,6 +72,7 @@ describe("getSFUConfigWithOpenID", () => {
ownMemberMock,
"https://sfu.example.org",
"!example_room_id",
logger,
);
} catch (ex) {
expect((ex as Error).message).toEqual(
@@ -100,6 +103,7 @@ describe("getSFUConfigWithOpenID", () => {
ownMemberMock,
"https://sfu.example.org",
"!example_room_id",
logger,
{
delayEndpointBaseUrl: "https://matrix.homeserverserver.org",
delayId: "mock_delay_id",
@@ -154,6 +158,7 @@ describe("getSFUConfigWithOpenID", () => {
ownMemberMock,
"https://sfu.example.org",
"!example_room_id",
logger,
{
delayEndpointBaseUrl: "https://matrix.homeserverserver.org",
delayId: "mock_delay_id",
@@ -204,6 +209,7 @@ describe("getSFUConfigWithOpenID", () => {
ownMemberMock,
"https://sfu.example.org",
"!example_room_id",
logger,
);
expect(config).toEqual({
jwt: testJWTToken,

View File

@@ -78,6 +78,7 @@ export type OpenIDClientParts = Pick<
* @param membership Our own membership identity parts used to send to jwt service.
* @param serviceUrl The URL of the livekit SFU service
* @param roomId The room id used in the jwt request. This is NOT the livekit_alias. The jwt service will provide the alias. It maps matrix room ids <-> Livekit aliases.
* @param logger optional logger.
* @param opts Additional options to modify which endpoint with which data will be used to acquire the jwt token.
* @param opts.forceJwtEndpoint This will use the old jwt endpoint which will create the rtc backend identity based on string concatenation
* instead of a hash.
@@ -86,7 +87,6 @@ export type OpenIDClientParts = Pick<
* For our own connection we can only use the hashed version if we also send the new matrix2.0 sticky events.
* @param opts.delayEndpointBaseUrl The URL of the matrix homeserver.
* @param opts.delayId The delay id used for the jwt service to manage.
* @param logger optional logger.
* @returns Object containing the token information
* @throws FailToGetOpenIdToken
*/
@@ -95,12 +95,12 @@ export async function getSFUConfigWithOpenID(
membership: CallMembershipIdentityParts,
serviceUrl: string,
roomId: string,
logger: Logger,
opts?: {
forceJwtEndpoint?: JwtEndpointVersion;
delayEndpointBaseUrl?: string;
delayId?: string;
},
logger?: Logger,
): Promise<SFUConfig> {
let openIdToken: IOpenIDToken;
try {
@@ -108,13 +108,12 @@ export async function getSFUConfigWithOpenID(
client.getOpenIdToken(),
);
} catch (error) {
logger.error("Failed to get openID token", error);
throw new FailToGetOpenIdToken(
error instanceof Error ? error : new Error("Unknown error"),
);
}
logger?.debug("Got openID token", openIdToken);
logger?.info(`Trying to get JWT for focus ${serviceUrl}...`);
logger.debug("Got openID token", { ...openIdToken, access_token: "XXXXX" });
let sfuConfig: { url: string; jwt: string } | undefined;
@@ -123,6 +122,11 @@ export async function getSFUConfigWithOpenID(
const forceMatrix2Jwt =
opts?.forceJwtEndpoint === JwtEndpointVersion.Matrix_2_0;
logger.debug(
`Trying to get JWT for focus ${serviceUrl} / forceMatrix2Jwt:${forceMatrix2Jwt}...`,
opts,
);
// We want to start using the new endpoint (with optional delay delegation)
// if we can use both or if we are forced to use the new one.
if (tryBothJwtEndpoints || forceMatrix2Jwt) {
@@ -135,16 +139,17 @@ export async function getSFUConfigWithOpenID(
opts?.delayEndpointBaseUrl,
opts?.delayId,
);
logger?.info(`Got JWT from call's active focus URL.`);
logger.info(`Got JWT from call's active focus URL.`);
} catch (e) {
logger.warn(`Failed fetching jwt with matrix 2.0 endpoint`, e);
if (e instanceof NotSupportedError) {
logger?.warn(
logger.warn(
`Failed fetching jwt with matrix 2.0 endpoint (retry with legacy) Not supported`,
e,
);
sfuConfig = undefined;
} else {
logger?.warn(
logger.warn(
`Failed fetching jwt with matrix 2.0 endpoint other issues ->`,
`(not going to try with legacy endpoint: forceOldJwtEndpoint is set to false, we did not get a not supported error from the sfu)`,
e,
@@ -161,13 +166,16 @@ export async function getSFUConfigWithOpenID(
// here we either have a sfuConfig or we alredy exited because of `if (forceMatrix2) throw ...`
// The only case we can get into this condition is, if `forceMatrix2` is `false`
if (sfuConfig === undefined) {
logger.debug(
`Trying to get JWT for focus ${serviceUrl} (legacy endpoint)...`,
);
sfuConfig = await getLiveKitJWT(
membership.deviceId,
serviceUrl,
roomId,
openIdToken,
);
logger?.info(`Got JWT from call's active focus URL.`);
logger.info(`Got JWT from call's active focus URL.`);
}
if (!sfuConfig) {

View File

@@ -214,6 +214,7 @@ describe("DeveloperSettingsTab", () => {
expect.anything(),
"wss://example.livekit.valid",
"#testRoom",
expect.anything(),
);
expect(customLivekitUrlSetting.getValue()).toBe(

View File

@@ -262,6 +262,7 @@ export const DeveloperSettingsTab: FC<Props> = ({
{ userId, deviceId, memberId: "" },
customLivekitUrlTextBuffer,
roomId,
logger,
);
setCustomLivekitUrlUpdateError(null);
setCustomLivekitUrl(customLivekitUrlTextBuffer);

View File

@@ -257,8 +257,8 @@ export const createLocalTransport$ = ({
ownMembershipIdentity,
transport.livekit_service_url,
roomId,
{ forceJwtEndpoint: JwtEndpointVersion.Legacy },
logger,
{ forceJwtEndpoint: JwtEndpointVersion.Legacy },
),
});
return from(fetchOldestMemberTransport()).pipe(startWith(null));
@@ -336,12 +336,12 @@ async function makeTransport(
membership,
url,
roomId,
logger,
{
forceJwtEndpoint: forceJwtEndpoint,
delayEndpointBaseUrl: client.baseUrl,
delayId,
},
logger,
);
return {
transport: {

View File

@@ -275,9 +275,9 @@ export class Connection {
this.ownMembershipIdentity,
this.transport.livekit_service_url,
this.roomId,
this.logger,
// dont pass any custom opts for the subscribe only connections
{},
this.logger,
);
}