Skip to content

Commit

Permalink
ov-components: Refactored and improved config
Browse files Browse the repository at this point in the history
  • Loading branch information
CSantosM committed Sep 4, 2024
1 parent 724fbd9 commit bd6ba55
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import {
ViewChild,
ViewContainerRef
} from '@angular/core';
import { Subscription } from 'rxjs';
import { combineLatest, map, Subscription } from 'rxjs';
import { StreamDirective } from '../../directives/template/openvidu-components-angular.directive';
import { ParticipantTrackPublication, ParticipantModel } from '../../models/participant.model';
import { LayoutService } from '../../services/layout/layout.service';
import { ParticipantService } from '../../services/participant/participant.service';
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';

/**
*
Expand Down Expand Up @@ -78,24 +80,29 @@ 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 layoutService: LayoutService,
private serviceConfig: ServiceConfigService,
private panelService: PanelService,
private participantService: ParticipantService,
private globalService: GlobalConfigService,
private directiveService: OpenViduComponentsConfigService,
private cd: ChangeDetectorRef
) {}
) {
this.layoutService = this.serviceConfig.getLayoutService();
}

ngOnInit(): void {
this.subscribeToParticipants();
this.subscribeToCaptions();
}

ngAfterViewInit() {
console.log('LayoutComponent.ngAfterViewInit');
this.layoutService.initialize(this.layoutContainer.element.nativeElement);
this.lastLayoutWidth = this.layoutContainer.element.nativeElement.getBoundingClientRect().width;
this.listenToResizeLayout();
Expand Down Expand Up @@ -142,11 +149,20 @@ export class LayoutComponent implements OnInit, OnDestroy, AfterViewInit {
}
});

this.remoteParticipantsSubs = this.participantService.remoteParticipants$.subscribe((participants) => {
this.remoteParticipantsSubs = combineLatest([
this.participantService.remoteParticipants$,
this.directiveService.layoutRemoteParticipants$
])
.pipe(
map(([serviceParticipants, directiveParticipants]) =>
directiveParticipants !== undefined ? directiveParticipants : serviceParticipants
)
)
.subscribe((participants) => {
this.remoteParticipants = participants;
this.layoutService.update();
this.cd.markForCheck();
});
});
}

private listenToResizeLayout() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Subscription } from 'rxjs';
import { ILogger } from '../../models/logger.model';
import { CdkOverlayService } from '../../services/cdk-overlay/cdk-overlay.service';
import { OpenViduComponentsConfigService } from '../../services/config/directive-config.service';
import { LayoutService } from '../../services/layout/layout.service';
import { LoggerService } from '../../services/logger/logger.service';
import { OpenViduService } from '../../services/openvidu/openvidu.service';
import { TranslateService } from '../../services/translate/translate.service';
Expand Down Expand Up @@ -55,11 +54,9 @@ export class PreJoinComponent implements OnInit, OnDestroy {
@HostListener('window:resize')
sizeChange() {
this.windowSize = window.innerWidth;
this.layoutService.update();
}

constructor(
private layoutService: LayoutService,
private loggerSrv: LoggerService,
private libService: OpenViduComponentsConfigService,
private cdkSrv: CdkOverlayService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
Track
} from 'livekit-client';
import { ParticipantModel } from '../../models/participant.model';
import { ServiceConfigService } from '../../services/config/service-config.service';

/**
* @internal
Expand Down Expand Up @@ -88,15 +89,16 @@ export class SessionComponent implements OnInit, OnDestroy {
private updateLayoutInterval: NodeJS.Timeout;
private captionLanguageSubscription: Subscription;
private log: ILogger;
private layoutService: LayoutService;

constructor(
private serviceConfig: ServiceConfigService,
private actionService: ActionService,
private openviduService: OpenViduService,
private participantService: ParticipantService,
private loggerSrv: LoggerService,
private chatService: ChatService,
private libService: OpenViduComponentsConfigService,
private layoutService: LayoutService,
private panelService: PanelService,
private recordingService: RecordingService,
private broadcastingService: BroadcastingService,
Expand All @@ -106,6 +108,7 @@ export class SessionComponent implements OnInit, OnDestroy {
private cd: ChangeDetectorRef
) {
this.log = this.loggerSrv.get('SessionComponent');
this.layoutService = this.serviceConfig.getLayoutService();
}

@HostListener('window:beforeunload')
Expand Down Expand Up @@ -205,7 +208,7 @@ export class SessionComponent implements OnInit, OnDestroy {
}

async ngOnDestroy() {
if(this.shouldDisconnectRoomWhenComponentIsDestroyed) {
if (this.shouldDisconnectRoomWhenComponentIsDestroyed) {
await this.disconnectRoom();
}
this.room.removeAllListeners();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CaptionsLangOption } from '../../../models/caption.model';
import { CaptionService } from '../../../services/caption/caption.service';
import { LayoutService } from '../../../services/layout/layout.service';
import { OpenViduService } from '../../../services/openvidu/openvidu.service';
import { ServiceConfigService } from '../../../services/config/service-config.service';

/**
* @internal
Expand All @@ -22,8 +23,11 @@ export class CaptionsSettingComponent implements OnInit, OnDestroy {
private captionsStatusSubs: Subscription;
private sttStatusSubs: Subscription;

private layoutService: LayoutService;

constructor(private layoutService: LayoutService, private captionService: CaptionService, private openviduService: OpenViduService) {}
constructor(private serviceConfig: ServiceConfigService, private captionService: CaptionService, private openviduService: OpenViduService) {
this.layoutService = this.serviceConfig.getLayoutService();
}

ngOnInit(): void {
// this.isOpenViduPro = this.openviduService.isOpenViduPro();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import { Subscription } from 'rxjs';
import { CdkOverlayService } from '../../services/cdk-overlay/cdk-overlay.service';
import { OpenViduComponentsConfigService } from '../../services/config/directive-config.service';
import { LayoutService } from '../../services/layout/layout.service';
import { OpenViduService } from '../../services/openvidu/openvidu.service';
import { ParticipantService } from '../../services/participant/participant.service';
import { StorageService } from '../../services/storage/storage.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}.
Expand Down Expand Up @@ -99,17 +98,18 @@ export class StreamComponent implements OnInit, OnDestroy {
private videoControlsSub: Subscription;
private readonly HOVER_TIMEOUT = 3000;

private layoutService: LayoutService;
/**
* @ignore
*/
constructor(
private openviduService: OpenViduService,
private layoutService: LayoutService,
private serviceConfig: ServiceConfigService,
private participantService: ParticipantService,
private storageService: StorageService,
private cdkSrv: CdkOverlayService,
private libService: OpenViduComponentsConfigService
) {}
) {
this.layoutService = this.serviceConfig.getLayoutService();
}

