2022-11-14 16:17:51 +00:00
|
|
|
import { Component, HostListener, OnInit } from '@angular/core';
|
2021-01-03 18:05:10 +00:00
|
|
|
import { MatDialog } from '@angular/material/dialog';
|
|
|
|
import { MatSlideToggleChange } from '@angular/material/slide-toggle';
|
2019-11-07 18:02:26 +00:00
|
|
|
|
2018-08-22 20:04:41 +00:00
|
|
|
import { State } from './responses';
|
2022-11-14 16:17:51 +00:00
|
|
|
import { OpenLPService, WebSocketStatus } from './openlp.service';
|
2022-02-10 22:16:36 +00:00
|
|
|
import { WindowRef } from './window-ref.service';
|
2019-11-07 18:02:26 +00:00
|
|
|
import { PageTitleService } from './page-title.service';
|
2019-10-08 05:43:49 +00:00
|
|
|
import { LoginComponent } from './components/login/login.component';
|
2022-11-14 16:17:51 +00:00
|
|
|
import { fromEvent } from 'rxjs';
|
|
|
|
import { debounceTime } from 'rxjs/operators';
|
2022-02-10 22:16:36 +00:00
|
|
|
// import { version } from '../../package.json';
|
2018-08-07 11:51:51 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'app-root',
|
|
|
|
templateUrl: './app.component.html',
|
2018-08-19 20:37:53 +00:00
|
|
|
styleUrls: ['./app.component.scss']
|
2018-08-07 11:51:51 +00:00
|
|
|
})
|
2019-10-08 05:43:49 +00:00
|
|
|
export class AppComponent implements OnInit {
|
2020-05-09 07:02:05 +00:00
|
|
|
private _fastSwitching = false;
|
2019-10-08 05:43:49 +00:00
|
|
|
state = new State();
|
|
|
|
showLogin = false;
|
2019-11-07 18:02:26 +00:00
|
|
|
pageTitle = 'OpenLP Remote';
|
2022-02-10 22:16:36 +00:00
|
|
|
appVersion = '0.0';
|
2022-11-14 16:17:51 +00:00
|
|
|
webSocketOpen = false;
|
2018-08-19 20:37:53 +00:00
|
|
|
|
2019-11-07 18:02:26 +00:00
|
|
|
constructor(private pageTitleService: PageTitleService, private openlpService: OpenLPService,
|
2022-02-10 22:16:36 +00:00
|
|
|
private dialog: MatDialog, private windowRef: WindowRef) {
|
2019-11-07 18:02:26 +00:00
|
|
|
pageTitleService.pageTitleChanged$.subscribe(pageTitle => this.pageTitle = pageTitle);
|
2018-08-19 20:37:53 +00:00
|
|
|
openlpService.stateChanged$.subscribe(item => this.state = item);
|
2022-11-14 16:17:51 +00:00
|
|
|
openlpService.webSocketStateChanged$.subscribe(status => this.webSocketOpen = status === WebSocketStatus.Open);
|
2022-02-10 22:16:36 +00:00
|
|
|
this.appVersion = windowRef.nativeWindow.appVersion || '0.0';
|
2022-11-14 16:17:51 +00:00
|
|
|
this.webSocketOpen = openlpService.webSocketStatus === WebSocketStatus.Open;
|
|
|
|
// Try to force websocket reconnection as user is now focused on window and will try to interact soon
|
|
|
|
// Adding a debounce to avoid event flooding
|
|
|
|
fromEvent(window, 'focus')
|
|
|
|
.pipe(debounceTime(300))
|
|
|
|
.subscribe(() => this.forceWebSocketReconnection());
|
2018-08-19 20:37:53 +00:00
|
|
|
}
|
2019-10-06 00:28:36 +00:00
|
|
|
|
2019-10-08 05:43:49 +00:00
|
|
|
ngOnInit(): void {
|
|
|
|
this.openlpService.retrieveSystemInformation().subscribe(res => this.showLogin = res.login_required);
|
|
|
|
}
|
|
|
|
|
2020-05-09 07:02:05 +00:00
|
|
|
get fastSwitching(): boolean {
|
|
|
|
if (localStorage.getItem('OpenLP-fastSwitching')) {
|
|
|
|
this._fastSwitching = JSON.parse(localStorage.getItem('OpenLP-fastSwitching'));
|
|
|
|
}
|
|
|
|
return this._fastSwitching;
|
|
|
|
}
|
|
|
|
|
|
|
|
set fastSwitching(value: boolean) {
|
|
|
|
this._fastSwitching = value;
|
|
|
|
localStorage.setItem('OpenLP-fastSwitching', JSON.stringify(value));
|
|
|
|
}
|
|
|
|
|
2019-10-08 05:43:49 +00:00
|
|
|
login() {
|
|
|
|
const dialogRef = this.dialog.open(LoginComponent, {
|
|
|
|
width: '250px'
|
|
|
|
});
|
|
|
|
|
|
|
|
dialogRef.afterClosed().subscribe(result => {
|
|
|
|
if (result) {
|
|
|
|
this.showLogin = false;
|
|
|
|
this.openlpService.setAuthToken(result.token);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-08-19 20:37:53 +00:00
|
|
|
nextItem() {
|
2019-10-06 00:28:36 +00:00
|
|
|
this.openlpService.nextItem().subscribe();
|
2018-08-19 20:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
previousItem() {
|
2019-10-06 00:28:36 +00:00
|
|
|
this.openlpService.previousItem().subscribe();
|
2018-08-19 20:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nextSlide() {
|
2019-10-06 00:28:36 +00:00
|
|
|
this.openlpService.nextSlide().subscribe();
|
2018-08-19 20:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
previousSlide() {
|
2019-10-06 00:28:36 +00:00
|
|
|
this.openlpService.previousSlide().subscribe();
|
2018-08-19 20:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
blankDisplay() {
|
2019-10-06 00:28:36 +00:00
|
|
|
this.openlpService.blankDisplay().subscribe();
|
2018-08-19 20:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
themeDisplay() {
|
2019-10-06 00:28:36 +00:00
|
|
|
this.openlpService.themeDisplay().subscribe();
|
2018-08-19 20:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
desktopDisplay() {
|
2019-10-06 00:28:36 +00:00
|
|
|
this.openlpService.desktopDisplay().subscribe();
|
2018-08-19 20:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
showDisplay() {
|
2019-10-06 00:28:36 +00:00
|
|
|
this.openlpService.showDisplay().subscribe();
|
2018-08-19 20:37:53 +00:00
|
|
|
}
|
|
|
|
|
2018-08-27 18:21:35 +00:00
|
|
|
sliderChanged(event: MatSlideToggleChange) {
|
|
|
|
this.fastSwitching = event.checked;
|
|
|
|
}
|
2022-11-14 16:17:51 +00:00
|
|
|
|
|
|
|
forceWebSocketReconnection() {
|
|
|
|
this.openlpService.reconnectWebSocketIfNeeded();
|
|
|
|
}
|
2018-08-07 11:51:51 +00:00
|
|
|
}
|