Refactors room parameter extraction
Streamlines parameter handling by centralizing logic. The `RoomService` is no longer responsible for setting the `roomId` and `roomSecret`. Instead, the `MeetingContextService` handles this and persists the room secret in session storage.
This commit is contained in:
parent
1663b008ed
commit
07b22a0d29
@ -2,11 +2,16 @@ import { inject } from '@angular/core';
|
||||
import { ActivatedRouteSnapshot, CanActivateFn } from '@angular/router';
|
||||
import { WebComponentProperty } from '@openvidu-meet/typings';
|
||||
import { ErrorReason } from '../models';
|
||||
import { AppDataService, MeetingContextService, NavigationService, RoomMemberService, RoomService, SessionStorageService } from '../services';
|
||||
import {
|
||||
AppDataService,
|
||||
MeetingContextService,
|
||||
NavigationService,
|
||||
RoomMemberService,
|
||||
SessionStorageService
|
||||
} from '../services';
|
||||
|
||||
export const extractRoomQueryParamsGuard: CanActivateFn = (route: ActivatedRouteSnapshot) => {
|
||||
const navigationService = inject(NavigationService);
|
||||
const roomService = inject(RoomService);
|
||||
const meetingContextService = inject(MeetingContextService);
|
||||
const roomMemberService = inject(RoomMemberService);
|
||||
const sessionStorageService = inject(SessionStorageService);
|
||||
@ -30,8 +35,8 @@ export const extractRoomQueryParamsGuard: CanActivateFn = (route: ActivatedRoute
|
||||
return navigationService.redirectToErrorPage(ErrorReason.MISSING_ROOM_SECRET);
|
||||
}
|
||||
|
||||
roomService.setRoomId(roomId);
|
||||
roomService.setRoomSecret(secret);
|
||||
meetingContextService.setRoomId(roomId);
|
||||
meetingContextService.setRoomSecret(secret, true);
|
||||
|
||||
if (e2eeKey) {
|
||||
meetingContextService.setE2eeKey(e2eeKey);
|
||||
@ -51,7 +56,7 @@ export const extractRoomQueryParamsGuard: CanActivateFn = (route: ActivatedRoute
|
||||
|
||||
export const extractRecordingQueryParamsGuard: CanActivateFn = (route: ActivatedRouteSnapshot) => {
|
||||
const navigationService = inject(NavigationService);
|
||||
const roomService = inject(RoomService);
|
||||
const meetingContextService = inject(MeetingContextService);
|
||||
const sessionStorageService = inject(SessionStorageService);
|
||||
|
||||
const { roomId, secret: querySecret } = extractParams(route);
|
||||
@ -62,8 +67,8 @@ export const extractRecordingQueryParamsGuard: CanActivateFn = (route: Activated
|
||||
return navigationService.redirectToErrorPage(ErrorReason.MISSING_ROOM_SECRET);
|
||||
}
|
||||
|
||||
roomService.setRoomId(roomId);
|
||||
roomService.setRoomSecret(secret);
|
||||
meetingContextService.setRoomId(roomId);
|
||||
meetingContextService.setRoomSecret(secret, true);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import { Injectable, signal, computed, inject, DestroyRef } from '@angular/core';
|
||||
import { MeetRoom } from 'node_modules/@openvidu-meet/typings/dist/room';
|
||||
import { Room, ParticipantService, ViewportService } from 'openvidu-components-angular';
|
||||
import { CustomParticipantModel } from '../../models';
|
||||
import { computed, DestroyRef, inject, Injectable, signal } from '@angular/core';
|
||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||
import { MeetRoom } from 'node_modules/@openvidu-meet/typings/dist/room';
|
||||
import { ParticipantService, Room, ViewportService } from 'openvidu-components-angular';
|
||||
import { CustomParticipantModel } from '../../models';
|
||||
import { FeatureConfigurationService } from '../feature-configuration.service';
|
||||
import { SessionStorageService } from '../session-storage.service';
|
||||
|
||||
/**
|
||||
* Central service for managing meeting context and state during the MEETING PHASE.
|
||||
@ -17,6 +18,7 @@ export class MeetingContextService {
|
||||
private readonly ovParticipantService = inject(ParticipantService);
|
||||
private readonly featureConfigService = inject(FeatureConfigurationService);
|
||||
private readonly viewportService = inject(ViewportService);
|
||||
private readonly sessionStorageService = inject(SessionStorageService);
|
||||
private readonly destroyRef = inject(DestroyRef);
|
||||
private isSubscribed = false;
|
||||
private readonly _meetRoom = signal<MeetRoom | undefined>(undefined);
|
||||
@ -188,8 +190,13 @@ export class MeetingContextService {
|
||||
/**
|
||||
* Sets the room secret in context
|
||||
* @param secret The room secret
|
||||
* @param updateStorage Whether to persist in SessionStorage (default: false)
|
||||
*/
|
||||
setRoomSecret(secret: string): void {
|
||||
setRoomSecret(secret: string, updateStorage = false): void {
|
||||
if (updateStorage) {
|
||||
this.sessionStorageService.setRoomSecret(secret);
|
||||
}
|
||||
|
||||
this._roomSecret.set(secret);
|
||||
}
|
||||
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { inject, Injectable } from '@angular/core';
|
||||
import { Injectable } from '@angular/core';
|
||||
import {
|
||||
MeetRoom,
|
||||
MeetRoomConfig,
|
||||
@ -11,7 +11,7 @@ import {
|
||||
MeetRoomStatus
|
||||
} from '@openvidu-meet/typings';
|
||||
import { LoggerService } from 'openvidu-components-angular';
|
||||
import { FeatureConfigurationService, HttpService, MeetingContextService, SessionStorageService } from '../services';
|
||||
import { FeatureConfigurationService, HttpService } from '../services';
|
||||
|
||||
/**
|
||||
* RoomService - Persistence Layer for Room Data
|
||||
@ -30,65 +30,15 @@ import { FeatureConfigurationService, HttpService, MeetingContextService, Sessio
|
||||
export class RoomService {
|
||||
protected readonly ROOMS_API = `${HttpService.API_PATH_PREFIX}/rooms`;
|
||||
protected readonly INTERNAL_ROOMS_API = `${HttpService.INTERNAL_API_PATH_PREFIX}/rooms`;
|
||||
|
||||
protected roomId: string = '';
|
||||
protected roomSecret: string = '';
|
||||
protected e2eeKey: string = '';
|
||||
protected log;
|
||||
protected meetingContext = inject(MeetingContextService);
|
||||
|
||||
constructor(
|
||||
protected loggerService: LoggerService,
|
||||
protected httpService: HttpService,
|
||||
protected featureConfService: FeatureConfigurationService,
|
||||
protected sessionStorageService: SessionStorageService
|
||||
protected featureConfService: FeatureConfigurationService
|
||||
) {
|
||||
this.log = this.loggerService.get('OpenVidu Meet - RoomService');
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the room ID in memory and automatically syncs to MeetingContextService.
|
||||
* This ensures persistence and reactivity across the application.
|
||||
*
|
||||
* @param roomId - The room identifier to store
|
||||
*/
|
||||
setRoomId(roomId: string) {
|
||||
this.roomId = roomId;
|
||||
// Auto-sync to MeetingContextService (Single Source of Truth for runtime)
|
||||
this.meetingContext.setRoomId(roomId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads persisted room state from internal storage to MeetingContextService.
|
||||
* Should be called during application initialization to restore state after page reload.
|
||||
*
|
||||
* This method transfers data from RoomService → MeetingContextService,
|
||||
* making it available as reactive signals throughout the application.
|
||||
*/
|
||||
loadPersistedStateToContext(): void {
|
||||
if (this.roomId) {
|
||||
this.meetingContext.setRoomId(this.roomId);
|
||||
}
|
||||
if (this.roomSecret) {
|
||||
this.meetingContext.setRoomSecret(this.roomSecret);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the room secret in memory, session storage, and automatically syncs to MeetingContextService.
|
||||
*
|
||||
* @param secret - The room secret to store
|
||||
* @param updateStorage - Whether to persist in SessionStorage (default: true)
|
||||
*/
|
||||
setRoomSecret(secret: string, updateStorage = true) {
|
||||
this.roomSecret = secret;
|
||||
if (updateStorage) {
|
||||
this.sessionStorageService.setRoomSecret(secret);
|
||||
}
|
||||
// Auto-sync to MeetingContextService (Single Source of Truth for runtime)
|
||||
this.meetingContext.setRoomSecret(secret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new room with the specified options.
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user