dont use throw for logic.
This commit is contained in:
@@ -105,35 +105,42 @@ export async function getSFUConfigWithOpenID(
|
|||||||
|
|
||||||
logger?.info(`Trying to get JWT for focus ${serviceUrl}...`);
|
logger?.info(`Trying to get JWT for focus ${serviceUrl}...`);
|
||||||
|
|
||||||
let sfuConfig: { url: string; jwt: string };
|
let sfuConfig: { url: string; jwt: string } | undefined;
|
||||||
try {
|
|
||||||
// we do not want to try the old endpoint, since we are not sending the new matrix2.0 sticky events (no hashed identity in the event)
|
|
||||||
if (forceOldJwtEndpoint) throw new Error("Force old jwt endpoint");
|
|
||||||
if (!delayId)
|
|
||||||
throw new Error("No delayId, Won't try matrix 2.0 jwt endpoint.");
|
|
||||||
|
|
||||||
sfuConfig = await getLiveKitJWTWithDelayDelegation(
|
// If forceOldJwtEndpoint is set we indicate that we do not want to try the new endpoint,
|
||||||
membership,
|
// since we are not sending the new matrix2.0 sticky events (no hashed identity in the event)
|
||||||
serviceUrl,
|
if (forceOldJwtEndpoint === false) {
|
||||||
roomId,
|
try {
|
||||||
openIdToken,
|
sfuConfig = await getLiveKitJWTWithDelayDelegation(
|
||||||
delayEndpointBaseUrl,
|
membership,
|
||||||
delayId,
|
serviceUrl,
|
||||||
);
|
roomId,
|
||||||
logger?.info(`Got JWT from call's active focus URL.`);
|
openIdToken,
|
||||||
} catch (e) {
|
delayEndpointBaseUrl,
|
||||||
logger?.warn(
|
delayId,
|
||||||
`Failed fetching jwt with matrix 2.0 endpoint (retry with legacy)`,
|
);
|
||||||
e,
|
logger?.info(`Got JWT from call's active focus URL.`);
|
||||||
);
|
} catch (e) {
|
||||||
|
sfuConfig = undefined;
|
||||||
|
logger?.warn(
|
||||||
|
`Failed fetching jwt with matrix 2.0 endpoint (retry with legacy)`,
|
||||||
|
e,
|
||||||
|
);
|
||||||
|
logger?.info(`Got JWT from call's active focus URL.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Either forceOldJwtEndpoint = true or getLiveKitJWTWithDelayDelegation throws -> reset sfuConfig = undefined
|
||||||
|
if (sfuConfig === undefined) {
|
||||||
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.`);
|
}
|
||||||
} // Pull the details from the JWT
|
|
||||||
|
// Pull the details from the JWT
|
||||||
const [, payloadStr] = sfuConfig.jwt.split(".");
|
const [, payloadStr] = sfuConfig.jwt.split(".");
|
||||||
// TODO: Prefer Uint8Array.fromBase64 when widely available
|
// TODO: Prefer Uint8Array.fromBase64 when widely available
|
||||||
const payload = JSON.parse(global.atob(payloadStr)) as SFUJWTPayload;
|
const payload = JSON.parse(global.atob(payloadStr)) as SFUJWTPayload;
|
||||||
|
|||||||
Reference in New Issue
Block a user