mirror of
https://gitlab.com/openlp/web-remote.git
synced 2024-12-22 03:22:48 +00:00
Merge branch 'master' into settings-section
This commit is contained in:
commit
31c6736c54
@ -15,14 +15,54 @@ export class ChordViewComponent extends StageViewComponent {
|
||||
// current songs transpose level
|
||||
transposeLevel = 0;
|
||||
stageProperty = 'chords';
|
||||
currentSlide = 0;
|
||||
useNewTransposeEndpoint = this.openlpService.assertApiVersionMinimum(2, 2);
|
||||
|
||||
updateCurrentSlides(serviceItemId: string, currentSlide: number): void {
|
||||
this.currentSlide = currentSlide;
|
||||
this.useNewTransposeEndpoint = this.openlpService.assertApiVersionMinimum(2, 2);
|
||||
this.serviceItemSubscription$?.unsubscribe();
|
||||
const newServiceItemTransposeLevel = this.songTransposeMap.get(serviceItemId);
|
||||
|
||||
setNewSlides(slides: Slide[]): void {
|
||||
super.setNewSlides(slides);
|
||||
if (this.useNewTransposeEndpoint && newServiceItemTransposeLevel && (newServiceItemTransposeLevel !== 0)) {
|
||||
this.transposeLevel = newServiceItemTransposeLevel;
|
||||
this.serviceItemSubscription$ = this.openlpService
|
||||
.transposeSong(newServiceItemTransposeLevel, 'service_item')
|
||||
.subscribe(serviceItem => {
|
||||
this.serviceItem = serviceItem;
|
||||
if (serviceItem instanceof Array) {
|
||||
this.setNewSlides(serviceItem, currentSlide);
|
||||
}
|
||||
else {
|
||||
this.setNewSlides(serviceItem.slides, currentSlide);
|
||||
this.setNotes(serviceItem.notes);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (this.useNewTransposeEndpoint) {
|
||||
this.songTransposeMap.set(serviceItemId, 0);
|
||||
this.transposeLevel = 0;
|
||||
}
|
||||
super.updateCurrentSlides(serviceItemId, currentSlide);
|
||||
}
|
||||
}
|
||||
|
||||
setNewSlides(slides: Slide[], currentSlide: number): void {
|
||||
if (this.openlpService.assertApiVersionExact(2, 2)) {
|
||||
// API Version 2.2 released on OpenLP 3.0.2 contains a bug on which 'selected' is not set correctly
|
||||
// on Transponse Service Item response.
|
||||
if (slides[currentSlide]) {
|
||||
slides[currentSlide].selected = true;
|
||||
}
|
||||
}
|
||||
super.setNewSlides(slides, currentSlide);
|
||||
// if this song is already known
|
||||
if (this.songTransposeMap.has(this.serviceItem.id)) {
|
||||
if (this.songTransposeMap.get(this.serviceItem.id) !== 0) {
|
||||
this.transposeChords();
|
||||
const transposeLevel = this.songTransposeMap.get(this.serviceItem.id);
|
||||
if (transposeLevel) {
|
||||
if (!this.useNewTransposeEndpoint) {
|
||||
this.transposeChords();
|
||||
}
|
||||
} else {
|
||||
this.transposeLevel = this.songTransposeMap.get(this.serviceItem.id);
|
||||
}
|
||||
@ -56,7 +96,15 @@ export class ChordViewComponent extends StageViewComponent {
|
||||
transposeChords(): void {
|
||||
const tmpTranspose = this.songTransposeMap.get(this.serviceItem.id);
|
||||
this.transposeLevel = tmpTranspose;
|
||||
this.openlpService.transposeSong(tmpTranspose).subscribe(transposedLyrics => {
|
||||
if (this.useNewTransposeEndpoint) {
|
||||
this.updateCurrentSlides(this.serviceItem.id, this.currentSlide);
|
||||
} else {
|
||||
this.transposeChordsLegacy(tmpTranspose);
|
||||
}
|
||||
}
|
||||
|
||||
transposeChordsLegacy(transposeLevel): void {
|
||||
this.openlpService.transposeSong(transposeLevel).subscribe(transposedLyrics => {
|
||||
// Replace the chords in the currentSlides with the returned transposed chords
|
||||
if (transposedLyrics instanceof Array) {
|
||||
for (let i = 0; i < transposedLyrics.length; ++i) {
|
||||
|
@ -26,7 +26,8 @@ export class StageViewComponent implements OnInit, OnDestroy {
|
||||
time = new Date();
|
||||
showNotes = true;
|
||||
fontScale: number;
|
||||
|
||||
|
||||
serviceItemSubscription$: Subscription = null;
|
||||
fontScaleSubscription$: Subscription;
|
||||
|
||||
stageProperty = 'stage';
|
||||
@ -41,8 +42,8 @@ export class StageViewComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.updateCurrentSlides();
|
||||
this.openlpService.stateChanged$.subscribe(item => this.updateCurrentSlides());
|
||||
this.updateCurrentSlides(null, null);
|
||||
this.openlpService.stateChanged$.subscribe(item => this.updateCurrentSlides(item.item, item.slide));
|
||||
this.fontScale = this.settingsService.get(
|
||||
this.stageProperty + 'FontScale' as keyof SettingsProperties
|
||||
) as number / 100;
|
||||
@ -59,14 +60,15 @@ export class StageViewComponent implements OnInit, OnDestroy {
|
||||
this.fontScaleSubscription$?.unsubscribe();
|
||||
}
|
||||
|
||||
updateCurrentSlides(): void {
|
||||
this.openlpService.getServiceItem().subscribe(serviceItem => {
|
||||
updateCurrentSlides(serviceItemId: string, currentSlide: number): void {
|
||||
this.serviceItemSubscription$?.unsubscribe();
|
||||
this.serviceItemSubscription$ = this.openlpService.getServiceItem().subscribe(serviceItem => {
|
||||
this.serviceItem = serviceItem;
|
||||
if (serviceItem instanceof Array) {
|
||||
this.setNewSlides(serviceItem);
|
||||
this.setNewSlides(serviceItem, currentSlide);
|
||||
}
|
||||
else {
|
||||
this.setNewSlides(serviceItem.slides);
|
||||
this.setNewSlides(serviceItem.slides, currentSlide);
|
||||
this.setNotes(serviceItem.notes);
|
||||
}
|
||||
});
|
||||
@ -76,7 +78,7 @@ export class StageViewComponent implements OnInit, OnDestroy {
|
||||
return this.currentSlides.slice(this.activeSlide + 1);
|
||||
}
|
||||
|
||||
setNewSlides(slides: Slide[]): void {
|
||||
setNewSlides(slides: Slide[], currentSlide: number): void {
|
||||
if (slides.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Injectable, EventEmitter } from '@angular/core';
|
||||
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { finalize, shareReplay } from 'rxjs/operators';
|
||||
import { finalize, shareReplay, tap } from 'rxjs/operators';
|
||||
|
||||
import {
|
||||
PluginDescription,
|
||||
@ -44,6 +44,8 @@ export enum WebSocketStatus {
|
||||
@Injectable()
|
||||
export class OpenLPService {
|
||||
private apiURL: string;
|
||||
public apiVersion: number | null;
|
||||
public apiRevision: number | null;
|
||||
private host: string;
|
||||
public stateChanged$: EventEmitter<State>;
|
||||
public webSocketStateChanged$: EventEmitter<WebSocketStatus>;
|
||||
@ -69,6 +71,14 @@ export class OpenLPService {
|
||||
this.createWebSocket();
|
||||
}
|
||||
|
||||
assertApiVersionExact(version: number, revision: number) {
|
||||
return version === this.apiVersion && revision === this.apiRevision;
|
||||
}
|
||||
|
||||
assertApiVersionMinimum(version: number, revision: number) {
|
||||
return this.apiVersion >= version && this.apiRevision >= revision;
|
||||
}
|
||||
|
||||
setAuthToken(token: string): void {
|
||||
httpOptions.headers = httpOptions.headers.set('Authorization', token);
|
||||
}
|
||||
@ -78,7 +88,13 @@ export class OpenLPService {
|
||||
}
|
||||
|
||||
retrieveSystemInformation(): Observable<SystemInformation> {
|
||||
return this.doGet<SystemInformation>(`${this.apiURL}/core/system`);
|
||||
return this.doGet<SystemInformation>(`${this.apiURL}/core/system`)
|
||||
.pipe(tap(systemInfo => {
|
||||
if (systemInfo.api_version) {
|
||||
this.apiVersion = systemInfo.api_version;
|
||||
this.apiRevision = systemInfo.api_revision;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
getMainImage(): Observable<MainView> {
|
||||
@ -185,8 +201,8 @@ export class OpenLPService {
|
||||
return this.doPost(`${this.apiURL}/plugins/${plugin}/add`, {id});
|
||||
}
|
||||
|
||||
transposeSong(transpose_value): Observable<any> {
|
||||
return this.doGet(`${this.apiURL}/plugins/songs/transpose-live-item/${transpose_value}`);
|
||||
transposeSong(transpose_value, return_format = 'default'): Observable<any> {
|
||||
return this.doGet(`${this.apiURL}/plugins/songs/transpose-live-item/${transpose_value}?response_format=${return_format}`);
|
||||
}
|
||||
|
||||
login(credentials: Credentials): Observable<AuthToken> {
|
||||
|
@ -12,6 +12,7 @@ export class State {
|
||||
blank: boolean;
|
||||
twelve: boolean;
|
||||
theme: boolean;
|
||||
item: string;
|
||||
|
||||
live = () => !(this.blank || this.display || this.theme);
|
||||
|
||||
@ -68,6 +69,8 @@ export interface MainView {
|
||||
export interface SystemInformation {
|
||||
websocket_port: number;
|
||||
login_required: boolean;
|
||||
api_version?: number;
|
||||
api_revision?: number;
|
||||
}
|
||||
|
||||
export interface Credentials {
|
||||
|
Loading…
Reference in New Issue
Block a user