mirror of https://github.com/OpenVidu/openvidu.git
openvidu-components: Refactored panel service
parent
87f43537d2
commit
9bcb55d4d8
|
@ -16,7 +16,7 @@ export class PanelService {
|
|||
private isExternalOpened: boolean = false;
|
||||
private externalType: string;
|
||||
protected _panelOpened = <BehaviorSubject<PanelEvent>>new BehaviorSubject({ opened: false });
|
||||
private panelMap: Map<string, boolean> = new Map();
|
||||
private panelTypes: string[] = Object.values(PanelType);
|
||||
|
||||
/**
|
||||
* @internal
|
||||
|
@ -24,7 +24,6 @@ export class PanelService {
|
|||
constructor(protected loggerSrv: LoggerService) {
|
||||
this.log = this.loggerSrv.get('PanelService');
|
||||
this.panelOpenedObs = this._panelOpened.asObservable();
|
||||
Object.values(PanelType).forEach((panel) => this.panelMap.set(panel, false));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -33,31 +32,22 @@ export class PanelService {
|
|||
*/
|
||||
togglePanel(type: PanelType | string, expand?: PanelSettingsOptions | string) {
|
||||
let nextOpenedValue: boolean = false;
|
||||
if (this.panelMap.has(type)) {
|
||||
const oldType = this._panelOpened.getValue().type;
|
||||
const oldOpened = this._panelOpened.getValue().opened;
|
||||
|
||||
if (this.panelTypes.includes(type)) {
|
||||
this.log.d(`Toggling ${type} menu`);
|
||||
|
||||
this.panelMap.forEach((opened: boolean, panel: string) => {
|
||||
if (panel === type) {
|
||||
// Toggle panel
|
||||
this.panelMap.set(panel, !opened);
|
||||
nextOpenedValue = !opened;
|
||||
} else {
|
||||
// Close others
|
||||
this.panelMap.set(panel, false);
|
||||
}
|
||||
});
|
||||
nextOpenedValue = oldType !== type ? true : !oldOpened;
|
||||
} else {
|
||||
// Panel is external
|
||||
this.log.d('Toggling external panel');
|
||||
// Close all panels
|
||||
this.panelMap.forEach((_, panel: string) => this.panelMap.set(panel, false));
|
||||
// Opening when external panel is closed or is opened with another type
|
||||
this.isExternalOpened = !this.isExternalOpened || this.externalType !== type;
|
||||
this.externalType = !this.isExternalOpened ? '' : type;
|
||||
nextOpenedValue = this.isExternalOpened;
|
||||
}
|
||||
|
||||
const oldType = this._panelOpened.getValue().type;
|
||||
this._panelOpened.next({ opened: nextOpenedValue, type, expand, oldType });
|
||||
}
|
||||
|
||||
|
@ -65,51 +55,54 @@ export class PanelService {
|
|||
* @internal
|
||||
*/
|
||||
isPanelOpened(): boolean {
|
||||
const anyOpened = Array.from(this.panelMap.values()).some((opened) => opened);
|
||||
return anyOpened || this.isExternalPanelOpened();
|
||||
return this._panelOpened.getValue().opened;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes the panel (if opened)
|
||||
*/
|
||||
closePanel(): void {
|
||||
this.panelMap.forEach((_, panel: string) => this.panelMap.set(panel, false));
|
||||
this._panelOpened.next({ opened: false });
|
||||
this._panelOpened.next({ opened: false, type: undefined, expand: undefined, oldType: undefined });
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the chat panel is opened or not.
|
||||
*/
|
||||
isChatPanelOpened(): boolean {
|
||||
return !!this.panelMap.get(PanelType.CHAT);
|
||||
const panelState = this._panelOpened.getValue();
|
||||
return panelState.opened && panelState.type === PanelType.CHAT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the participants panel is opened or not.
|
||||
*/
|
||||
isParticipantsPanelOpened(): boolean {
|
||||
return !!this.panelMap.get(PanelType.PARTICIPANTS);
|
||||
const panelState = this._panelOpened.getValue();
|
||||
return panelState.opened && panelState.type === PanelType.PARTICIPANTS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the activities panel is opened or not.
|
||||
*/
|
||||
isActivitiesPanelOpened(): boolean {
|
||||
return !!this.panelMap.get(PanelType.ACTIVITIES);
|
||||
const panelState = this._panelOpened.getValue();
|
||||
return panelState.opened && panelState.type === PanelType.ACTIVITIES;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the settings panel is opened or not.
|
||||
*/
|
||||
isSettingsPanelOpened(): boolean {
|
||||
return !!this.panelMap.get(PanelType.SETTINGS);
|
||||
const panelState = this._panelOpened.getValue();
|
||||
return panelState.opened && panelState.type === PanelType.SETTINGS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the background effects panel is opened or not.
|
||||
*/
|
||||
isBackgroundEffectsPanelOpened(): boolean {
|
||||
return !!this.panelMap.get(PanelType.BACKGROUND_EFFECTS);
|
||||
const panelState = this._panelOpened.getValue();
|
||||
return panelState.opened && panelState.type === PanelType.BACKGROUND_EFFECTS;
|
||||
}
|
||||
|
||||
isExternalPanelOpened(): boolean {
|
||||
|
|
Loading…
Reference in New Issue