backend: Rename getRoomSecretRole to getRoomRoleBySecret and update related calls
This commit is contained in:
parent
81db83129b
commit
cc2dc83401
@ -34,7 +34,6 @@ export class MeetRoomHelper {
|
|||||||
static extractSecretsFromRoom(room: MeetRoom): { publisherSecret: string; moderatorSecret: string } {
|
static extractSecretsFromRoom(room: MeetRoom): { publisherSecret: string; moderatorSecret: string } {
|
||||||
const { publisherRoomUrl, moderatorRoomUrl } = room;
|
const { publisherRoomUrl, moderatorRoomUrl } = room;
|
||||||
|
|
||||||
|
|
||||||
const publisherUrl = new URL(publisherRoomUrl);
|
const publisherUrl = new URL(publisherRoomUrl);
|
||||||
const publisherSecret = publisherUrl.searchParams.get('secret') || '';
|
const publisherSecret = publisherUrl.searchParams.get('secret') || '';
|
||||||
const moderatorUrl = new URL(moderatorRoomUrl);
|
const moderatorUrl = new URL(moderatorRoomUrl);
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export const configureTokenAuth = async (req: Request, res: Response, next: Next
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const { roomId, secret } = req.body as TokenOptions;
|
const { roomId, secret } = req.body as TokenOptions;
|
||||||
role = await roomService.getRoomSecretRole(roomId, secret);
|
role = await roomService.getRoomRoleBySecret(roomId, secret);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error('Error getting room secret role', error);
|
logger.error('Error getting room secret role', error);
|
||||||
return res.status(500).json({ message: 'Internal server error' });
|
return res.status(500).json({ message: 'Internal server error' });
|
||||||
|
|||||||
@ -30,7 +30,7 @@ export class ParticipantService {
|
|||||||
throw errorParticipantNotFound(participantName, roomId);
|
throw errorParticipantNotFound(participantName, roomId);
|
||||||
}
|
}
|
||||||
|
|
||||||
const role = await this.roomService.getRoomSecretRole(roomId, secret);
|
const role = await this.roomService.getRoomRoleBySecret(roomId, secret);
|
||||||
const token = await this.generateParticipantToken(role, options);
|
const token = await this.generateParticipantToken(role, options);
|
||||||
this.logger.verbose(`Participant token generated for room ${roomId}`);
|
this.logger.verbose(`Participant token generated for room ${roomId}`);
|
||||||
return token;
|
return token;
|
||||||
|
|||||||
@ -232,21 +232,9 @@ export class RoomService {
|
|||||||
* @throws Error if the moderator or publisher secrets cannot be extracted from their URLs
|
* @throws Error if the moderator or publisher secrets cannot be extracted from their URLs
|
||||||
* @throws Error if the provided secret doesn't match any of the room's secrets (unauthorized)
|
* @throws Error if the provided secret doesn't match any of the room's secrets (unauthorized)
|
||||||
*/
|
*/
|
||||||
async getRoomSecretRole(roomId: string, secret: string): Promise<ParticipantRole> {
|
async getRoomRoleBySecret(roomId: string, secret: string): Promise<ParticipantRole> {
|
||||||
const room = await this.getMeetRoom(roomId);
|
const room = await this.getMeetRoom(roomId);
|
||||||
const { moderatorRoomUrl, publisherRoomUrl } = room;
|
const { moderatorSecret, publisherSecret } = MeetRoomHelper.extractSecretsFromRoom(room);
|
||||||
|
|
||||||
const extractSecret = (urlString: string, type: string): string => {
|
|
||||||
const url = new URL(urlString);
|
|
||||||
const secret = url.searchParams.get('secret');
|
|
||||||
|
|
||||||
if (!secret) throw new Error(`${type} secret not found`);
|
|
||||||
|
|
||||||
return secret;
|
|
||||||
};
|
|
||||||
|
|
||||||
const publisherSecret = extractSecret(publisherRoomUrl, 'Publisher');
|
|
||||||
const moderatorSecret = extractSecret(moderatorRoomUrl, 'Moderator');
|
|
||||||
|
|
||||||
switch (secret) {
|
switch (secret) {
|
||||||
case moderatorSecret:
|
case moderatorSecret:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user