2022-02-23 12:13:28 +01:00
|
|
|
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, ContentChild, OnInit, TemplateRef } from '@angular/core';
|
2022-02-03 17:08:23 +01:00
|
|
|
import { skip, Subscription } from 'rxjs';
|
2022-03-07 15:50:27 +01:00
|
|
|
import { ChatPanelDirective, ParticipantsPanelDirective } from '../../directives/template/openvidu-angular.directive';
|
2022-02-03 17:08:23 +01:00
|
|
|
import { MenuType } from '../../models/menu.model';
|
|
|
|
import { SidenavMenuService } from '../../services/sidenav-menu/sidenav-menu.service';
|
2022-02-02 13:42:33 +01:00
|
|
|
|
|
|
|
@Component({
|
2022-02-03 17:08:23 +01:00
|
|
|
selector: 'ov-panel',
|
|
|
|
templateUrl: './panel.component.html',
|
2022-02-23 12:13:28 +01:00
|
|
|
styleUrls: ['./panel.component.css'],
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
2022-02-02 13:42:33 +01:00
|
|
|
})
|
|
|
|
export class PanelComponent implements OnInit {
|
2022-02-03 17:08:23 +01:00
|
|
|
@ContentChild('participantsPanel', { read: TemplateRef }) participantsPanelTemplate: TemplateRef<any>;
|
|
|
|
@ContentChild('chatPanel', { read: TemplateRef }) chatPanelTemplate: TemplateRef<any>;
|
2022-02-02 13:42:33 +01:00
|
|
|
|
2022-02-17 17:26:30 +01:00
|
|
|
@ContentChild(ParticipantsPanelDirective)
|
|
|
|
set externalParticipantPanel(externalParticipantsPanel: ParticipantsPanelDirective) {
|
|
|
|
// This directive will has value only when PARTICIPANTS PANEL component tagged with '*ovParticipantsPanel'
|
|
|
|
// is inside of the PANEL component tagged with '*ovPanel'
|
|
|
|
if (externalParticipantsPanel) {
|
|
|
|
this.participantsPanelTemplate = externalParticipantsPanel.template;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@ContentChild(ChatPanelDirective)
|
|
|
|
set externalChatPanel(externalChatPanel: ChatPanelDirective) {
|
|
|
|
// This directive will has value only when CHAT PANEL component tagged with '*ovChatPanel'
|
|
|
|
// is inside of the PANEL component tagged with '*ovPanel'
|
|
|
|
if (externalChatPanel) {
|
|
|
|
this.chatPanelTemplate = externalChatPanel.template;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-03 17:08:23 +01:00
|
|
|
isParticipantsPanelOpened: boolean;
|
|
|
|
isChatPanelOpened: boolean;
|
|
|
|
menuSubscription: Subscription;
|
2022-02-23 12:13:28 +01:00
|
|
|
constructor(protected menuService: SidenavMenuService, private cd: ChangeDetectorRef) {}
|
2022-02-02 13:42:33 +01:00
|
|
|
|
2022-02-03 17:08:23 +01:00
|
|
|
ngOnInit(): void {
|
|
|
|
this.subscribeToPanelToggling();
|
|
|
|
}
|
|
|
|
subscribeToPanelToggling() {
|
|
|
|
this.menuSubscription = this.menuService.menuOpenedObs.pipe(skip(1)).subscribe((ev: { opened: boolean; type?: MenuType }) => {
|
|
|
|
this.isChatPanelOpened = ev.opened && ev.type === MenuType.CHAT;
|
|
|
|
this.isParticipantsPanelOpened = ev.opened && ev.type === MenuType.PARTICIPANTS;
|
2022-02-23 12:13:28 +01:00
|
|
|
this.cd.markForCheck();
|
2022-02-03 17:08:23 +01:00
|
|
|
});
|
|
|
|
}
|
2022-02-02 13:42:33 +01:00
|
|
|
|
2022-02-03 17:08:23 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
this.isChatPanelOpened = false;
|
|
|
|
this.isParticipantsPanelOpened = false;
|
|
|
|
if (this.menuSubscription) this.menuSubscription.unsubscribe();
|
|
|
|
}
|
2022-02-02 13:42:33 +01:00
|
|
|
}
|