mirror of https://github.com/OpenVidu/openvidu.git
openvidu-components: Fixed layout when is webcomponent
When webcomponent, the layout need more time for initilizating and showing the videos.pull/707/head
parent
e0de51921c
commit
a3d5a9c98f
|
@ -1,9 +1,19 @@
|
|||
import { AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, OnDestroy, OnInit, TemplateRef } from '@angular/core';
|
||||
import {
|
||||
AfterViewInit,
|
||||
ChangeDetectionStrategy,
|
||||
ChangeDetectorRef,
|
||||
Component,
|
||||
ContentChild,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
TemplateRef
|
||||
} from '@angular/core';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { ParticipantService } from '../../services/participant/participant.service';
|
||||
import { ParticipantAbstractModel } from '../../models/participant.model';
|
||||
import { LayoutService } from '../../services/layout/layout.service';
|
||||
import { StreamDirective } from '../../directives/template/openvidu-angular.directive';
|
||||
import { OpenViduAngularConfigService } from '../../services/config/openvidu-angular.config.service';
|
||||
|
||||
@Component({
|
||||
selector: 'ov-layout',
|
||||
|
@ -15,10 +25,10 @@ export class LayoutComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||
@ContentChild('stream', { read: TemplateRef }) streamTemplate: TemplateRef<any>;
|
||||
|
||||
@ContentChild(StreamDirective)
|
||||
set externalStream (externalStream: StreamDirective) {
|
||||
set externalStream(externalStream: StreamDirective) {
|
||||
// This directive will has value only when STREAM component tagget with '*ovStream' directive
|
||||
// is inside of the layout component tagged with '*ovLayout' directive
|
||||
if(externalStream) {
|
||||
if (externalStream) {
|
||||
this.streamTemplate = externalStream.template;
|
||||
}
|
||||
}
|
||||
|
@ -28,15 +38,25 @@ export class LayoutComponent implements OnInit, OnDestroy, AfterViewInit {
|
|||
protected localParticipantSubs: Subscription;
|
||||
protected remoteParticipantsSubs: Subscription;
|
||||
|
||||
constructor(protected layoutService: LayoutService, protected participantService: ParticipantService, private cd: ChangeDetectorRef) {}
|
||||
constructor(
|
||||
protected layoutService: LayoutService,
|
||||
protected participantService: ParticipantService,
|
||||
private libService: OpenViduAngularConfigService,
|
||||
private cd: ChangeDetectorRef
|
||||
) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.subscribeToParticipants();
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.layoutService.initialize();
|
||||
this.layoutService.update();
|
||||
let timeout: number = null;
|
||||
if (this.libService.isWebcomponent()) {
|
||||
timeout = 0;
|
||||
}
|
||||
|
||||
this.layoutService.initialize(timeout);
|
||||
this.layoutService.update(timeout);
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
align-items: center;
|
||||
}
|
||||
#media-buttons-container {
|
||||
max-height: 100%;
|
||||
max-height: 100% !important;
|
||||
}
|
||||
|
||||
#media-buttons-container > *, ::ng-deep #media-buttons-container > * {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
export interface OpenViduAngularConfig {
|
||||
production?: boolean,
|
||||
participantFactory?: ParticipantFactoryFunction,
|
||||
webcomponent?: boolean
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -141,7 +141,7 @@ export class OpenViduLayout {
|
|||
}
|
||||
|
||||
getLayoutContainer(): HTMLElement {
|
||||
return this.layoutContainer
|
||||
return this.layoutContainer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -70,6 +70,10 @@ export class OpenViduAngularConfigService {
|
|||
return this.configuration?.production;
|
||||
}
|
||||
|
||||
isWebcomponent(): boolean {
|
||||
return this.configuration?.webcomponent;
|
||||
}
|
||||
|
||||
hasParticipantFactory(): boolean {
|
||||
return typeof this.getConfig().participantFactory === "function";
|
||||
}
|
||||
|
|
|
@ -17,23 +17,25 @@ export class LayoutService {
|
|||
}
|
||||
|
||||
initialize(timeout: number = null) {
|
||||
if (!!timeout) {
|
||||
if (typeof timeout === 'number' && timeout >= 0) {
|
||||
setTimeout(() => {
|
||||
this._initialize();
|
||||
this.sendLayoutWidthEvent();
|
||||
}, timeout);
|
||||
} else {
|
||||
this._initialize();
|
||||
this.sendLayoutWidthEvent();
|
||||
}
|
||||
this.sendLayoutWidthEvent();
|
||||
}
|
||||
|
||||
private _initialize() {
|
||||
this.openviduLayout = new OpenViduLayout();
|
||||
this.openviduLayoutOptions = this.getOptions();
|
||||
this.openviduLayout.initLayoutContainer(document.getElementById('layout'), this.openviduLayoutOptions);
|
||||
const element = document.getElementById('layout');
|
||||
this.openviduLayout.initLayoutContainer(element, this.openviduLayoutOptions);
|
||||
}
|
||||
|
||||
getOptions(): OpenViduLayoutOptions {
|
||||
private getOptions(): OpenViduLayoutOptions {
|
||||
const options = {
|
||||
maxRatio: 3 / 2, // The narrowest ratio that will be used (default 2x3)
|
||||
minRatio: 9 / 16, // The widest ratio that will be used (default 16x9)
|
||||
|
@ -51,16 +53,17 @@ export class LayoutService {
|
|||
return options;
|
||||
}
|
||||
|
||||
update(timeout?: number) {
|
||||
if (!!this.openviduLayout) {
|
||||
if (!timeout) {
|
||||
update(timeout: number = null) {
|
||||
const updateAux = () => {
|
||||
if (!!this.openviduLayout) {
|
||||
this.openviduLayout.updateLayout();
|
||||
} else {
|
||||
setTimeout(() => {
|
||||
this.openviduLayout.updateLayout();
|
||||
}, timeout);
|
||||
this.sendLayoutWidthEvent();
|
||||
}
|
||||
this.sendLayoutWidthEvent();
|
||||
};
|
||||
if (typeof timeout === 'number' && timeout >= 0) {
|
||||
setTimeout(() => updateAux(), timeout);
|
||||
} else {
|
||||
updateAux();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,10 +77,10 @@ export class LayoutService {
|
|||
|
||||
private sendLayoutWidthEvent() {
|
||||
const sidenavLayoutElement = this.documentService.getHTMLElementByClassName(
|
||||
this.openviduLayout.getLayoutContainer(),
|
||||
this.openviduLayout?.getLayoutContainer(),
|
||||
LayoutClass.SIDENAV_CONTAINER
|
||||
);
|
||||
if(sidenavLayoutElement && sidenavLayoutElement.clientWidth) {
|
||||
if (sidenavLayoutElement && sidenavLayoutElement.clientWidth) {
|
||||
this._layoutWidthObs.next(sidenavLayoutElement.clientWidth);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,4 +73,11 @@ $openvidu-components-theme: mat.define-light-theme((
|
|||
}
|
||||
|
||||
html, body { height: 100%; overflow: hidden;}
|
||||
body { margin: 0; font-family: 'Roboto','RobotoDraft',Helvetica,Arial,sans-serif;}
|
||||
body { margin: 0; font-family: 'Roboto','RobotoDraft',Helvetica,Arial,sans-serif;}
|
||||
|
||||
#poster-text {
|
||||
padding: 0px !important;
|
||||
}
|
||||
ov-chat-panel .text-info {
|
||||
margin: 3px auto !important;
|
||||
}
|
|
@ -5,23 +5,23 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
|
|||
|
||||
import { OpenviduWebComponentComponent } from './openvidu-webcomponent.component';
|
||||
|
||||
import { OpenviduAngularModule, VideoconferenceComponent } from 'openvidu-angular';
|
||||
import { OpenViduAngularModule, VideoconferenceComponent } from 'openvidu-angular';
|
||||
import { environment } from '../../environments/environment';
|
||||
|
||||
import { createCustomElement } from '@angular/elements';
|
||||
|
||||
@NgModule({
|
||||
declarations: [OpenviduWebComponentComponent],
|
||||
imports: [CommonModule, BrowserModule, BrowserAnimationsModule, OpenviduAngularModule.forRoot(environment)],
|
||||
imports: [CommonModule, BrowserModule, BrowserAnimationsModule, OpenViduAngularModule.forRoot(environment)],
|
||||
// exports: [OpenviduWebComponentComponent],
|
||||
providers: [{ provide: APP_BASE_HREF, useValue: '/' }, VideoconferenceComponent]
|
||||
providers: [{ provide: APP_BASE_HREF, useValue: '/' }, VideoconferenceComponent],
|
||||
})
|
||||
export class OpenviduWebComponentModule implements DoBootstrap {
|
||||
constructor(private injector: Injector) {}
|
||||
|
||||
ngDoBootstrap(): void {
|
||||
const element = createCustomElement(OpenviduWebComponentComponent, {
|
||||
injector: this.injector
|
||||
injector: this.injector,
|
||||
});
|
||||
|
||||
customElements.define('openvidu-webcomponent', element);
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
export const environment = {
|
||||
production: true
|
||||
production: true,
|
||||
// The webcomponent build will use this environment.
|
||||
// Wee need this flag for settings a delay in the layout for correct behaviour
|
||||
webcomponent: true
|
||||
};
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
// The list of file replacements can be found in `angular.json`.
|
||||
|
||||
export const environment = {
|
||||
production: false
|
||||
production: false,
|
||||
webcomponent: true
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue