add retries inside the getLiveKitJWTWithDelayDelegation and
`getLiveKitJWT` functions.
This commit is contained in:
@@ -6,7 +6,6 @@ Please see LICENSE in the repository root for full details.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
HTTPError,
|
|
||||||
retryNetworkOperation,
|
retryNetworkOperation,
|
||||||
type IOpenIDToken,
|
type IOpenIDToken,
|
||||||
type MatrixClient,
|
type MatrixClient,
|
||||||
@@ -116,17 +115,15 @@ export async function getSFUConfigWithOpenID(
|
|||||||
// since we are not sending the new matrix2.0 sticky events (no hashed identity in the event)
|
// since we are not sending the new matrix2.0 sticky events (no hashed identity in the event)
|
||||||
if (forceOldJwtEndpoint === false) {
|
if (forceOldJwtEndpoint === false) {
|
||||||
try {
|
try {
|
||||||
await retryNetworkOperation(4, async () => {
|
sfuConfig = await getLiveKitJWTWithDelayDelegation(
|
||||||
sfuConfig = await getLiveKitJWTWithDelayDelegation(
|
membership,
|
||||||
membership,
|
serviceUrl,
|
||||||
serviceUrl,
|
roomId,
|
||||||
roomId,
|
openIdToken,
|
||||||
openIdToken,
|
delayEndpointBaseUrl,
|
||||||
delayEndpointBaseUrl,
|
delayId,
|
||||||
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) {
|
||||||
if (e instanceof NotSupportedError) {
|
if (e instanceof NotSupportedError) {
|
||||||
logger?.warn(
|
logger?.warn(
|
||||||
@@ -146,14 +143,13 @@ export async function getSFUConfigWithOpenID(
|
|||||||
// DEPRECATED
|
// DEPRECATED
|
||||||
// Either forceOldJwtEndpoint = true or getLiveKitJWTWithDelayDelegation throws -> reset sfuConfig = undefined
|
// Either forceOldJwtEndpoint = true or getLiveKitJWTWithDelayDelegation throws -> reset sfuConfig = undefined
|
||||||
if (sfuConfig === undefined) {
|
if (sfuConfig === undefined) {
|
||||||
await retryNetworkOperation(4, async () => {
|
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.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,25 +171,33 @@ export async function getSFUConfigWithOpenID(
|
|||||||
livekitIdentity: payload.sub,
|
livekitIdentity: payload.sub,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
const RETRIES = 4;
|
||||||
async function getLiveKitJWT(
|
async function getLiveKitJWT(
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
livekitServiceURL: string,
|
livekitServiceURL: string,
|
||||||
matrixRoomId: string,
|
matrixRoomId: string,
|
||||||
openIDToken: IOpenIDToken,
|
openIDToken: IOpenIDToken,
|
||||||
): Promise<{ url: string; jwt: string }> {
|
): Promise<{ url: string; jwt: string }> {
|
||||||
const res = await fetch(livekitServiceURL + "/sfu/get", {
|
let res: Response | undefined;
|
||||||
method: "POST",
|
await retryNetworkOperation(RETRIES, async () => {
|
||||||
headers: {
|
res = await fetch(livekitServiceURL + "/sfu/get", {
|
||||||
"Content-Type": "application/json",
|
method: "POST",
|
||||||
},
|
headers: {
|
||||||
body: JSON.stringify({
|
"Content-Type": "application/json",
|
||||||
// This is the actual livekit room alias. For the legacy jwt endpoint simply the room id was used.
|
},
|
||||||
room: matrixRoomId,
|
body: JSON.stringify({
|
||||||
openid_token: openIDToken,
|
// This is the actual livekit room alias. For the legacy jwt endpoint simply the room id was used.
|
||||||
device_id: deviceId,
|
room: matrixRoomId,
|
||||||
}),
|
openid_token: openIDToken,
|
||||||
|
device_id: deviceId,
|
||||||
|
}),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
if (!res) {
|
||||||
|
throw new Error(
|
||||||
|
`Network error while connecting to jwt service after ${RETRIES} retries`,
|
||||||
|
);
|
||||||
|
}
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
throw new Error("SFU Config fetch failed with status code " + res.status);
|
throw new Error("SFU Config fetch failed with status code " + res.status);
|
||||||
}
|
}
|
||||||
@@ -240,13 +244,23 @@ export async function getLiveKitJWTWithDelayDelegation(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await fetch(livekitServiceURL + "/get_token", {
|
let res: Response | undefined;
|
||||||
method: "POST",
|
|
||||||
headers: {
|
await retryNetworkOperation(RETRIES, async () => {
|
||||||
"Content-Type": "application/json",
|
res = await fetch(livekitServiceURL + "/get_token", {
|
||||||
},
|
method: "POST",
|
||||||
body: JSON.stringify({ ...body, ...bodyDalayParts }),
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ ...body, ...bodyDalayParts }),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!res) {
|
||||||
|
throw new Error(
|
||||||
|
`Network error while connecting to jwt service after ${RETRIES} retries`,
|
||||||
|
);
|
||||||
|
}
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const msg = "SFU Config fetch failed with status code " + res.status;
|
const msg = "SFU Config fetch failed with status code " + res.status;
|
||||||
if (res.status === 404) {
|
if (res.status === 404) {
|
||||||
|
|||||||
Reference in New Issue
Block a user