diff --git a/backend/src/controllers/participant.controller.ts b/backend/src/controllers/participant.controller.ts index 567b4a0..3985d7e 100644 --- a/backend/src/controllers/participant.controller.ts +++ b/backend/src/controllers/participant.controller.ts @@ -1,7 +1,7 @@ import { container } from '../config/dependency-injector.config.js'; import { Request, Response } from 'express'; import { LoggerService } from '../services/logger.service.js'; -import { TokenOptions } from '@typings-ce'; +import { ParticipantOptions } from '@typings-ce'; import { OpenViduMeetError } from '../models/index.js'; import { ParticipantService } from '../services/participant.service.js'; import { MEET_PARTICIPANT_TOKEN_EXPIRATION } from '../environment.js'; @@ -14,15 +14,19 @@ export const generateParticipantToken = async (req: Request, res: Response) => { const logger = container.get(LoggerService); const participantService = container.get(ParticipantService); const roomService = container.get(RoomService); - const tokenOptions: TokenOptions = req.body; - const { roomId } = tokenOptions; + const participantOptions: ParticipantOptions = req.body; + const { roomId } = participantOptions; try { logger.verbose(`Generating participant token for room ${roomId}`); await roomService.createLivekitRoom(roomId); - const token = await participantService.generateOrRefreshParticipantToken(tokenOptions); + const token = await participantService.generateOrRefreshParticipantToken(participantOptions); - res.cookie(INTERNAL_CONFIG.PARTICIPANT_TOKEN_COOKIE_NAME, token, getCookieOptions('/', MEET_PARTICIPANT_TOKEN_EXPIRATION)); + res.cookie( + INTERNAL_CONFIG.PARTICIPANT_TOKEN_COOKIE_NAME, + token, + getCookieOptions('/', MEET_PARTICIPANT_TOKEN_EXPIRATION) + ); return res.status(200).json({ token }); } catch (error) { logger.error(`Error generating participant token for room: ${roomId}`); @@ -49,15 +53,19 @@ export const refreshParticipantToken = async (req: Request, res: Response) => { } } - const tokenOptions: TokenOptions = req.body; - const { roomId } = tokenOptions; + const participantOptions: ParticipantOptions = req.body; + const { roomId } = participantOptions; const participantService = container.get(ParticipantService); try { logger.verbose(`Refreshing participant token for room ${roomId}`); - const token = await participantService.generateOrRefreshParticipantToken(tokenOptions, true); + const token = await participantService.generateOrRefreshParticipantToken(participantOptions, true); - res.cookie(INTERNAL_CONFIG.PARTICIPANT_TOKEN_COOKIE_NAME, token, getCookieOptions('/', MEET_PARTICIPANT_TOKEN_EXPIRATION)); + res.cookie( + INTERNAL_CONFIG.PARTICIPANT_TOKEN_COOKIE_NAME, + token, + getCookieOptions('/', MEET_PARTICIPANT_TOKEN_EXPIRATION) + ); logger.verbose(`Participant token refreshed for room ${roomId}`); return res.status(200).json({ token }); } catch (error) { diff --git a/backend/src/middlewares/participant.middleware.ts b/backend/src/middlewares/participant.middleware.ts index 46eb696..cabbf60 100644 --- a/backend/src/middlewares/participant.middleware.ts +++ b/backend/src/middlewares/participant.middleware.ts @@ -1,5 +1,5 @@ import { Request, Response, NextFunction } from 'express'; -import { AuthMode, ParticipantRole, UserRole, TokenOptions } from '@typings-ce'; +import { AuthMode, ParticipantRole, UserRole, ParticipantOptions } from '@typings-ce'; import { container } from '../config/dependency-injector.config.js'; import { MeetStorageService, LoggerService, RoomService } from '../services/index.js'; import { allowAnonymous, tokenAndRoleValidator, withAuth } from './auth.middleware.js'; @@ -19,7 +19,7 @@ export const configureTokenAuth = async (req: Request, res: Response, next: Next let role: ParticipantRole; try { - const { roomId, secret } = req.body as TokenOptions; + const { roomId, secret } = req.body as ParticipantOptions; role = await roomService.getRoomRoleBySecret(roomId, secret); } catch (error) { logger.error('Error getting room secret role', error); diff --git a/backend/src/middlewares/request-validators/participant-validator.middleware.ts b/backend/src/middlewares/request-validators/participant-validator.middleware.ts index 502c7b2..5aa201d 100644 --- a/backend/src/middlewares/request-validators/participant-validator.middleware.ts +++ b/backend/src/middlewares/request-validators/participant-validator.middleware.ts @@ -1,9 +1,9 @@ -import { TokenOptions } from '@typings-ce'; +import { ParticipantOptions } from '@typings-ce'; import { Request, Response, NextFunction } from 'express'; import { z } from 'zod'; import { nonEmptySanitizedRoomId } from './room-validator.middleware.js'; -const ParticipantTokenRequestSchema: z.ZodType = z.object({ +const ParticipantTokenRequestSchema: z.ZodType = z.object({ roomId: nonEmptySanitizedRoomId('roomId'), participantName: z.string().nonempty('Participant name is required'), secret: z.string().nonempty('Secret is required') diff --git a/backend/src/services/livekit.service.ts b/backend/src/services/livekit.service.ts index da75c21..eae05c4 100644 --- a/backend/src/services/livekit.service.ts +++ b/backend/src/services/livekit.service.ts @@ -1,6 +1,5 @@ import { inject, injectable } from '../config/dependency-injector.config.js'; import { - AccessToken, CreateOptions, DataPacket_Kind, EgressClient, @@ -15,13 +14,7 @@ import { SendDataOptions, StreamOutput } from 'livekit-server-sdk'; -import { - LIVEKIT_API_KEY, - LIVEKIT_API_SECRET, - LIVEKIT_URL, - LIVEKIT_URL_PRIVATE, - MEET_PARTICIPANT_TOKEN_EXPIRATION -} from '../environment.js'; +import { LIVEKIT_API_KEY, LIVEKIT_API_SECRET, LIVEKIT_URL_PRIVATE } from '../environment.js'; import { LoggerService } from './logger.service.js'; import { errorLivekitIsNotAvailable, @@ -30,7 +23,6 @@ import { internalError, OpenViduMeetError } from '../models/error.model.js'; -import { ParticipantPermissions, ParticipantRole, TokenOptions } from '@typings-ce'; import { RecordingHelper } from '../helpers/recording.helper.js'; @injectable() diff --git a/backend/src/services/participant.service.ts b/backend/src/services/participant.service.ts index aad27cf..d405c48 100644 --- a/backend/src/services/participant.service.ts +++ b/backend/src/services/participant.service.ts @@ -1,5 +1,5 @@ import { injectable, inject } from 'inversify'; -import { ParticipantPermissions, ParticipantRole, TokenOptions } from '@typings-ce'; +import { ParticipantPermissions, ParticipantRole, ParticipantOptions } from '@typings-ce'; import { ParticipantInfo } from 'livekit-server-sdk'; import { errorParticipantAlreadyExists, errorParticipantNotFound } from '../models/index.js'; import { LiveKitService, LoggerService, RoomService, TokenService } from './index.js'; @@ -13,8 +13,8 @@ export class ParticipantService { @inject(TokenService) protected tokenService: TokenService ) {} - async generateOrRefreshParticipantToken(options: TokenOptions, refresh = false): Promise { - const { roomId, participantName, secret } = options; + async generateOrRefreshParticipantToken(participantOptions: ParticipantOptions, refresh = false): Promise { + const { roomId, participantName, secret } = participantOptions; // Check if participant with same participantName exists in the room const participantExists = await this.participantExists(roomId, participantName); @@ -30,14 +30,17 @@ export class ParticipantService { } const role = await this.roomService.getRoomRoleBySecret(roomId, secret); - const token = await this.generateParticipantToken(role, options); + const token = await this.generateParticipantToken(role, participantOptions); this.logger.verbose(`Participant token generated for room ${roomId}`); return token; } - protected async generateParticipantToken(role: ParticipantRole, options: TokenOptions): Promise { - const permissions = this.getParticipantPermissions(role, options.roomId); - return this.tokenService.generateParticipantToken(options, permissions, role); + protected async generateParticipantToken( + role: ParticipantRole, + participantOptions: ParticipantOptions + ): Promise { + const permissions = this.getParticipantPermissions(role, participantOptions.roomId); + return this.tokenService.generateParticipantToken(participantOptions, permissions, role); } async getParticipant(roomId: string, participantName: string): Promise { diff --git a/backend/src/services/s3.service.ts b/backend/src/services/s3.service.ts index aacb6ba..c1fed99 100644 --- a/backend/src/services/s3.service.ts +++ b/backend/src/services/s3.service.ts @@ -1,7 +1,4 @@ import { - _Object, - DeleteObjectCommand, - DeleteObjectCommandOutput, DeleteObjectsCommand, DeleteObjectsCommandOutput, GetObjectCommand, diff --git a/backend/src/services/token.service.ts b/backend/src/services/token.service.ts index 956de57..8ca7d4b 100644 --- a/backend/src/services/token.service.ts +++ b/backend/src/services/token.service.ts @@ -8,7 +8,7 @@ import { } from '../environment.js'; import { inject, injectable } from '../config/dependency-injector.config.js'; import { AccessToken, AccessTokenOptions, ClaimGrants, TokenVerifier, VideoGrant } from 'livekit-server-sdk'; -import { ParticipantPermissions, ParticipantRole, TokenOptions, User } from '@typings-ce'; +import { ParticipantPermissions, ParticipantRole, ParticipantOptions, User } from '@typings-ce'; import { LoggerService } from './index.js'; @injectable() @@ -38,7 +38,7 @@ export class TokenService { } async generateParticipantToken( - participantOptions: TokenOptions, + participantOptions: ParticipantOptions, permissions: ParticipantPermissions, role: ParticipantRole ): Promise { diff --git a/frontend/projects/shared-meet-components/src/lib/services/http/http.service.ts b/frontend/projects/shared-meet-components/src/lib/services/http/http.service.ts index 948fd32..a4e0c58 100644 --- a/frontend/projects/shared-meet-components/src/lib/services/http/http.service.ts +++ b/frontend/projects/shared-meet-components/src/lib/services/http/http.service.ts @@ -6,7 +6,7 @@ import { MeetRoomRoleAndPermissions, MeetRoomPreferences, SecurityPreferencesDTO, - TokenOptions, + ParticipantOptions, User } from '@lib/typings/ce'; import { RecordingInfo } from 'openvidu-components-angular'; @@ -51,12 +51,12 @@ export class HttpService { return this.deleteRequest(`${this.INTERNAL_API_PATH_PREFIX}/meetings/${roomId}`); } - generateParticipantToken(tokenOptions: TokenOptions): Promise<{ token: string }> { - return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/participants/token`, tokenOptions); + generateParticipantToken(participantOptions: ParticipantOptions): Promise<{ token: string }> { + return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/participants/token`, participantOptions); } - refreshParticipantToken(tokenOptions: TokenOptions): Promise<{ token: string }> { - return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/participants/token/refresh`, tokenOptions); + refreshParticipantToken(participantOptions: ParticipantOptions): Promise<{ token: string }> { + return this.postRequest(`${this.INTERNAL_API_PATH_PREFIX}/participants/token/refresh`, participantOptions); } /**