frontend: remove ParticipantTokenInfo and streamline participant token handling

This commit is contained in:
juancarmore 2025-08-13 18:58:26 +02:00
parent 25f3d9f887
commit f5d874d06d
5 changed files with 25 additions and 44 deletions

View File

@ -3,5 +3,4 @@ export * from './custom-participant.model';
export * from './navigation.model'; export * from './navigation.model';
export * from './notification.model'; export * from './notification.model';
export * from './sidenav.model'; export * from './sidenav.model';
export * from './token.model';
export * from './wizard.model'; export * from './wizard.model';

View File

@ -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
}

View File

@ -94,7 +94,6 @@ export class MeetingComponent implements OnInit {
roomSecret = ''; roomSecret = '';
participantName = ''; participantName = '';
participantToken = ''; participantToken = '';
participantRole: ParticipantRole = ParticipantRole.SPEAKER;
localParticipant?: CustomParticipantModel; localParticipant?: CustomParticipantModel;
remoteParticipants: CustomParticipantModel[] = []; remoteParticipants: CustomParticipantModel[] = [];
@ -283,13 +282,11 @@ export class MeetingComponent implements OnInit {
*/ */
private async generateParticipantToken() { private async generateParticipantToken() {
try { try {
const { token, role } = await this.participantTokenService.generateToken({ this.participantToken = await this.participantTokenService.generateToken({
roomId: this.roomId, roomId: this.roomId,
secret: this.roomSecret, secret: this.roomSecret,
participantName: this.participantName participantName: this.participantName
}); });
this.participantToken = token;
this.participantRole = role;
} catch (error: any) { } catch (error: any) {
console.error('Error generating participant token:', error); console.error('Error generating participant token:', error);
switch (error.status) { switch (error.status) {

View File

@ -9,8 +9,8 @@ export interface ApplicationFeatures {
// Media Features // Media Features
videoEnabled: boolean; videoEnabled: boolean;
audioEnabled: boolean; audioEnabled: boolean;
showMicrophone: boolean;
showCamera: boolean; showCamera: boolean;
showMicrophone: boolean;
showScreenShare: boolean; showScreenShare: boolean;
// UI Features // UI Features
@ -32,8 +32,8 @@ export interface ApplicationFeatures {
const DEFAULT_FEATURES: ApplicationFeatures = { const DEFAULT_FEATURES: ApplicationFeatures = {
videoEnabled: true, videoEnabled: true,
audioEnabled: true, audioEnabled: true,
showMicrophone: true,
showCamera: true, showCamera: true,
showMicrophone: true,
showScreenShare: true, showScreenShare: true,
showRecordings: true, showRecordings: true,
@ -139,8 +139,8 @@ export class FeatureConfigurationService {
const canPublishSources = participantPerms.livekit.canPublishSources ?? []; const canPublishSources = participantPerms.livekit.canPublishSources ?? [];
features.videoEnabled = canPublish || canPublishSources.includes(TrackSource.CAMERA); features.videoEnabled = canPublish || canPublishSources.includes(TrackSource.CAMERA);
features.audioEnabled = canPublish || canPublishSources.includes(TrackSource.MICROPHONE); features.audioEnabled = canPublish || canPublishSources.includes(TrackSource.MICROPHONE);
features.showMicrophone = features.audioEnabled;
features.showCamera = features.videoEnabled; features.showCamera = features.videoEnabled;
features.showMicrophone = features.audioEnabled;
features.showScreenShare = canPublish || canPublishSources.includes(TrackSource.SCREEN_SHARE); features.showScreenShare = canPublish || canPublishSources.includes(TrackSource.SCREEN_SHARE);
} }

View File

@ -1,5 +1,4 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { ParticipantTokenInfo } from '@lib/models';
import { FeatureConfigurationService, HttpService } from '@lib/services'; import { FeatureConfigurationService, HttpService } from '@lib/services';
import { MeetTokenMetadata, ParticipantOptions, ParticipantPermissions, ParticipantRole } from '@lib/typings/ce'; import { MeetTokenMetadata, ParticipantOptions, ParticipantPermissions, ParticipantRole } from '@lib/typings/ce';
import { getValidDecodedToken } from '@lib/utils'; import { getValidDecodedToken } from '@lib/utils';
@ -12,8 +11,8 @@ export class ParticipantService {
protected readonly PARTICIPANTS_API = `${HttpService.INTERNAL_API_PATH_PREFIX}/participants`; protected readonly PARTICIPANTS_API = `${HttpService.INTERNAL_API_PATH_PREFIX}/participants`;
protected participantName?: string; protected participantName?: string;
protected participantRole: ParticipantRole = ParticipantRole.SPEAKER; protected role: ParticipantRole = ParticipantRole.SPEAKER;
protected currentTokenInfo?: ParticipantTokenInfo; protected permissions?: ParticipantPermissions;
protected log; protected log;
@ -37,28 +36,28 @@ export class ParticipantService {
* Generates a participant token and extracts role/permissions * Generates a participant token and extracts role/permissions
* *
* @param participantOptions - The options for the participant, including room ID, participant name, and secret * @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<ParticipantTokenInfo> { async generateToken(participantOptions: ParticipantOptions): Promise<string> {
const path = `${this.PARTICIPANTS_API}/token`; const path = `${this.PARTICIPANTS_API}/token`;
const { token } = await this.httpService.postRequest<{ token: string }>(path, participantOptions); const { token } = await this.httpService.postRequest<{ token: string }>(path, participantOptions);
this.updateParticipantTokenInfo(token); this.updateParticipantTokenInfo(token);
return this.currentTokenInfo!; return token;
} }
/** /**
* Refreshes the participant token using the provided options. * Refreshes the participant token using the provided options.
* *
* @param participantOptions - The options for the participant, including room ID, participant name, and secret * @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<ParticipantTokenInfo> { async refreshParticipantToken(participantOptions: ParticipantOptions): Promise<string> {
const path = `${this.PARTICIPANTS_API}/token/refresh`; const path = `${this.PARTICIPANTS_API}/token/refresh`;
const { token } = await this.httpService.postRequest<{ token: string }>(path, participantOptions); const { token } = await this.httpService.postRequest<{ token: string }>(path, participantOptions);
this.updateParticipantTokenInfo(token); this.updateParticipantTokenInfo(token);
return this.currentTokenInfo!; return token;
} }
/** /**
@ -71,38 +70,31 @@ export class ParticipantService {
try { try {
const decodedToken = getValidDecodedToken(token); const decodedToken = getValidDecodedToken(token);
const metadata = decodedToken.metadata as MeetTokenMetadata; const metadata = decodedToken.metadata as MeetTokenMetadata;
const role = metadata.selectedRole;
const permissions = metadata.roles.find((r) => r.role === role)!.permissions; this.role = metadata.selectedRole;
this.currentTokenInfo = { const openviduPermissions = metadata.roles.find((r) => r.role === this.role)!.permissions;
token: token, this.permissions = {
role: role, livekit: decodedToken.video,
permissions: { openvidu: openviduPermissions
livekit: decodedToken.video,
openvidu: permissions
}
}; };
this.participantRole = this.currentTokenInfo.role; console.warn('PARTICIPANT PERMISSIONS', this.permissions);
// Update feature configuration // Update feature configuration
this.featureConfService.setParticipantRole(this.currentTokenInfo.role); this.featureConfService.setParticipantRole(this.role);
this.featureConfService.setParticipantPermissions(this.currentTokenInfo.permissions); this.featureConfService.setParticipantPermissions(this.permissions);
} catch (error) { } catch (error) {
this.log.e('Error setting participant token and associated data', error); this.log.e('Error setting participant token and associated data', error);
throw new Error('Error setting participant token'); throw new Error('Error setting participant token');
} }
} }
getParticipantToken(): string | undefined {
return this.currentTokenInfo?.token;
}
setParticipantRole(participantRole: ParticipantRole): void { setParticipantRole(participantRole: ParticipantRole): void {
this.participantRole = participantRole; this.role = participantRole;
this.featureConfService.setParticipantRole(this.participantRole); this.featureConfService.setParticipantRole(this.role);
} }
getParticipantRole(): ParticipantRole { getParticipantRole(): ParticipantRole {
return this.participantRole; return this.role;
} }
isModeratorParticipant(): boolean { isModeratorParticipant(): boolean {
@ -110,7 +102,7 @@ export class ParticipantService {
} }
getParticipantPermissions(): ParticipantPermissions | undefined { getParticipantPermissions(): ParticipantPermissions | undefined {
return this.currentTokenInfo?.permissions; return this.permissions;
} }
getParticipantRoleHeader(): Record<string, string> { getParticipantRoleHeader(): Record<string, string> {