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 isExternalOpened: boolean = false;
|
||||||
private externalType: string;
|
private externalType: string;
|
||||||
protected _panelOpened = <BehaviorSubject<PanelEvent>>new BehaviorSubject({ opened: false });
|
protected _panelOpened = <BehaviorSubject<PanelEvent>>new BehaviorSubject({ opened: false });
|
||||||
private panelMap: Map<string, boolean> = new Map();
|
private panelTypes: string[] = Object.values(PanelType);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
|
@ -24,7 +24,6 @@ export class PanelService {
|
||||||
constructor(protected loggerSrv: LoggerService) {
|
constructor(protected loggerSrv: LoggerService) {
|
||||||
this.log = this.loggerSrv.get('PanelService');
|
this.log = this.loggerSrv.get('PanelService');
|
||||||
this.panelOpenedObs = this._panelOpened.asObservable();
|
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) {
|
togglePanel(type: PanelType | string, expand?: PanelSettingsOptions | string) {
|
||||||
let nextOpenedValue: boolean = false;
|
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.log.d(`Toggling ${type} menu`);
|
||||||
|
|
||||||
this.panelMap.forEach((opened: boolean, panel: string) => {
|
nextOpenedValue = oldType !== type ? true : !oldOpened;
|
||||||
if (panel === type) {
|
|
||||||
// Toggle panel
|
|
||||||
this.panelMap.set(panel, !opened);
|
|
||||||
nextOpenedValue = !opened;
|
|
||||||
} else {
|
|
||||||
// Close others
|
|
||||||
this.panelMap.set(panel, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
// Panel is external
|
// Panel is external
|
||||||
this.log.d('Toggling external panel');
|
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
|
// Opening when external panel is closed or is opened with another type
|
||||||
this.isExternalOpened = !this.isExternalOpened || this.externalType !== type;
|
this.isExternalOpened = !this.isExternalOpened || this.externalType !== type;
|
||||||
this.externalType = !this.isExternalOpened ? '' : type;
|
this.externalType = !this.isExternalOpened ? '' : type;
|
||||||
nextOpenedValue = this.isExternalOpened;
|
nextOpenedValue = this.isExternalOpened;
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldType = this._panelOpened.getValue().type;
|
|
||||||
this._panelOpened.next({ opened: nextOpenedValue, type, expand, oldType });
|
this._panelOpened.next({ opened: nextOpenedValue, type, expand, oldType });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,51 +55,54 @@ export class PanelService {
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
isPanelOpened(): boolean {
|
isPanelOpened(): boolean {
|
||||||
const anyOpened = Array.from(this.panelMap.values()).some((opened) => opened);
|
return this._panelOpened.getValue().opened;
|
||||||
return anyOpened || this.isExternalPanelOpened();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes the panel (if opened)
|
* Closes the panel (if opened)
|
||||||
*/
|
*/
|
||||||
closePanel(): void {
|
closePanel(): void {
|
||||||
this.panelMap.forEach((_, panel: string) => this.panelMap.set(panel, false));
|
this._panelOpened.next({ opened: false, type: undefined, expand: undefined, oldType: undefined });
|
||||||
this._panelOpened.next({ opened: false });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the chat panel is opened or not.
|
* Whether the chat panel is opened or not.
|
||||||
*/
|
*/
|
||||||
isChatPanelOpened(): boolean {
|
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.
|
* Whether the participants panel is opened or not.
|
||||||
*/
|
*/
|
||||||
isParticipantsPanelOpened(): boolean {
|
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.
|
* Whether the activities panel is opened or not.
|
||||||
*/
|
*/
|
||||||
isActivitiesPanelOpened(): boolean {
|
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.
|
* Whether the settings panel is opened or not.
|
||||||
*/
|
*/
|
||||||
isSettingsPanelOpened(): boolean {
|
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.
|
* Whether the background effects panel is opened or not.
|
||||||
*/
|
*/
|
||||||
isBackgroundEffectsPanelOpened(): boolean {
|
isBackgroundEffectsPanelOpened(): boolean {
|
||||||
return !!this.panelMap.get(PanelType.BACKGROUND_EFFECTS);
|
const panelState = this._panelOpened.getValue();
|
||||||
|
return panelState.opened && panelState.type === PanelType.BACKGROUND_EFFECTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
isExternalPanelOpened(): boolean {
|
isExternalPanelOpened(): boolean {
|
||||||
|
|
Loading…
Reference in New Issue