diff --git a/frontend/projects/shared-meet-components/src/lib/models/context.model.ts b/frontend/projects/shared-meet-components/src/lib/models/context.model.ts index fcc8b8a..8e1e15d 100644 --- a/frontend/projects/shared-meet-components/src/lib/models/context.model.ts +++ b/frontend/projects/shared-meet-components/src/lib/models/context.model.ts @@ -1,4 +1,8 @@ -import { OpenViduMeetPermissions, ParticipantRole } from 'projects/shared-meet-components/src/public-api'; +import { + GlobalPreferences, + OpenViduMeetPermissions, + ParticipantRole +} from 'projects/shared-meet-components/src/public-api'; export interface ContextData { roomName: string; @@ -9,6 +13,7 @@ export interface ContextData { participantPermissions: OpenViduMeetPermissions; mode: ApplicationMode; edition: Edition; + globalPreferences?: GlobalPreferences; leaveRedirectUrl: string; parentDomain: string; version: string; diff --git a/frontend/projects/shared-meet-components/src/lib/services/context/context.service.ts b/frontend/projects/shared-meet-components/src/lib/services/context/context.service.ts index d6c3f83..6d23eaf 100644 --- a/frontend/projects/shared-meet-components/src/lib/services/context/context.service.ts +++ b/frontend/projects/shared-meet-components/src/lib/services/context/context.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { jwtDecode } from 'jwt-decode'; import { ApplicationMode, ContextData, Edition } from '../../models/context.model'; import { LoggerService } from 'openvidu-components-angular'; -import { ParticipantRole } from 'projects/shared-meet-components/src/public-api'; +import { AuthMode, HttpService, ParticipantRole } from 'projects/shared-meet-components/src/public-api'; @Injectable({ providedIn: 'root' @@ -25,6 +25,7 @@ export class ContextService { }, mode: ApplicationMode.STANDALONE, edition: Edition.CE, + globalPreferences: undefined, leaveRedirectUrl: '', parentDomain: '', version: '', @@ -37,7 +38,10 @@ export class ContextService { /** * Initializes a new instance of the ContextService class. */ - constructor(private loggerService: LoggerService) { + constructor( + private loggerService: LoggerService, + private httpService: HttpService + ) { this.log = this.loggerService.get('OpenVidu Meet - ContextService'); } @@ -162,6 +166,21 @@ export class ContextService { return this.context.participantPermissions.canChat; } + async canUsersCreateRooms(): Promise { + await this.getGlobalPreferences(); + return this.context.globalPreferences!.securityPreferences.roomCreationPolicy.allowRoomCreation; + } + + async requireAuthenticationForRoomCreation(): Promise { + await this.getGlobalPreferences(); + return this.context.globalPreferences!.securityPreferences.roomCreationPolicy.requireAuthentication; + } + + async getAuthModeToEnterRoom(): Promise { + await this.getGlobalPreferences(); + return this.context.globalPreferences!.securityPreferences.authentication.authMode; + } + private getValidDecodedToken(token: string) { this.checkIsJWTValid(token); const decodedToken: any = jwtDecode(token); @@ -184,4 +203,16 @@ export class ContextService { throw new Error('Invalid token. Token must be a valid JWT'); } } + + private async getGlobalPreferences() { + if (!this.context.globalPreferences) { + try { + // TODO: Retrieve only publicly available global preferences + this.context.globalPreferences = await this.httpService.getGlobalPreferences(); + } catch (error) { + this.log.e('Error getting global preferences', error); + throw new Error('Error getting global preferences'); + } + } + } }