mirror of
https://github.com/vector-im/element-call.git
synced 2026-08-05 19:59:20 +00:00
make logger mandatory add some logs
This commit is contained in:
@@ -15,6 +15,7 @@ import {
|
|||||||
vitest,
|
vitest,
|
||||||
} from "vitest";
|
} from "vitest";
|
||||||
import fetchMock from "fetch-mock";
|
import fetchMock from "fetch-mock";
|
||||||
|
import { logger } from "matrix-js-sdk/lib/logger";
|
||||||
|
|
||||||
import { getSFUConfigWithOpenID, type OpenIDClientParts } from "./openIDSFU";
|
import { getSFUConfigWithOpenID, type OpenIDClientParts } from "./openIDSFU";
|
||||||
import { testJWTToken } from "../utils/test-fixtures";
|
import { testJWTToken } from "../utils/test-fixtures";
|
||||||
@@ -47,6 +48,7 @@ describe("getSFUConfigWithOpenID", () => {
|
|||||||
ownMemberMock,
|
ownMemberMock,
|
||||||
"https://sfu.example.org",
|
"https://sfu.example.org",
|
||||||
"!example_room_id",
|
"!example_room_id",
|
||||||
|
logger,
|
||||||
);
|
);
|
||||||
expect(config).toEqual({
|
expect(config).toEqual({
|
||||||
jwt: testJWTToken,
|
jwt: testJWTToken,
|
||||||
@@ -70,6 +72,7 @@ describe("getSFUConfigWithOpenID", () => {
|
|||||||
ownMemberMock,
|
ownMemberMock,
|
||||||
"https://sfu.example.org",
|
"https://sfu.example.org",
|
||||||
"!example_room_id",
|
"!example_room_id",
|
||||||
|
logger,
|
||||||
);
|
);
|
||||||
} catch (ex) {
|
} catch (ex) {
|
||||||
expect((ex as Error).message).toEqual(
|
expect((ex as Error).message).toEqual(
|
||||||
@@ -100,6 +103,7 @@ describe("getSFUConfigWithOpenID", () => {
|
|||||||
ownMemberMock,
|
ownMemberMock,
|
||||||
"https://sfu.example.org",
|
"https://sfu.example.org",
|
||||||
"!example_room_id",
|
"!example_room_id",
|
||||||
|
logger,
|
||||||
{
|
{
|
||||||
delayEndpointBaseUrl: "https://matrix.homeserverserver.org",
|
delayEndpointBaseUrl: "https://matrix.homeserverserver.org",
|
||||||
delayId: "mock_delay_id",
|
delayId: "mock_delay_id",
|
||||||
@@ -154,6 +158,7 @@ describe("getSFUConfigWithOpenID", () => {
|
|||||||
ownMemberMock,
|
ownMemberMock,
|
||||||
"https://sfu.example.org",
|
"https://sfu.example.org",
|
||||||
"!example_room_id",
|
"!example_room_id",
|
||||||
|
logger,
|
||||||
{
|
{
|
||||||
delayEndpointBaseUrl: "https://matrix.homeserverserver.org",
|
delayEndpointBaseUrl: "https://matrix.homeserverserver.org",
|
||||||
delayId: "mock_delay_id",
|
delayId: "mock_delay_id",
|
||||||
@@ -204,6 +209,7 @@ describe("getSFUConfigWithOpenID", () => {
|
|||||||
ownMemberMock,
|
ownMemberMock,
|
||||||
"https://sfu.example.org",
|
"https://sfu.example.org",
|
||||||
"!example_room_id",
|
"!example_room_id",
|
||||||
|
logger,
|
||||||
);
|
);
|
||||||
expect(config).toEqual({
|
expect(config).toEqual({
|
||||||
jwt: testJWTToken,
|
jwt: testJWTToken,
|
||||||
|
|||||||
@@ -78,6 +78,7 @@ export type OpenIDClientParts = Pick<
|
|||||||
* @param membership Our own membership identity parts used to send to jwt service.
|
* @param membership Our own membership identity parts used to send to jwt service.
|
||||||
* @param serviceUrl The URL of the livekit SFU 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 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 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
|
* @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.
|
* 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.
|
* 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.delayEndpointBaseUrl The URL of the matrix homeserver.
|
||||||
* @param opts.delayId The delay id used for the jwt service to manage.
|
* @param opts.delayId The delay id used for the jwt service to manage.
|
||||||
* @param logger optional logger.
|
|
||||||
* @returns Object containing the token information
|
* @returns Object containing the token information
|
||||||
* @throws FailToGetOpenIdToken
|
* @throws FailToGetOpenIdToken
|
||||||
*/
|
*/
|
||||||
@@ -95,12 +95,12 @@ export async function getSFUConfigWithOpenID(
|
|||||||
membership: CallMembershipIdentityParts,
|
membership: CallMembershipIdentityParts,
|
||||||
serviceUrl: string,
|
serviceUrl: string,
|
||||||
roomId: string,
|
roomId: string,
|
||||||
|
logger: Logger,
|
||||||
opts?: {
|
opts?: {
|
||||||
forceJwtEndpoint?: JwtEndpointVersion;
|
forceJwtEndpoint?: JwtEndpointVersion;
|
||||||
delayEndpointBaseUrl?: string;
|
delayEndpointBaseUrl?: string;
|
||||||
delayId?: string;
|
delayId?: string;
|
||||||
},
|
},
|
||||||
logger?: Logger,
|
|
||||||
): Promise<SFUConfig> {
|
): Promise<SFUConfig> {
|
||||||
let openIdToken: IOpenIDToken;
|
let openIdToken: IOpenIDToken;
|
||||||
try {
|
try {
|
||||||
@@ -108,13 +108,12 @@ export async function getSFUConfigWithOpenID(
|
|||||||
client.getOpenIdToken(),
|
client.getOpenIdToken(),
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
logger.error("Failed to get openID token", error);
|
||||||
throw new FailToGetOpenIdToken(
|
throw new FailToGetOpenIdToken(
|
||||||
error instanceof Error ? error : new Error("Unknown error"),
|
error instanceof Error ? error : new Error("Unknown error"),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
logger?.debug("Got openID token", openIdToken);
|
logger.debug("Got openID token", { ...openIdToken, access_token: "XXXXX" });
|
||||||
|
|
||||||
logger?.info(`Trying to get JWT for focus ${serviceUrl}...`);
|
|
||||||
|
|
||||||
let sfuConfig: { url: string; jwt: string } | undefined;
|
let sfuConfig: { url: string; jwt: string } | undefined;
|
||||||
|
|
||||||
@@ -123,6 +122,11 @@ export async function getSFUConfigWithOpenID(
|
|||||||
const forceMatrix2Jwt =
|
const forceMatrix2Jwt =
|
||||||
opts?.forceJwtEndpoint === JwtEndpointVersion.Matrix_2_0;
|
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)
|
// 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 we can use both or if we are forced to use the new one.
|
||||||
if (tryBothJwtEndpoints || forceMatrix2Jwt) {
|
if (tryBothJwtEndpoints || forceMatrix2Jwt) {
|
||||||
@@ -135,16 +139,17 @@ export async function getSFUConfigWithOpenID(
|
|||||||
opts?.delayEndpointBaseUrl,
|
opts?.delayEndpointBaseUrl,
|
||||||
opts?.delayId,
|
opts?.delayId,
|
||||||
);
|
);
|
||||||
logger?.info(`Got JWT from call's active focus URL.`);
|
logger.info(`Got JWT from call's active focus URL.`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
logger.warn(`Failed fetching jwt with matrix 2.0 endpoint`, e);
|
||||||
if (e instanceof NotSupportedError) {
|
if (e instanceof NotSupportedError) {
|
||||||
logger?.warn(
|
logger.warn(
|
||||||
`Failed fetching jwt with matrix 2.0 endpoint (retry with legacy) Not supported`,
|
`Failed fetching jwt with matrix 2.0 endpoint (retry with legacy) Not supported`,
|
||||||
e,
|
e,
|
||||||
);
|
);
|
||||||
sfuConfig = undefined;
|
sfuConfig = undefined;
|
||||||
} else {
|
} else {
|
||||||
logger?.warn(
|
logger.warn(
|
||||||
`Failed fetching jwt with matrix 2.0 endpoint other issues ->`,
|
`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)`,
|
`(not going to try with legacy endpoint: forceOldJwtEndpoint is set to false, we did not get a not supported error from the sfu)`,
|
||||||
e,
|
e,
|
||||||
@@ -161,13 +166,16 @@ export async function getSFUConfigWithOpenID(
|
|||||||
// here we either have a sfuConfig or we alredy exited because of `if (forceMatrix2) throw ...`
|
// 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`
|
// The only case we can get into this condition is, if `forceMatrix2` is `false`
|
||||||
if (sfuConfig === undefined) {
|
if (sfuConfig === undefined) {
|
||||||
|
logger.debug(
|
||||||
|
`Trying to get JWT for focus ${serviceUrl} (legacy endpoint)...`,
|
||||||
|
);
|
||||||
sfuConfig = await getLiveKitJWT(
|
sfuConfig = await getLiveKitJWT(
|
||||||
membership.deviceId,
|
membership.deviceId,
|
||||||
serviceUrl,
|
serviceUrl,
|
||||||
roomId,
|
roomId,
|
||||||
openIdToken,
|
openIdToken,
|
||||||
);
|
);
|
||||||
logger?.info(`Got JWT from call's active focus URL.`);
|
logger.info(`Got JWT from call's active focus URL.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sfuConfig) {
|
if (!sfuConfig) {
|
||||||
|
|||||||
@@ -214,6 +214,7 @@ describe("DeveloperSettingsTab", () => {
|
|||||||
expect.anything(),
|
expect.anything(),
|
||||||
"wss://example.livekit.valid",
|
"wss://example.livekit.valid",
|
||||||
"#testRoom",
|
"#testRoom",
|
||||||
|
expect.anything(),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(customLivekitUrlSetting.getValue()).toBe(
|
expect(customLivekitUrlSetting.getValue()).toBe(
|
||||||
|
|||||||
@@ -262,6 +262,7 @@ export const DeveloperSettingsTab: FC<Props> = ({
|
|||||||
{ userId, deviceId, memberId: "" },
|
{ userId, deviceId, memberId: "" },
|
||||||
customLivekitUrlTextBuffer,
|
customLivekitUrlTextBuffer,
|
||||||
roomId,
|
roomId,
|
||||||
|
logger,
|
||||||
);
|
);
|
||||||
setCustomLivekitUrlUpdateError(null);
|
setCustomLivekitUrlUpdateError(null);
|
||||||
setCustomLivekitUrl(customLivekitUrlTextBuffer);
|
setCustomLivekitUrl(customLivekitUrlTextBuffer);
|
||||||
|
|||||||
@@ -257,8 +257,8 @@ export const createLocalTransport$ = ({
|
|||||||
ownMembershipIdentity,
|
ownMembershipIdentity,
|
||||||
transport.livekit_service_url,
|
transport.livekit_service_url,
|
||||||
roomId,
|
roomId,
|
||||||
{ forceJwtEndpoint: JwtEndpointVersion.Legacy },
|
|
||||||
logger,
|
logger,
|
||||||
|
{ forceJwtEndpoint: JwtEndpointVersion.Legacy },
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
return from(fetchOldestMemberTransport()).pipe(startWith(null));
|
return from(fetchOldestMemberTransport()).pipe(startWith(null));
|
||||||
@@ -336,12 +336,12 @@ async function makeTransport(
|
|||||||
membership,
|
membership,
|
||||||
url,
|
url,
|
||||||
roomId,
|
roomId,
|
||||||
|
logger,
|
||||||
{
|
{
|
||||||
forceJwtEndpoint: forceJwtEndpoint,
|
forceJwtEndpoint: forceJwtEndpoint,
|
||||||
delayEndpointBaseUrl: client.baseUrl,
|
delayEndpointBaseUrl: client.baseUrl,
|
||||||
delayId,
|
delayId,
|
||||||
},
|
},
|
||||||
logger,
|
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
transport: {
|
transport: {
|
||||||
|
|||||||
@@ -275,9 +275,9 @@ export class Connection {
|
|||||||
this.ownMembershipIdentity,
|
this.ownMembershipIdentity,
|
||||||
this.transport.livekit_service_url,
|
this.transport.livekit_service_url,
|
||||||
this.roomId,
|
this.roomId,
|
||||||
|
this.logger,
|
||||||
// dont pass any custom opts for the subscribe only connections
|
// dont pass any custom opts for the subscribe only connections
|
||||||
{},
|
{},
|
||||||
this.logger,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user