From f5d874d06dc3c869e10096bbef038690308b38b3 Mon Sep 17 00:00:00 2001 From: juancarmore Date: Wed, 13 Aug 2025 18:58:26 +0200 Subject: [PATCH] frontend: remove ParticipantTokenInfo and streamline participant token handling --- .../src/lib/models/index.ts | 1 - .../src/lib/models/token.model.ts | 7 --- .../lib/pages/meeting/meeting.component.ts | 5 +- .../services/feature-configuration.service.ts | 6 +-- .../src/lib/services/participant.service.ts | 50 ++++++++----------- 5 files changed, 25 insertions(+), 44 deletions(-) delete mode 100644 frontend/projects/shared-meet-components/src/lib/models/token.model.ts diff --git a/frontend/projects/shared-meet-components/src/lib/models/index.ts b/frontend/projects/shared-meet-components/src/lib/models/index.ts index aca8052..0a08fe8 100644 --- a/frontend/projects/shared-meet-components/src/lib/models/index.ts +++ b/frontend/projects/shared-meet-components/src/lib/models/index.ts @@ -3,5 +3,4 @@ export * from './custom-participant.model'; export * from './navigation.model'; export * from './notification.model'; export * from './sidenav.model'; -export * from './token.model'; export * from './wizard.model'; diff --git a/frontend/projects/shared-meet-components/src/lib/models/token.model.ts b/frontend/projects/shared-meet-components/src/lib/models/token.model.ts deleted file mode 100644 index aae2c6d..0000000 --- a/frontend/projects/shared-meet-components/src/lib/models/token.model.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { ParticipantPermissions, ParticipantRole } from '../typings/ce'; - -export interface ParticipantTokenInfo { - token: string; // The generated participant token - role: ParticipantRole; // Role of the participant (e.g., 'moderator', 'speaker') - permissions: ParticipantPermissions; // List of permissions granted to the participant -} diff --git a/frontend/projects/shared-meet-components/src/lib/pages/meeting/meeting.component.ts b/frontend/projects/shared-meet-components/src/lib/pages/meeting/meeting.component.ts index 04f2de4..8817e61 100644 --- a/frontend/projects/shared-meet-components/src/lib/pages/meeting/meeting.component.ts +++ b/frontend/projects/shared-meet-components/src/lib/pages/meeting/meeting.component.ts @@ -94,7 +94,6 @@ export class MeetingComponent implements OnInit { roomSecret = ''; participantName = ''; participantToken = ''; - participantRole: ParticipantRole = ParticipantRole.SPEAKER; localParticipant?: CustomParticipantModel; remoteParticipants: CustomParticipantModel[] = []; @@ -283,13 +282,11 @@ export class MeetingComponent implements OnInit { */ private async generateParticipantToken() { try { - const { token, role } = await this.participantTokenService.generateToken({ + this.participantToken = await this.participantTokenService.generateToken({ roomId: this.roomId, secret: this.roomSecret, participantName: this.participantName }); - this.participantToken = token; - this.participantRole = role; } catch (error: any) { console.error('Error generating participant token:', error); switch (error.status) { diff --git a/frontend/projects/shared-meet-components/src/lib/services/feature-configuration.service.ts b/frontend/projects/shared-meet-components/src/lib/services/feature-configuration.service.ts index c43dc5c..5215821 100644 --- a/frontend/projects/shared-meet-components/src/lib/services/feature-configuration.service.ts +++ b/frontend/projects/shared-meet-components/src/lib/services/feature-configuration.service.ts @@ -9,8 +9,8 @@ export interface ApplicationFeatures { // Media Features videoEnabled: boolean; audioEnabled: boolean; - showMicrophone: boolean; showCamera: boolean; + showMicrophone: boolean; showScreenShare: boolean; // UI Features @@ -32,8 +32,8 @@ export interface ApplicationFeatures { const DEFAULT_FEATURES: ApplicationFeatures = { videoEnabled: true, audioEnabled: true, - showMicrophone: true, showCamera: true, + showMicrophone: true, showScreenShare: true, showRecordings: true, @@ -139,8 +139,8 @@ export class FeatureConfigurationService { const canPublishSources = participantPerms.livekit.canPublishSources ?? []; features.videoEnabled = canPublish || canPublishSources.includes(TrackSource.CAMERA); features.audioEnabled = canPublish || canPublishSources.includes(TrackSource.MICROPHONE); - features.showMicrophone = features.audioEnabled; features.showCamera = features.videoEnabled; + features.showMicrophone = features.audioEnabled; features.showScreenShare = canPublish || canPublishSources.includes(TrackSource.SCREEN_SHARE); } diff --git a/frontend/projects/shared-meet-components/src/lib/services/participant.service.ts b/frontend/projects/shared-meet-components/src/lib/services/participant.service.ts index 5ad7813..c68f8cb 100644 --- a/frontend/projects/shared-meet-components/src/lib/services/participant.service.ts +++ b/frontend/projects/shared-meet-components/src/lib/services/participant.service.ts @@ -1,5 +1,4 @@ import { Injectable } from '@angular/core'; -import { ParticipantTokenInfo } from '@lib/models'; import { FeatureConfigurationService, HttpService } from '@lib/services'; import { MeetTokenMetadata, ParticipantOptions, ParticipantPermissions, ParticipantRole } from '@lib/typings/ce'; import { getValidDecodedToken } from '@lib/utils'; @@ -12,8 +11,8 @@ export class ParticipantService { protected readonly PARTICIPANTS_API = `${HttpService.INTERNAL_API_PATH_PREFIX}/participants`; protected participantName?: string; - protected participantRole: ParticipantRole = ParticipantRole.SPEAKER; - protected currentTokenInfo?: ParticipantTokenInfo; + protected role: ParticipantRole = ParticipantRole.SPEAKER; + protected permissions?: ParticipantPermissions; protected log; @@ -37,28 +36,28 @@ export class ParticipantService { * Generates a participant token and extracts role/permissions * * @param participantOptions - The options for the participant, including room ID, participant name, and secret - * @return A promise that resolves to an object containing the token, role, and permissions + * @return A promise that resolves to the participant token */ - async generateToken(participantOptions: ParticipantOptions): Promise { + async generateToken(participantOptions: ParticipantOptions): Promise { const path = `${this.PARTICIPANTS_API}/token`; const { token } = await this.httpService.postRequest<{ token: string }>(path, participantOptions); this.updateParticipantTokenInfo(token); - return this.currentTokenInfo!; + return token; } /** * Refreshes the participant token using the provided options. * * @param participantOptions - The options for the participant, including room ID, participant name, and secret - * @return A promise that resolves to an object containing the new token, role, and permissions + * @return A promise that resolves to the refreshed participant token */ - async refreshParticipantToken(participantOptions: ParticipantOptions): Promise { + async refreshParticipantToken(participantOptions: ParticipantOptions): Promise { const path = `${this.PARTICIPANTS_API}/token/refresh`; const { token } = await this.httpService.postRequest<{ token: string }>(path, participantOptions); this.updateParticipantTokenInfo(token); - return this.currentTokenInfo!; + return token; } /** @@ -71,38 +70,31 @@ export class ParticipantService { try { const decodedToken = getValidDecodedToken(token); const metadata = decodedToken.metadata as MeetTokenMetadata; - const role = metadata.selectedRole; - const permissions = metadata.roles.find((r) => r.role === role)!.permissions; - this.currentTokenInfo = { - token: token, - role: role, - permissions: { - livekit: decodedToken.video, - openvidu: permissions - } + + this.role = metadata.selectedRole; + const openviduPermissions = metadata.roles.find((r) => r.role === this.role)!.permissions; + this.permissions = { + livekit: decodedToken.video, + openvidu: openviduPermissions }; - this.participantRole = this.currentTokenInfo.role; + console.warn('PARTICIPANT PERMISSIONS', this.permissions); // Update feature configuration - this.featureConfService.setParticipantRole(this.currentTokenInfo.role); - this.featureConfService.setParticipantPermissions(this.currentTokenInfo.permissions); + this.featureConfService.setParticipantRole(this.role); + this.featureConfService.setParticipantPermissions(this.permissions); } catch (error) { this.log.e('Error setting participant token and associated data', error); throw new Error('Error setting participant token'); } } - getParticipantToken(): string | undefined { - return this.currentTokenInfo?.token; - } - setParticipantRole(participantRole: ParticipantRole): void { - this.participantRole = participantRole; - this.featureConfService.setParticipantRole(this.participantRole); + this.role = participantRole; + this.featureConfService.setParticipantRole(this.role); } getParticipantRole(): ParticipantRole { - return this.participantRole; + return this.role; } isModeratorParticipant(): boolean { @@ -110,7 +102,7 @@ export class ParticipantService { } getParticipantPermissions(): ParticipantPermissions | undefined { - return this.currentTokenInfo?.permissions; + return this.permissions; } getParticipantRoleHeader(): Record {