diff --git a/openvidu-call-front/src/app/app-routing.module.ts b/openvidu-call-front/src/app/app-routing.module.ts deleted file mode 100644 index ee80e843..00000000 --- a/openvidu-call-front/src/app/app-routing.module.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; -import { AdminDashboardComponent } from './components/admin-dashboard/admin-dashboard.component'; -import { VideoRoomComponent } from './components/video-room/video-room.component'; -import { HomeComponent } from './components/home/home.component'; -import { NavigationGuardService } from './services/guards/navigation-guard.service'; - -const routes: Routes = [ - { path: '', component: HomeComponent }, - { path: 'admin', component: AdminDashboardComponent }, - { path: ':roomName', component: VideoRoomComponent, canActivate: [NavigationGuardService] } -]; - -@NgModule({ - imports: [RouterModule.forRoot(routes)], - exports: [RouterModule] -}) -export class AppRoutingModule {} diff --git a/openvidu-call-front/src/app/app.config.ts b/openvidu-call-front/src/app/app.config.ts new file mode 100644 index 00000000..76f8abbd --- /dev/null +++ b/openvidu-call-front/src/app/app.config.ts @@ -0,0 +1,21 @@ + +import { ApplicationConfig, importProvidersFrom, provideZoneChangeDetection } from '@angular/core'; +import { provideRouter } from '@angular/router'; + +import { provideAnimationsAsync } from '@angular/platform-browser/animations/async'; +import { OpenViduComponentsModule, OpenViduComponentsConfig } from 'openvidu-components-angular'; +import { environment } from '@environment/environment'; +import { routes } from '@app/app.routes'; + +const ovComponentsconfig: OpenViduComponentsConfig = { + production: environment.production +}; + +export const appConfig: ApplicationConfig = { + providers: [ + importProvidersFrom(OpenViduComponentsModule.forRoot(ovComponentsconfig)), + provideZoneChangeDetection({ eventCoalescing: true }), + provideRouter(routes), + provideAnimationsAsync() + ] +}; \ No newline at end of file diff --git a/openvidu-call-front/src/app/app.routes.ts b/openvidu-call-front/src/app/app.routes.ts new file mode 100644 index 00000000..772e9804 --- /dev/null +++ b/openvidu-call-front/src/app/app.routes.ts @@ -0,0 +1,13 @@ +import { Routes } from '@angular/router'; +import { HomeComponent } from '@pages/home/home.component'; +import { AdminDashboardComponent } from '@pages/admin-dashboard/admin-dashboard.component'; +import { VideoRoomComponent } from '@pages/video-room/video-room.component'; +import { roomGuard } from '@guards/room.guard'; + + +export const routes: Routes = [ + { path: '', redirectTo: 'home', pathMatch: 'full' }, + { path: 'home', component: HomeComponent }, + { path: 'admin', component: AdminDashboardComponent }, + { path: ':roomName', component: VideoRoomComponent, canActivate: [roomGuard] } +]; diff --git a/openvidu-call-front/src/app/core/guards/room.guard.ts b/openvidu-call-front/src/app/core/guards/room.guard.ts new file mode 100644 index 00000000..dbebb7ae --- /dev/null +++ b/openvidu-call-front/src/app/core/guards/room.guard.ts @@ -0,0 +1,34 @@ +import { inject } from '@angular/core'; +import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router'; +import { ConfigService } from '../services/config.service'; +import { StorageService } from '../services/storage.service'; +import { RestService } from '../services/rest.service'; +import { CanActivateFn } from '@angular/router'; + +export const roomGuard: CanActivateFn = async (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => { + const configService = inject(ConfigService); + const storageService = inject(StorageService); + const restService = inject(RestService); + const router = inject(Router); + + try { + await configService.initialize(); + + if (configService.isPrivateAccess()) { + const userCredentials = storageService.getUserCredentials(); + + if (!userCredentials) { + router.navigate(['/']); + return false; + } + + await restService.userLogin(userCredentials); + return true; + } + } catch (error) { + router.navigate(['/'], { queryParams: { roomName: state.url } }); + return false; + } + + return true; +}; diff --git a/openvidu-call-front/src/app/services/config.service.ts b/openvidu-call-front/src/app/core/services/config.service.ts similarity index 100% rename from openvidu-call-front/src/app/services/config.service.ts rename to openvidu-call-front/src/app/core/services/config.service.ts diff --git a/openvidu-call-front/src/app/services/rest.service.ts b/openvidu-call-front/src/app/core/services/rest.service.ts similarity index 100% rename from openvidu-call-front/src/app/services/rest.service.ts rename to openvidu-call-front/src/app/core/services/rest.service.ts diff --git a/openvidu-call-front/src/app/services/storage.service.ts b/openvidu-call-front/src/app/core/services/storage.service.ts similarity index 100% rename from openvidu-call-front/src/app/services/storage.service.ts rename to openvidu-call-front/src/app/core/services/storage.service.ts diff --git a/openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.html b/openvidu-call-front/src/app/pages/admin-dashboard/admin-dashboard.component.html similarity index 100% rename from openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.html rename to openvidu-call-front/src/app/pages/admin-dashboard/admin-dashboard.component.html diff --git a/openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.scss b/openvidu-call-front/src/app/pages/admin-dashboard/admin-dashboard.component.scss similarity index 100% rename from openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.scss rename to openvidu-call-front/src/app/pages/admin-dashboard/admin-dashboard.component.scss diff --git a/openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.spec.ts b/openvidu-call-front/src/app/pages/admin-dashboard/admin-dashboard.component.spec.ts similarity index 100% rename from openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.spec.ts rename to openvidu-call-front/src/app/pages/admin-dashboard/admin-dashboard.component.spec.ts diff --git a/openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.ts b/openvidu-call-front/src/app/pages/admin-dashboard/admin-dashboard.component.ts similarity index 95% rename from openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.ts rename to openvidu-call-front/src/app/pages/admin-dashboard/admin-dashboard.component.ts index 49bdded7..0f7772e1 100644 --- a/openvidu-call-front/src/app/components/admin-dashboard/admin-dashboard.component.ts +++ b/openvidu-call-front/src/app/pages/admin-dashboard/admin-dashboard.component.ts @@ -1,6 +1,6 @@ import { Component, OnDestroy, OnInit } from '@angular/core'; -import { RestService } from 'src/app/services/rest.service'; -import { StorageService } from 'src/app/services/storage.service'; +import { RestService } from '@services/rest.service'; +import { StorageService } from '@services/storage.service'; import { OpenViduComponentsModule, ApiDirectiveModule } from 'openvidu-components-angular'; @Component({ diff --git a/openvidu-call-front/src/app/components/home/home.component.html b/openvidu-call-front/src/app/pages/home/home.component.html similarity index 100% rename from openvidu-call-front/src/app/components/home/home.component.html rename to openvidu-call-front/src/app/pages/home/home.component.html diff --git a/openvidu-call-front/src/app/components/home/home.component.scss b/openvidu-call-front/src/app/pages/home/home.component.scss similarity index 100% rename from openvidu-call-front/src/app/components/home/home.component.scss rename to openvidu-call-front/src/app/pages/home/home.component.scss diff --git a/openvidu-call-front/src/app/components/home/home.component.spec.ts b/openvidu-call-front/src/app/pages/home/home.component.spec.ts similarity index 100% rename from openvidu-call-front/src/app/components/home/home.component.spec.ts rename to openvidu-call-front/src/app/pages/home/home.component.spec.ts diff --git a/openvidu-call-front/src/app/components/home/home.component.ts b/openvidu-call-front/src/app/pages/home/home.component.ts similarity index 96% rename from openvidu-call-front/src/app/components/home/home.component.ts rename to openvidu-call-front/src/app/pages/home/home.component.ts index 4fafa7d0..c8526bb8 100644 --- a/openvidu-call-front/src/app/components/home/home.component.ts +++ b/openvidu-call-front/src/app/pages/home/home.component.ts @@ -7,18 +7,22 @@ import { FormsModule, ReactiveFormsModule } from '@angular/forms'; -import { ActivatedRoute, Router } from '@angular/router'; -import { Subscription } from 'rxjs'; -import { ConfigService } from 'src/app/services/config.service'; -import { animals, colors, Config, countries, names, uniqueNamesGenerator } from 'unique-names-generator'; -import packageInfo from '../../../../package.json'; -import { RestService } from 'src/app/services/rest.service'; -import { StorageService } from 'src/app/services/storage.service'; import { MatIcon } from '@angular/material/icon'; import { MatTooltip } from '@angular/material/tooltip'; import { MatIconButton, MatButton } from '@angular/material/button'; import { NgClass } from '@angular/common'; import { MatToolbar } from '@angular/material/toolbar'; +import { ActivatedRoute, Router } from '@angular/router'; + +import { Subscription } from 'rxjs'; + +import { ConfigService } from '@services/config.service'; +import { RestService } from '@services/rest.service'; +import { StorageService } from '@services/storage.service'; + +import packageInfo from '../../../../package.json'; + +import { animals, colors, Config, countries, names, uniqueNamesGenerator } from 'unique-names-generator'; @Component({ selector: 'app-home', diff --git a/openvidu-call-front/src/app/components/video-room/video-room.component.html b/openvidu-call-front/src/app/pages/video-room/video-room.component.html similarity index 100% rename from openvidu-call-front/src/app/components/video-room/video-room.component.html rename to openvidu-call-front/src/app/pages/video-room/video-room.component.html diff --git a/openvidu-call-front/src/app/components/video-room/video-room.component.scss b/openvidu-call-front/src/app/pages/video-room/video-room.component.scss similarity index 100% rename from openvidu-call-front/src/app/components/video-room/video-room.component.scss rename to openvidu-call-front/src/app/pages/video-room/video-room.component.scss diff --git a/openvidu-call-front/src/app/components/video-room/video-room.component.spec.ts b/openvidu-call-front/src/app/pages/video-room/video-room.component.spec.ts similarity index 100% rename from openvidu-call-front/src/app/components/video-room/video-room.component.spec.ts rename to openvidu-call-front/src/app/pages/video-room/video-room.component.spec.ts diff --git a/openvidu-call-front/src/app/components/video-room/video-room.component.ts b/openvidu-call-front/src/app/pages/video-room/video-room.component.ts similarity index 97% rename from openvidu-call-front/src/app/components/video-room/video-room.component.ts rename to openvidu-call-front/src/app/pages/video-room/video-room.component.ts index 6c526663..cd703979 100644 --- a/openvidu-call-front/src/app/components/video-room/video-room.component.ts +++ b/openvidu-call-front/src/app/pages/video-room/video-room.component.ts @@ -9,9 +9,9 @@ import { OpenViduComponentsModule, ApiDirectiveModule } from 'openvidu-components-angular'; -import { RestService } from '../../services/rest.service'; import { MatIcon } from '@angular/material/icon'; +import { RestService } from '@services/rest.service'; @Component({ selector: 'app-video-room', diff --git a/openvidu-call-front/src/app/services/guards/navigation-guard.service.ts b/openvidu-call-front/src/app/services/guards/navigation-guard.service.ts deleted file mode 100644 index 4f4d5f62..00000000 --- a/openvidu-call-front/src/app/services/guards/navigation-guard.service.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router'; -import { ConfigService } from '../config.service'; -import { StorageService } from '../storage.service'; -import { RestService } from '../rest.service'; - -@Injectable({ - providedIn: 'root' -}) -export class NavigationGuardService { - constructor( - private router: Router, - private callService: ConfigService, - private storageService: StorageService, - private restService: RestService - ) {} - - // Check if user can navigate to the route - async canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise { - await this.callService.initialize(); - - if (this.callService.isPrivateAccess()) { - const userCredentials = this.storageService.getUserCredentials(); - - if (!userCredentials) { - this.router.navigate(['/']); - return false; - } - - try { - await this.restService.userLogin(userCredentials); - return true; - } catch (error) { - this.router.navigate(['/'], { queryParams: { roomName: state.url } }); - return false; - } - } - - return true; - } -} diff --git a/openvidu-call-front/src/main.ts b/openvidu-call-front/src/main.ts index 21b2b699..29cecf56 100644 --- a/openvidu-call-front/src/main.ts +++ b/openvidu-call-front/src/main.ts @@ -1,22 +1,11 @@ -import { enableProdMode, importProvidersFrom } from '@angular/core'; -import { environment } from './environments/environment'; +import { enableProdMode } from '@angular/core'; +import { environment } from '@environment/environment'; import { AppComponent } from './app/app.component'; -import { AppRoutingModule } from './app/app-routing.module'; -import { OpenViduComponentsModule, OpenViduComponentsConfig } from 'openvidu-components-angular'; -import { provideAnimations } from '@angular/platform-browser/animations'; -import { BrowserModule, bootstrapApplication } from '@angular/platform-browser'; - -const componentsConfig: OpenViduComponentsConfig = { - production: environment.production -}; +import { bootstrapApplication } from '@angular/platform-browser'; +import { appConfig } from './app/app.config'; if (environment.production) { enableProdMode(); } -bootstrapApplication(AppComponent, { - providers: [ - importProvidersFrom(BrowserModule, OpenViduComponentsModule.forRoot(componentsConfig), AppRoutingModule), - provideAnimations() - ] -}).catch((err) => console.log(err)); +bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err)); diff --git a/openvidu-call-front/tsconfig.json b/openvidu-call-front/tsconfig.json index ab8ae9f1..9da897ae 100644 --- a/openvidu-call-front/tsconfig.json +++ b/openvidu-call-front/tsconfig.json @@ -4,18 +4,24 @@ "baseUrl": "./", "module": "esnext", "outDir": "./dist/out-tsc", - "sourceMap": true, - "esModuleInterop": true, + "sourceMap": true, + "esModuleInterop": true, "declaration": false, "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, - "resolveJsonModule": true, + "resolveJsonModule": true, "target": "ES2022", "typeRoots": ["node_modules/@types"], "lib": ["es2017", "dom"], "paths": { - "core-js/es7/reflect": ["./node_modules/core-js/proposals/reflect-metadata"] + "core-js/es7/reflect": ["./node_modules/core-js/proposals/reflect-metadata"], + "@app/*": ["src/app/*"], + "@core/*": ["src/app/core/*"], + "@services/*": ["src/app/core/services/*"], + "@guards/*": ["src/app/core/guards/*"], + "@pages/*": ["src/app/pages/*"], + "@environment/*": ["src/environments/*"] }, "useDefineForClassFields": false }