mirror of https://github.com/OpenVidu/openvidu.git
openvidu-components: Refactored panel service
parent
4cef8c3fac
commit
aa0c78b882
|
@ -72,7 +72,7 @@ export class ChatPanelComponent implements OnInit, AfterViewInit {
|
|||
*/
|
||||
@HostListener('document:keydown.escape', ['$event'])
|
||||
onKeydownHandler(event: KeyboardEvent) {
|
||||
if (this.PanelService.isMenuOpened()) {
|
||||
if (this.PanelService.isPanelOpened()) {
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
@ -119,13 +119,13 @@ export class ChatPanelComponent implements OnInit, AfterViewInit {
|
|||
}
|
||||
|
||||
close() {
|
||||
this.PanelService.toggleMenu(MenuType.CHAT);
|
||||
this.PanelService.togglePanel(MenuType.CHAT);
|
||||
}
|
||||
|
||||
private subscribeToMessages() {
|
||||
this.chatMessageSubscription = this.chatService.messagesObs.subscribe((messages: ChatMessage[]) => {
|
||||
this.messageList = messages;
|
||||
if (this.PanelService.isMenuOpened()) {
|
||||
if (this.PanelService.isPanelOpened()) {
|
||||
this.scrollToBottom();
|
||||
this.cd.markForCheck();
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ export class PanelComponent implements OnInit {
|
|||
}
|
||||
|
||||
private subscribeToPanelToggling() {
|
||||
this.menuSubscription = this.panelService.menuOpenedObs.pipe(skip(1)).subscribe((ev: { opened: boolean; type?: MenuType }) => {
|
||||
this.menuSubscription = this.panelService.panelOpenedObs.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;
|
||||
this.cd.markForCheck();
|
||||
|
|
|
@ -153,7 +153,7 @@ export class SessionComponent implements OnInit {
|
|||
this.updateLayoutInterval = setInterval(() => this.layoutService.update(), 50);
|
||||
});
|
||||
|
||||
this.menuSubscription = this.panelService.menuOpenedObs.pipe(skip(1)).subscribe((ev: { opened: boolean; type?: MenuType }) => {
|
||||
this.menuSubscription = this.panelService.panelOpenedObs.pipe(skip(1)).subscribe((ev: { opened: boolean; type?: MenuType }) => {
|
||||
if (this.sideMenu) {
|
||||
this.isChatPanelOpened = ev.opened && ev.type === MenuType.CHAT;
|
||||
this.isParticipantsPanelOpened = ev.opened && ev.type === MenuType.PARTICIPANTS;
|
||||
|
|
|
@ -340,7 +340,7 @@ export class ToolbarComponent implements OnInit, OnDestroy {
|
|||
*/
|
||||
toggleParticipantsPanel() {
|
||||
this.onParticipantsPanelButtonClicked.emit();
|
||||
this.panelService.toggleMenu(MenuType.PARTICIPANTS);
|
||||
this.panelService.togglePanel(MenuType.PARTICIPANTS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -348,7 +348,7 @@ export class ToolbarComponent implements OnInit, OnDestroy {
|
|||
*/
|
||||
toggleChatPanel() {
|
||||
this.onChatPanelButtonClicked.emit();
|
||||
this.panelService.toggleMenu(MenuType.CHAT);
|
||||
this.panelService.togglePanel(MenuType.CHAT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -362,7 +362,7 @@ export class ToolbarComponent implements OnInit, OnDestroy {
|
|||
|
||||
protected subscribeToReconnection() {
|
||||
this.session.on('reconnecting', () => {
|
||||
if (this.panelService.isMenuOpened()) {
|
||||
if (this.panelService.isPanelOpened()) {
|
||||
this.panelService.closeMenu();
|
||||
}
|
||||
this.isConnectionLost = true;
|
||||
|
@ -372,7 +372,7 @@ export class ToolbarComponent implements OnInit, OnDestroy {
|
|||
});
|
||||
}
|
||||
protected subscribeToMenuToggling() {
|
||||
this.menuTogglingSubscription = this.panelService.menuOpenedObs.subscribe((ev: { opened: boolean; type?: MenuType }) => {
|
||||
this.menuTogglingSubscription = this.panelService.panelOpenedObs.subscribe((ev: { opened: boolean; type?: MenuType }) => {
|
||||
this.isChatOpened = ev.opened && ev.type === MenuType.CHAT;
|
||||
this.isParticipantsOpened = ev.opened && ev.type === MenuType.PARTICIPANTS;
|
||||
if (this.isChatOpened) {
|
||||
|
@ -383,7 +383,7 @@ export class ToolbarComponent implements OnInit, OnDestroy {
|
|||
|
||||
protected subscribeToChatMessages() {
|
||||
this.chatMessagesSubscription = this.chatService.messagesObs.pipe(skip(1)).subscribe((messages) => {
|
||||
if (!this.panelService.isMenuOpened()) {
|
||||
if (!this.panelService.isPanelOpened()) {
|
||||
this.unreadMessages++;
|
||||
}
|
||||
this.messageList = messages;
|
||||
|
|
|
@ -50,7 +50,7 @@ export class ChatService {
|
|||
nickname: data.nickname,
|
||||
message: data.message
|
||||
});
|
||||
if (!this.panelService.isMenuOpened()) {
|
||||
if (!this.panelService.isPanelOpened()) {
|
||||
const notificationOptions: INotificationOptions = {
|
||||
message: `${data.nickname.toUpperCase()} sent a message`,
|
||||
cssClassName: 'messageSnackbar',
|
||||
|
@ -77,6 +77,6 @@ export class ChatService {
|
|||
}
|
||||
|
||||
protected launchNotification(options: INotificationOptions) {
|
||||
this.actionService.launchNotification(options, this.panelService.toggleMenu.bind(this.panelService, MenuType.CHAT));
|
||||
this.actionService.launchNotification(options, this.panelService.togglePanel.bind(this.panelService, MenuType.CHAT));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,59 +11,59 @@ import { LoggerService } from '../logger/logger.service';
|
|||
providedIn: 'root'
|
||||
})
|
||||
export class PanelService {
|
||||
menuOpenedObs: Observable<{ opened: boolean; type?: MenuType }>;
|
||||
panelOpenedObs: Observable<{ opened: boolean; type?: MenuType }>;
|
||||
protected log: ILogger;
|
||||
protected isChatMenuOpened: boolean = false;
|
||||
protected isParticipantsMenuOpened: boolean = false;
|
||||
protected _menuOpened = <BehaviorSubject<{ opened: boolean; type?: MenuType }>>new BehaviorSubject({ opened: false });
|
||||
protected isChatPanelOpened: boolean = false;
|
||||
protected isParticipantsPanelOpened: boolean = false;
|
||||
protected _panelOpened = <BehaviorSubject<{ opened: boolean; type?: MenuType }>>new BehaviorSubject({ opened: false });
|
||||
|
||||
constructor(protected loggerSrv: LoggerService) {
|
||||
this.log = this.loggerSrv.get('PanelService');
|
||||
this.menuOpenedObs = this._menuOpened.asObservable();
|
||||
this.panelOpenedObs = this._panelOpened.asObservable();
|
||||
}
|
||||
|
||||
isMenuOpened(): boolean {
|
||||
isPanelOpened(): boolean {
|
||||
return this.isChatOpened() || this.isParticipantsOpened();
|
||||
}
|
||||
|
||||
toggleMenu(type: MenuType) {
|
||||
togglePanel(type: MenuType) {
|
||||
this.log.d(`Toggling ${type} menu`);
|
||||
if (type === MenuType.CHAT) {
|
||||
if (this.isChatMenuOpened) {
|
||||
if (this.isChatPanelOpened) {
|
||||
// Close chat and side menu
|
||||
this.isChatMenuOpened = false;
|
||||
this._menuOpened.next({ opened: false });
|
||||
this.isChatPanelOpened = false;
|
||||
this._panelOpened.next({ opened: false });
|
||||
} else {
|
||||
// Open chat
|
||||
this.isChatMenuOpened = true;
|
||||
this.isParticipantsMenuOpened = false;
|
||||
this._menuOpened.next({ opened: true, type: MenuType.CHAT });
|
||||
this.isChatPanelOpened = true;
|
||||
this.isParticipantsPanelOpened = false;
|
||||
this._panelOpened.next({ opened: true, type: MenuType.CHAT });
|
||||
}
|
||||
} else if (type === MenuType.PARTICIPANTS) {
|
||||
if (this.isParticipantsMenuOpened) {
|
||||
if (this.isParticipantsPanelOpened) {
|
||||
// Close participants menu and side menu
|
||||
this.isParticipantsMenuOpened = false;
|
||||
this._menuOpened.next({ opened: false });
|
||||
this.isParticipantsPanelOpened = false;
|
||||
this._panelOpened.next({ opened: false });
|
||||
} else {
|
||||
// Open participants menu
|
||||
this.isParticipantsMenuOpened = true;
|
||||
this.isChatMenuOpened = false;
|
||||
this._menuOpened.next({ opened: true, type: MenuType.PARTICIPANTS });
|
||||
this.isParticipantsPanelOpened = true;
|
||||
this.isChatPanelOpened = false;
|
||||
this._panelOpened.next({ opened: true, type: MenuType.PARTICIPANTS });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closeMenu() {
|
||||
this.isParticipantsMenuOpened = false;
|
||||
this.isChatMenuOpened = false;
|
||||
this._menuOpened.next({ opened: false });
|
||||
this.isParticipantsPanelOpened = false;
|
||||
this.isChatPanelOpened = false;
|
||||
this._panelOpened.next({ opened: false });
|
||||
}
|
||||
|
||||
isChatOpened() {
|
||||
return this.isChatMenuOpened;
|
||||
return this.isChatPanelOpened;
|
||||
}
|
||||
|
||||
isParticipantsOpened() {
|
||||
return this.isParticipantsMenuOpened;
|
||||
return this.isParticipantsPanelOpened;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue