Skip to content

Commit a278b35

Browse files
authored
Merge pull request #2 from mconf/v1.23.8-mconf-custom-bbb-on-demand
Call admin API before joining a BBB room to get fresh credentials
2 parents dd3f252 + e5aaa82 commit a278b35

File tree

3 files changed

+72
-4
lines changed

3 files changed

+72
-4
lines changed

back/src/Model/GameRoom.ts

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,32 @@ export class GameRoom implements BrothersFinder {
768768
throw new Error("Unexpected room redirect received or error while querying map details");
769769
}
770770

771+
/**
772+
* Connects to the admin server to fetch map details with user context.
773+
* This version passes user information to the admin API to get user-specific settings.
774+
*/
775+
private static async getMapDetailsWithUser(roomUrl: string, user: User): Promise<MapDetailsData> {
776+
if (!ADMIN_API_URL) {
777+
// Fall back to the regular method if no admin API
778+
return GameRoom.getMapDetails(roomUrl);
779+
}
780+
781+
const userId = user.uuid;
782+
const result = isMapDetailsData.safeParse(await adminApi.fetchMapDetails(roomUrl, userId));
783+
784+
if (result.success) {
785+
return result.data;
786+
}
787+
788+
console.error(result.error.issues);
789+
console.error("Unexpected room redirect or error received while querying map details with user", result);
790+
Sentry.captureException(result.error.issues);
791+
Sentry.captureException(
792+
`Unexpected room redirect or error received while querying map details with user ${JSON.stringify(result)}`
793+
);
794+
throw new Error("Unexpected room redirect received or error while querying map details with user");
795+
}
796+
771797
private mapPromise: Promise<ITiledMap> | undefined;
772798

773799
/**
@@ -1050,17 +1076,47 @@ export class GameRoom implements BrothersFinder {
10501076
return undefined;
10511077
}
10521078

1053-
public getBbbSettings(): MapBbbData | undefined {
1079+
public async getBbbSettings(user?: User): Promise<MapBbbData | undefined> {
1080+
// If we have a user, try to get fresh settings from admin API
1081+
if (user && ADMIN_API_URL) {
1082+
try {
1083+
console.log(`Attempting to fetch fresh BBB settings for user: ${user.name} (${user.uuid})`);
1084+
const mapDetails = await GameRoom.getMapDetailsWithUser(this._roomUrl, user);
1085+
if (mapDetails.thirdParty?.bbb) {
1086+
console.log(`Using fresh BBB settings from Admin API for user: `, {
1087+
url: mapDetails.thirdParty.bbb.url,
1088+
secret: "[REDACTED]",
1089+
});
1090+
return mapDetails.thirdParty.bbb;
1091+
}
1092+
} catch (e) {
1093+
console.warn("Failed to fetch fresh BBB settings, falling back to stored settings", e);
1094+
}
1095+
}
1096+
1097+
// Fall back to stored settings
10541098
const bbb = this.thirdParty?.bbb;
10551099
if (bbb) {
1100+
console.log(`Using stored BBB settings from Admin API: `, {
1101+
url: bbb.url,
1102+
secret: "[REDACTED]",
1103+
});
10561104
return bbb;
10571105
}
1106+
1107+
// Environment variable fallback
10581108
if (BBB_URL && BBB_SECRET) {
1109+
console.log(`Using BBB settings from environment variables: `, {
1110+
url: BBB_URL,
1111+
secret: "[REDACTED]",
1112+
});
10591113
return {
10601114
url: BBB_URL,
10611115
secret: BBB_SECRET,
10621116
};
10631117
}
1118+
1119+
console.log(`No BBB settings available`);
10641120
return undefined;
10651121
}
10661122

back/src/Services/AdminApi.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,27 @@ import * as Sentry from "@sentry/node";
1111
import { ADMIN_API_TOKEN, ADMIN_API_URL } from "../Enum/EnvironmentVariable";
1212

1313
class AdminApi {
14-
async fetchMapDetails(playUri: string): Promise<MapDetailsData | RoomRedirect | ErrorApiData> {
14+
async fetchMapDetails(
15+
playUri: string,
16+
userId?: string,
17+
accessToken?: string
18+
): Promise<MapDetailsData | RoomRedirect | ErrorApiData> {
1519
if (!ADMIN_API_URL) {
1620
return Promise.reject(new Error("No admin backoffice set!"));
1721
}
1822

19-
const params: { playUri: string } = {
23+
const params: { playUri: string; userId?: string; accessToken?: string } = {
2024
playUri,
2125
};
2226

27+
// Add user parameters if provided
28+
if (userId) {
29+
params.userId = userId;
30+
}
31+
if (accessToken) {
32+
params.accessToken = accessToken;
33+
}
34+
2335
try {
2436
const res = await axios.get(ADMIN_API_URL + "/api/map", {
2537
headers: { Authorization: `${ADMIN_API_TOKEN ?? ""}` },

back/src/Services/SocketManager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ export class SocketManager {
894894
let meetingId = joinBBBMeetingQuery.meetingId;
895895
const localMeetingId = joinBBBMeetingQuery.localMeetingId;
896896
const meetingName = joinBBBMeetingQuery.meetingName;
897-
const bbbSettings = gameRoom.getBbbSettings();
897+
const bbbSettings = await gameRoom.getBbbSettings(user);
898898

899899
if (bbbSettings === undefined) {
900900
throw new Error(

0 commit comments

Comments
 (0)