diff --git a/frontend/projects/shared-meet-components/src/lib/guards/extract-query-params.guard.ts b/frontend/projects/shared-meet-components/src/lib/guards/extract-query-params.guard.ts index 8e30c32..a931c05 100644 --- a/frontend/projects/shared-meet-components/src/lib/guards/extract-query-params.guard.ts +++ b/frontend/projects/shared-meet-components/src/lib/guards/extract-query-params.guard.ts @@ -9,6 +9,10 @@ export const extractRoomQueryParamsGuard: CanActivateFn = (route: ActivatedRoute const participantService = inject(ParticipantTokenService); const { roomId, participantName, secret, leaveRedirectUrl, showOnlyRecordings } = extractParams(route); + if (isValidUrl(leaveRedirectUrl)) { + navigationService.setLeaveRedirectUrl(leaveRedirectUrl); + } + if (!secret) { // If no secret is provided, redirect to the error page return navigationService.redirectToErrorPage(ErrorReason.MISSING_ROOM_SECRET); @@ -21,10 +25,6 @@ export const extractRoomQueryParamsGuard: CanActivateFn = (route: ActivatedRoute participantService.setParticipantName(participantName); } - if (isValidUrl(leaveRedirectUrl)) { - navigationService.setLeaveRedirectUrl(leaveRedirectUrl); - } - if (showOnlyRecordings === 'true') { // Redirect to the room recordings page return navigationService.createRedirectionTo(`room/${roomId}/recordings`, { secret }); diff --git a/frontend/projects/shared-meet-components/src/lib/services/navigation.service.ts b/frontend/projects/shared-meet-components/src/lib/services/navigation.service.ts index 6581133..d745933 100644 --- a/frontend/projects/shared-meet-components/src/lib/services/navigation.service.ts +++ b/frontend/projects/shared-meet-components/src/lib/services/navigation.service.ts @@ -2,35 +2,60 @@ import { Location } from '@angular/common'; import { Injectable } from '@angular/core'; import { Params, Router, UrlTree } from '@angular/router'; import { ErrorReason } from '@lib/models'; +import { SessionStorageService } from '@lib/services'; @Injectable({ providedIn: 'root' }) export class NavigationService { - protected leaveRedirectUrl: string = ''; + protected leaveRedirectUrl?: string; constructor( private router: Router, - private location: Location + private location: Location, + private sessionStorageService: SessionStorageService ) {} setLeaveRedirectUrl(leaveRedirectUrl: string): void { this.leaveRedirectUrl = leaveRedirectUrl; + this.sessionStorageService.setRedirectUrl(leaveRedirectUrl); } - getLeaveRedirectURL(): string { + getLeaveRedirectURL(): string | undefined { + const storedRedirectUrl = this.sessionStorageService.getRedirectUrl(); + if (!this.leaveRedirectUrl && storedRedirectUrl) { + this.leaveRedirectUrl = storedRedirectUrl; + } + return this.leaveRedirectUrl; } + /** + * Navigates to a specific route + * + * @param route - The route to navigate to + * @param queryParams - Optional query parameters to include in the navigation + * @param replaceUrl - If true, replaces the current URL in the browser history + */ + async navigateTo(route: string, queryParams?: Params, replaceUrl: boolean = false): Promise { + try { + await this.router.navigate([route], { + queryParams, + replaceUrl + }); + } catch (error) { + console.error('Error navigating to route:', error); + } + } + /** * Redirects to internal or external URLs * * @param url - The URL to redirect to - * @param isExternal - If true, treats the URL as an external link; otherwise, - * treats it as an internal route */ - async redirectTo(url: string, isExternal = false): Promise { - if (isExternal) { + async redirectTo(url: string): Promise { + const isExternalURL = /^https?:\/\//.test(url); + if (isExternalURL) { console.log('Redirecting to external URL:', url); window.location.href = url; } else { @@ -45,6 +70,17 @@ export class NavigationService { } } + /** + * Creates a URL tree for redirecting to a specific route + * + * @param route - The route to redirect to + * @param queryParams - Optional query parameters to include in the URL + * @returns A UrlTree representing the redirection + */ + createRedirectionTo(route: string, queryParams?: Params): UrlTree { + return this.router.createUrlTree([route], { queryParams }); + } + /** * Creates a UrlTree for the error page with specific reason and optionally navigates to it. * @@ -88,35 +124,6 @@ export class NavigationService { return urlTree; } - /** - * Creates a URL tree for redirecting to a specific route - * - * @param route - The route to redirect to - * @param queryParams - Optional query parameters to include in the URL - * @returns A UrlTree representing the redirection - */ - createRedirectionTo(route: string, queryParams?: Params): UrlTree { - return this.router.createUrlTree([route], { queryParams }); - } - - /** - * Navigates to a specific route - * - * @param route - The route to navigate to - * @param queryParams - Optional query parameters to include in the navigation - * @param replaceUrl - If true, replaces the current URL in the browser history - */ - async navigateTo(route: string, queryParams?: Params, replaceUrl: boolean = false): Promise { - try { - await this.router.navigate([route], { - queryParams, - replaceUrl - }); - } catch (error) { - console.error('Error navigating to route:', error); - } - } - /** * Checks if the current URL contains a specific route * diff --git a/frontend/projects/shared-meet-components/src/lib/services/session-storage.service.ts b/frontend/projects/shared-meet-components/src/lib/services/session-storage.service.ts index 90ca30f..ad24f0d 100644 --- a/frontend/projects/shared-meet-components/src/lib/services/session-storage.service.ts +++ b/frontend/projects/shared-meet-components/src/lib/services/session-storage.service.ts @@ -39,6 +39,24 @@ export class SessionStorageService { this.remove(`moderator_secret_${roomId}`); } + /** + * Stores a redirect URL to be used after leaving OpenVidu Meet. + * + * @param redirectUrl The URL to redirect to. + */ + public setRedirectUrl(redirectUrl: string): void { + this.set('redirect_url', redirectUrl); + } + + /** + * Retrieves the redirect URL stored in sessionStorage. + * + * @returns The redirect URL or null if not found. + */ + public getRedirectUrl(): string | null { + return this.get('redirect_url') ?? null; + } + /** * Clears all data stored in sessionStorage. */