backend: Add endpoint to retrieve participant role by room secret

This commit is contained in:
juancarmore 2025-03-28 12:12:33 +01:00
parent 8422b3c38a
commit bc33e9c5d9
4 changed files with 57 additions and 2 deletions

View File

@ -94,6 +94,24 @@ export const deleteRooms = async (req: Request, res: Response) => {
}
};
export const getParticipantRole = async (req: Request, res: Response) => {
const logger = container.get(LoggerService);
const roomService = container.get(RoomService);
const { roomName } = req.params;
const { secret } = req.query as { secret: string };
try {
logger.verbose(`Getting participant role for room '${roomName}'`);
const role = await roomService.getRoomSecretRole(roomName, secret);
return res.status(200).json(role);
} catch (error) {
logger.error(`Error getting participant role for room '${roomName}'`);
handleError(res, error);
}
};
export const updateRoomPreferences = async (req: Request, res: Response) => {
const logger = container.get(LoggerService);

View File

@ -49,6 +49,10 @@ const RoomRequestOptionsSchema: z.ZodType<OpenViduMeetRoomOptions> = z.object({
.default(null)
});
const GetParticipantRoleSchema = z.object({
secret: z.string()
});
export const validateRoomRequest = (req: Request, res: Response, next: NextFunction) => {
const { success, error, data } = RoomRequestOptionsSchema.safeParse(req.body);
@ -80,4 +84,24 @@ export const validateGetRoomQueryParams = (req: Request, res: Response, next: Ne
}
next();
}
};
export const validateGetParticipantRoleRequest = (req: Request, res: Response, next: NextFunction) => {
const { success, error, data } = GetParticipantRoleSchema.safeParse(req.query);
if (!success) {
const errors = error.errors.map((error) => ({
field: error.path.join('.'),
message: error.message
}));
return res.status(422).json({
error: 'Unprocessable Entity',
message: 'Invalid request query',
details: errors
});
}
req.query = data;
next();
};

View File

@ -8,6 +8,7 @@ import {
participantTokenValidator
} from '../middlewares/auth.middleware.js';
import {
validateGetParticipantRoleRequest,
validateGetRoomQueryParams,
validateRoomRequest
} from '../middlewares/request-validators/room-validator.middleware.js';
@ -38,3 +39,10 @@ roomRouter.delete('/:roomName', withAuth(apiKeyValidator, tokenAndRoleValidator(
// Room preferences
roomRouter.put('/', withAuth(apiKeyValidator, tokenAndRoleValidator(UserRole.ADMIN)), roomCtrl.updateRoomPreferences);
// Internal room routes
export const internalRoomRouter = Router();
internalRoomRouter.use(bodyParser.urlencoded({ extended: true }));
internalRoomRouter.use(bodyParser.json());
internalRoomRouter.get('/:roomName/participant-role', validateGetParticipantRoleRequest, roomCtrl.getParticipantRole);

View File

@ -13,6 +13,7 @@ import { openapiHtmlPath, indexHtmlPath, publicFilesPath, webcomponentBundlePath
import {
authRouter,
internalRecordingRouter,
internalRoomRouter,
livekitWebhookRouter,
preferencesRouter,
recordingRouter,
@ -49,6 +50,7 @@ const createApp = () => {
app.use(`${MEET_API_BASE_PATH_V1}/preferences`, /*mediaTypeValidatorMiddleware,*/ preferencesRouter);
// Internal routes
app.use(`${MEET_INTERNAL_API_BASE_PATH_V1}/rooms`, internalRoomRouter);
app.use(`${MEET_INTERNAL_API_BASE_PATH_V1}/participants`, internalParticipantsRouter);
app.use(`${MEET_INTERNAL_API_BASE_PATH_V1}/recordings`, internalRecordingRouter);
app.use('/meet/health', (_req: Request, res: Response) => res.status(200).send('OK'));
@ -76,7 +78,10 @@ const startServer = (app: express.Application) => {
console.log('---------------------------------------------------------');
console.log(' ');
console.log('OpenVidu Meet is listening on port', chalk.cyanBright(SERVER_PORT));
console.log('REST API Docs: ', chalk.cyanBright(`http://localhost:${SERVER_PORT}${MEET_API_BASE_PATH_V1}/docs`));
console.log(
'REST API Docs: ',
chalk.cyanBright(`http://localhost:${SERVER_PORT}${MEET_API_BASE_PATH_V1}/docs`)
);
logEnvVars();
await Promise.all([initializeGlobalPreferences(), container.get(RoomService).initialize()]);
});