ngOnInit() {
this.subscribeToStreamDirectives();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { CdkOverlayService } from '../../services/cdk-overlay/cdk-overlay.servic
import { 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}.
Expand Down Expand Up @@ -342,11 +343,13 @@ 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 documentService: DocumentService,
private chatService: ChatService,
private panelService: PanelService,
Expand All @@ -355,7 +358,6 @@ export class ToolbarComponent implements OnInit, OnDestroy, AfterViewInit {
private oVDevicesService: DeviceService,
private actionService: ActionService,
private loggerSrv: LoggerService,
private layoutService: LayoutService,
private cd: ChangeDetectorRef,
private libService: OpenViduComponentsConfigService,
private platformService: PlatformService,
Expand All @@ -366,6 +368,7 @@ export class ToolbarComponent implements OnInit, OnDestroy, AfterViewInit {
private cdkOverlayService: CdkOverlayService
) {
this.log = this.loggerSrv.get('ToolbarComponent');
this.layoutService = this.serviceConfig.getLayoutService();
}
/**
* @ignore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { ParticipantProperties } from '../models/participant.model';

export interface OpenViduComponentsConfig {
production?: boolean,
participantFactory?: ParticipantFactoryFunction,
production?: boolean;
participantFactory?: ParticipantFactoryFunction;
services?: any;
}

export type ParticipantFactoryFunction = (props: ParticipantProperties) => any;
export type ParticipantFactoryFunction = (props: ParticipantProperties) => any;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NgModule } from '@angular/core';
import { ActivitiesPanelBroadcastingActivityDirective, ActivitiesPanelRecordingActivityDirective } from './activities-panel.directive';
import { AdminLoginErrorDirective, AdminDashboardRecordingsListDirective } from './admin.directive';
import { LogoDirective } from './internals.directive';
import { LayoutRemoteParticipantsDirective, LogoDirective } from './internals.directive';
import { ParticipantPanelItemMuteButtonDirective } from './participant-panel-item.directive';
import {
StreamDisplayAudioDetectionDirective,
Expand Down Expand Up @@ -76,7 +76,8 @@ import {
ActivitiesPanelRecordingActivityDirective,
ActivitiesPanelBroadcastingActivityDirective,
AdminDashboardRecordingsListDirective,
AdminLoginErrorDirective
AdminLoginErrorDirective,
LayoutRemoteParticipantsDirective
],
exports: [
LivekitUrlDirective,
Expand Down Expand Up @@ -113,7 +114,8 @@ import {
ActivitiesPanelRecordingActivityDirective,
ActivitiesPanelBroadcastingActivityDirective,
AdminDashboardRecordingsListDirective,
AdminLoginErrorDirective
AdminLoginErrorDirective,
LayoutRemoteParticipantsDirective
]
})
export class ApiDirectiveModule {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// * Private directives *
// * Internal directives *

import { Directive, ElementRef, HostListener, Input } from '@angular/core';
import { ParticipantModel } from '../../models/participant.model';
import { OpenViduComponentsConfigService } from '../../services/config/directive-config.service';

/**
* Load default OpenVidu logo if custom one is not exist
Expand All @@ -21,3 +23,35 @@ export class LogoDirective {
element.src = this.ovLogo || this.defaultLogo;
}
}

/**
* @internal
*/
@Directive({
selector: 'ov-layout[ovRemoteParticipants]'
})
export class LayoutRemoteParticipantsDirective {
@Input() set ovRemoteParticipants(value: ParticipantModel[] | undefined) {
this.update(value);
}
constructor(
public elementRef: ElementRef,
private directiveService: OpenViduComponentsConfigService
) {}

ngOnDestroy(): void {
this.clear();
}

ngAfterViewInit() {
this.update(this.ovRemoteParticipants);
}

update(value: ParticipantModel[] | undefined) {
this.directiveService.setLayoutRemoteParticipants(value);
}

clear() {
this.update(undefined);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OverlayContainer } from '@angular/cdk/overlay';
import { CommonModule } from '@angular/common';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { ModuleWithProviders, NgModule } from '@angular/core';
import { ModuleWithProviders, NgModule, Provider } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';

import { DeleteDialogComponent } from './components/dialogs/delete-recording.component';
Expand All @@ -25,7 +25,6 @@ import { CdkOverlayContainer } from './config/custom-cdk-overlay';
import { OpenViduComponentsConfig } from './config/openvidu-components-angular.config';
import { ActionService } from './services/action/action.service';
import { ChatService } from './services/chat/chat.service';
import { OpenViduComponentsConfigService } from './services/config/directive-config.service';
import { DeviceService } from './services/device/device.service';
import { DocumentService } from './services/document/document.service';
import { LayoutService } from './services/layout/layout.service';
Expand Down Expand Up @@ -65,6 +64,8 @@ import { AppMaterialModule } from './openvidu-components-angular.material.module
import { VirtualBackgroundService } from './services/virtual-background/virtual-background.service';
import { BroadcastingService } from './services/broadcasting/broadcasting.service';
import { TranslateService } from './services/translate/translate.service';
import { GlobalConfigService } from './services/config/global-config.service';
import { OpenViduComponentsConfigService } from './services/config/directive-config.service';

const publicComponents = [
AdminDashboardComponent,
Expand Down Expand Up @@ -131,6 +132,8 @@ const privateComponents = [
DragDropModule
],
providers: [
GlobalConfigService,
OpenViduComponentsConfigService,
ActionService,
BroadcastingService,
// CaptionService,
Expand All @@ -139,7 +142,7 @@ const privateComponents = [
ChatService,
DeviceService,
DocumentService,
LayoutService,
// LayoutService,
LoggerService,
OpenViduService,
PanelService,
Expand All @@ -153,12 +156,12 @@ const privateComponents = [
]
})
export class OpenViduComponentsModule {
static forRoot(config): ModuleWithProviders<OpenViduComponentsModule> {
// console.log(`${library.name} config: ${environment}`);
const libConfig: OpenViduComponentsConfig = config;
static forRoot(config: OpenViduComponentsConfig): ModuleWithProviders<OpenViduComponentsModule> {
const providers: Provider[] = [{ provide: 'OPENVIDU_COMPONENTS_CONFIG', useValue: config }];

return {
ngModule: OpenViduComponentsModule,
providers: [OpenViduComponentsConfigService, { provide: 'OPENVIDU_COMPONENTS_CONFIG', useValue: libConfig }]
providers
};
}
}
Loading

0 comments on commit bd6ba55

Please sign in to comment.