-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathsession-toolbar.component.ts
More file actions
118 lines (98 loc) · 2.91 KB
/
session-toolbar.component.ts
File metadata and controls
118 lines (98 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { Component, ElementRef, HostListener, Input, Renderer2 } from '@angular/core';
import { UtilsService } from '@shared/services/utils.service';
@Component({
selector: 'session-toolbar',
templateUrl: 'session-toolbar.component.html',
styleUrls: ['session-toolbar.component.scss'],
})
export class SessionToolbarComponent {
@Input() sessionContainerParent: ElementRef;
@Input() leftButtons: {
label: string;
icon: string;
action: () => void;
}[] = [];
@Input() middleButtons: {
label: string;
icon: string;
action: () => void;
}[] = [];
@Input() middleToggleButtons: {
label: string;
icon: string;
action: () => void;
isActive: () => boolean;
}[] = [];
@Input() rightButtons: {
label: string;
icon: string;
action: () => void;
}[] = [];
@Input() checkboxes: {
label: string;
action: () => void;
isChecked: () => boolean;
}[] = [];
isFullScreenMode = false;
showToolbarDiv = true;
loading = true;
constructor(
private renderer: Renderer2,
protected utils: UtilsService,
) {}
@HostListener('document:mousemove', ['$event'])
onMouseMove(event: MouseEvent): void {
this.handleSessionToolbarDisplay(event);
}
@HostListener('document:fullscreenchange')
onFullScreenChange(): void {
this.handleOnFullScreenEvent();
}
private handleOnFullScreenEvent(): void {
if (!document.fullscreenElement) {
this.handleExitFullScreenEvent();
}
}
private handleSessionToolbarDisplay(event: MouseEvent): void {
if (!document.fullscreenElement) {
return;
}
if (event.clientY === 0) {
this.showToolbarDiv = true;
} else if (event.clientY > 44) {
this.showToolbarDiv = false;
}
}
toggleFullscreen(): void {
this.isFullScreenMode = !this.isFullScreenMode;
!document.fullscreenElement ? this.enterFullScreen() : this.exitFullScreen();
}
private async enterFullScreen(): Promise<void> {
if (document.fullscreenElement) {
return;
}
try {
const sessionContainerElement = this.sessionContainerParent.nativeElement;
await sessionContainerElement.requestFullscreen();
} catch (err) {
this.isFullScreenMode = false;
console.error(`Error attempting to enable fullscreen mode: ${err.message} (${err.name})`);
}
}
private exitFullScreen(): void {
if (document.fullscreenElement) {
document.exitFullscreen().catch((err) => {
console.error(`Error attempting to exit fullscreen: ${err}`);
});
}
}
private handleExitFullScreenEvent(): void {
this.isFullScreenMode = false;
this.showToolbarDiv = true;
const sessionContainerElement = this.sessionContainerParent.nativeElement;
const sessionToolbarElement = sessionContainerElement.querySelector('#sessionToolbar');
if (sessionToolbarElement) {
this.renderer.removeClass(sessionToolbarElement, 'session-toolbar-layer');
}
}
}