From 5fba250b1d31c460d1381248848c101d0943162d Mon Sep 17 00:00:00 2001 From: Carlos Santos <4a.santos@gmail.com> Date: Sat, 8 Mar 2025 17:42:43 +0100 Subject: [PATCH] ov-components: remove ServiceConfigService and update components to use LayoutService directly --- .../lib/components/layout/layout.component.ts | 28 ++++++------- .../components/session/session.component.ts | 5 +-- .../settings/captions/captions.component.ts | 10 ++--- .../lib/components/stream/stream.component.ts | 8 +--- .../components/toolbar/toolbar.component.ts | 5 +-- .../openvidu-components-angular.config.ts | 1 - .../services/config/service-config.service.ts | 40 ------------------- 7 files changed, 21 insertions(+), 76 deletions(-) delete mode 100644 openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/config/service-config.service.ts diff --git a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/layout/layout.component.ts b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/layout/layout.component.ts index 68f8c661..d3a72685 100644 --- a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/layout/layout.component.ts +++ b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/layout/layout.component.ts @@ -19,7 +19,6 @@ import { ParticipantService } from '../../services/participant/participant.servi import { CdkDrag } from '@angular/cdk/drag-drop'; import { PanelService } from '../../services/panel/panel.service'; import { GlobalConfigService } from '../../services/config/global-config.service'; -import { ServiceConfigService } from '../../services/config/service-config.service'; import { OpenViduComponentsConfigService } from '../../services/config/directive-config.service'; /** @@ -80,21 +79,18 @@ export class LayoutComponent implements OnInit, OnDestroy, AfterViewInit { private resizeTimeout: NodeJS.Timeout; private videoIsAtRight: boolean = false; private lastLayoutWidth: number = 0; - private layoutService: LayoutService; /** * @ignore */ constructor( - private serviceConfig: ServiceConfigService, + private layoutService: LayoutService, private panelService: PanelService, private participantService: ParticipantService, private globalService: GlobalConfigService, private directiveService: OpenViduComponentsConfigService, private cd: ChangeDetectorRef - ) { - this.layoutService = this.serviceConfig.getLayoutService(); - } + ) {} ngOnInit(): void { this.subscribeToParticipants(); @@ -152,17 +148,17 @@ export class LayoutComponent implements OnInit, OnDestroy, AfterViewInit { this.remoteParticipantsSubs = combineLatest([ this.participantService.remoteParticipants$, this.directiveService.layoutRemoteParticipants$ - ]) - .pipe( - map(([serviceParticipants, directiveParticipants]) => - directiveParticipants !== undefined ? directiveParticipants : serviceParticipants + ]) + .pipe( + map(([serviceParticipants, directiveParticipants]) => + directiveParticipants !== undefined ? directiveParticipants : serviceParticipants + ) ) - ) - .subscribe((participants) => { - this.remoteParticipants = participants; - this.layoutService.update(); - this.cd.markForCheck(); - }); + .subscribe((participants) => { + this.remoteParticipants = participants; + this.layoutService.update(); + this.cd.markForCheck(); + }); } private listenToResizeLayout() { diff --git a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/session/session.component.ts b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/session/session.component.ts index 481f9fb3..2ad7501a 100644 --- a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/session/session.component.ts +++ b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/session/session.component.ts @@ -47,7 +47,6 @@ import { Track } from 'livekit-client'; import { ParticipantLeftEvent, ParticipantModel } from '../../models/participant.model'; -import { ServiceConfigService } from '../../services/config/service-config.service'; /** * @internal @@ -108,10 +107,9 @@ export class SessionComponent implements OnInit, OnDestroy { private updateLayoutInterval: NodeJS.Timeout; private captionLanguageSubscription: Subscription; private log: ILogger; - private layoutService: LayoutService; constructor( - private serviceConfig: ServiceConfigService, + private layoutService: LayoutService, private actionService: ActionService, private openviduService: OpenViduService, private participantService: ParticipantService, @@ -127,7 +125,6 @@ export class SessionComponent implements OnInit, OnDestroy { private cd: ChangeDetectorRef ) { this.log = this.loggerSrv.get('SessionComponent'); - this.layoutService = this.serviceConfig.getLayoutService(); } @HostListener('window:beforeunload') diff --git a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/settings/captions/captions.component.ts b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/settings/captions/captions.component.ts index f094d79b..4178f488 100644 --- a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/settings/captions/captions.component.ts +++ b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/settings/captions/captions.component.ts @@ -23,11 +23,11 @@ export class CaptionsSettingComponent implements OnInit, OnDestroy { private captionsStatusSubs: Subscription; private sttStatusSubs: Subscription; - private layoutService: LayoutService; - - constructor(private serviceConfig: ServiceConfigService, private captionService: CaptionService, private openviduService: OpenViduService) { - this.layoutService = this.serviceConfig.getLayoutService(); - } + constructor( + private layoutService: LayoutService, + private captionService: CaptionService, + private openviduService: OpenViduService + ) {} ngOnInit(): void { // this.isOpenViduPro = this.openviduService.isOpenViduPro(); diff --git a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/stream/stream.component.ts b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/stream/stream.component.ts index e5e77481..d8aa88c8 100644 --- a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/stream/stream.component.ts +++ b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/stream/stream.component.ts @@ -7,7 +7,6 @@ import { LayoutService } from '../../services/layout/layout.service'; import { ParticipantService } from '../../services/participant/participant.service'; import { Track } from 'livekit-client'; import { ParticipantTrackPublication } from '../../models/participant.model'; -import { ServiceConfigService } from '../../services/config/service-config.service'; /** * The **StreamComponent** is hosted inside of the {@link LayoutComponent}. @@ -98,18 +97,15 @@ export class StreamComponent implements OnInit, OnDestroy { private videoControlsSub: Subscription; private readonly HOVER_TIMEOUT = 3000; - private layoutService: LayoutService; /** * @ignore */ constructor( - private serviceConfig: ServiceConfigService, + private layoutService: LayoutService, private participantService: ParticipantService, private cdkSrv: CdkOverlayService, private libService: OpenViduComponentsConfigService - ) { - this.layoutService = this.serviceConfig.getLayoutService(); - } + ) {} ngOnInit() { this.subscribeToStreamDirectives(); diff --git a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/toolbar/toolbar.component.ts b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/toolbar/toolbar.component.ts index 999838b7..c421946d 100644 --- a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/toolbar/toolbar.component.ts +++ b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/components/toolbar/toolbar.component.ts @@ -49,7 +49,6 @@ import { CdkOverlayService } from '../../services/cdk-overlay/cdk-overlay.servic import { ParticipantLeftEvent, ParticipantModel } from '../../models/participant.model'; import { Room, RoomEvent } from 'livekit-client'; import { ToolbarAdditionalButtonsPosition } from '../../models/toolbar.model'; -import { ServiceConfigService } from '../../services/config/service-config.service'; /** * The **ToolbarComponent** is hosted inside of the {@link VideoconferenceComponent}. @@ -349,13 +348,12 @@ export class ToolbarComponent implements OnInit, OnDestroy, AfterViewInit { private additionalButtonsPositionSub: Subscription; private fullscreenChangeSubscription: Subscription; private currentWindowHeight = window.innerHeight; - private layoutService: LayoutService; /** * @ignore */ constructor( - private serviceConfig: ServiceConfigService, + private layoutService: LayoutService, private documentService: DocumentService, private chatService: ChatService, private panelService: PanelService, @@ -374,7 +372,6 @@ export class ToolbarComponent implements OnInit, OnDestroy, AfterViewInit { private cdkOverlayService: CdkOverlayService ) { this.log = this.loggerSrv.get('ToolbarComponent'); - this.layoutService = this.serviceConfig.getLayoutService(); } /** * @ignore diff --git a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/config/openvidu-components-angular.config.ts b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/config/openvidu-components-angular.config.ts index 7f5bdb67..33052857 100644 --- a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/config/openvidu-components-angular.config.ts +++ b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/config/openvidu-components-angular.config.ts @@ -3,7 +3,6 @@ import { ParticipantProperties } from '../models/participant.model'; export interface OpenViduComponentsConfig { production?: boolean; participantFactory?: ParticipantFactoryFunction; - services?: any; } export type ParticipantFactoryFunction = (props: ParticipantProperties) => any; diff --git a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/config/service-config.service.ts b/openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/config/service-config.service.ts deleted file mode 100644 index 30119d58..00000000 --- a/openvidu-components-angular/projects/openvidu-components-angular/src/lib/services/config/service-config.service.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { Injectable, Inject, Injector, Optional } from '@angular/core'; -import { LayoutService } from '../layout/layout.service'; -import { OpenViduComponentsConfig } from '../../config/openvidu-components-angular.config'; - -/** - * @internal - */ -@Injectable({ - providedIn: 'root' -}) -export class ServiceConfigService { - private configuration: OpenViduComponentsConfig; - - constructor( - @Optional() private injector: Injector, - @Inject('OPENVIDU_COMPONENTS_CONFIG') config: OpenViduComponentsConfig - ) { - this.configuration = config; - } - - getLayoutService(): LayoutService { - return this.getServiceSafely('LayoutService', LayoutService); - } - - private getService(key: string): T { - const service = this.configuration.services ? this.configuration.services[key] : null; - if (!service) { - throw new Error(`No service registered with key ${key}`); - } - return this.injector.get(service) as T; - } - - private getServiceSafely(key: string, fallback: new (...args: any[]) => T): T { - try { - return this.getService(key); - } catch { - return this.injector.get(fallback); - } - } -}