2022-01-19 17:24:11 +01:00
import { Injectable } from '@angular/core' ;
import { BehaviorSubject , Observable } from 'rxjs' ;
import { LayoutClass , OpenViduLayout , OpenViduLayoutOptions } from '../../models/layout.model' ;
import { DocumentService } from '../document/document.service' ;
@Injectable ( {
providedIn : 'root'
} )
export class LayoutService {
layoutWidthObs : Observable < number > ;
private _layoutWidthObs : BehaviorSubject < number > = new BehaviorSubject ( 0 ) ;
private openviduLayout : OpenViduLayout ;
private openviduLayoutOptions : OpenViduLayoutOptions ;
constructor ( private documentService : DocumentService ) {
this . layoutWidthObs = this . _layoutWidthObs . asObservable ( ) ;
}
initialize ( timeout : number = null ) {
2022-03-09 12:34:10 +01:00
if ( typeof timeout === 'number' && timeout >= 0 ) {
2022-01-19 17:24:11 +01:00
setTimeout ( ( ) = > {
this . _initialize ( ) ;
2022-03-09 12:34:10 +01:00
this . sendLayoutWidthEvent ( ) ;
2022-01-19 17:24:11 +01:00
} , timeout ) ;
} else {
this . _initialize ( ) ;
2022-03-09 12:34:10 +01:00
this . sendLayoutWidthEvent ( ) ;
2022-01-19 17:24:11 +01:00
}
}
private _initialize() {
this . openviduLayout = new OpenViduLayout ( ) ;
this . openviduLayoutOptions = this . getOptions ( ) ;
2022-03-09 12:34:10 +01:00
const element = document . getElementById ( 'layout' ) ;
this . openviduLayout . initLayoutContainer ( element , this . openviduLayoutOptions ) ;
2022-01-19 17:24:11 +01:00
}
2022-03-09 12:34:10 +01:00
private getOptions ( ) : OpenViduLayoutOptions {
2022-01-19 17:24:11 +01:00
const options = {
maxRatio : 3 / 2 , // The narrowest ratio that will be used (default 2x3)
2022-02-14 10:41:55 +01:00
minRatio : 9 / 16 , // The widest ratio that will be used (default 16x9)
2022-01-19 17:24:11 +01:00
fixedRatio : false / * If this is true then the aspect ratio of the video is maintained
and minRatio and maxRatio are ignored ( default false ) * / ,
bigClass : LayoutClass.BIG_ELEMENT , // The class to add to elements that should be sized bigger
smallClass : LayoutClass.SMALL_ELEMENT ,
2022-03-23 11:51:28 +01:00
bigPercentage : 0.8 , // The maximum percentage of space the big ones should take up
2022-01-19 17:24:11 +01:00
bigFixedRatio : false , // fixedRatio for the big ones
2022-02-14 10:41:55 +01:00
bigMaxRatio : 9 / 16 , // The narrowest ratio to use for the big elements (default 2x3)
2022-01-19 17:24:11 +01:00
bigMinRatio : 9 / 16 , // The widest ratio to use for the big elements (default 16x9)
bigFirst : true , // Whether to place the big one in the top left (true) or bottom right
2022-02-24 13:02:00 +01:00
animate : true // Whether you want to animate the transitions. Deprecated property, to disable it remove the transaction property on OT_publisher css class
2022-01-19 17:24:11 +01:00
} ;
return options ;
}
2022-03-09 12:34:10 +01:00
update ( timeout : number = null ) {
const updateAux = ( ) = > {
if ( ! ! this . openviduLayout ) {
2022-01-19 17:24:11 +01:00
this . openviduLayout . updateLayout ( ) ;
2022-03-09 12:34:10 +01:00
this . sendLayoutWidthEvent ( ) ;
2022-01-19 17:24:11 +01:00
}
2022-03-09 12:34:10 +01:00
} ;
if ( typeof timeout === 'number' && timeout >= 0 ) {
setTimeout ( ( ) = > updateAux ( ) , timeout ) ;
} else {
updateAux ( ) ;
2022-01-19 17:24:11 +01:00
}
}
getLayout() {
return this . openviduLayout ;
}
clear() {
this . openviduLayout = null ;
}
private sendLayoutWidthEvent() {
const sidenavLayoutElement = this . documentService . getHTMLElementByClassName (
2022-03-09 12:34:10 +01:00
this . openviduLayout ? . getLayoutContainer ( ) ,
2022-01-19 17:24:11 +01:00
LayoutClass . SIDENAV_CONTAINER
) ;
2022-03-09 12:34:10 +01:00
if ( sidenavLayoutElement && sidenavLayoutElement . clientWidth ) {
2022-01-19 17:24:11 +01:00
this . _layoutWidthObs . next ( sidenavLayoutElement . clientWidth ) ;
}
}
}