-
Notifications
You must be signed in to change notification settings - Fork 0
/
stage-bible.js
181 lines (142 loc) · 5.51 KB
/
stage-bible.js
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/******************************************************************************
* OpenLP - Open Source Lyrics Projection *
* --------------------------------------------------------------------------- *
* Copyright (c) 2008-2021 OpenLP Developers *
* --------------------------------------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the Free *
* Software Foundation; version 2 of the License. *
* *
* This program is distributed in the hope that it will be useful, but WITHOUT *
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *
* more details. *
* *
* You should have received a copy of the GNU General Public License along *
* with this program; if not, write to the Free Software Foundation, Inc., 59 *
* Temple Place, Suite 330, Boston, MA 02111-1307 USA *
******************************************************************************/
var intfadein = 300;
var intfadeout= 300;
window.OpenLP = { // Connect to the OpenLP Remote WebSocket to get pushed updates
myWebSocket: function (data, status) {
const host = window.location.hostname;
const websocket_port = 4317;
var curmode;
ws = new WebSocket(`ws://${host}:${websocket_port}`);
ws.onmessage = (event) => {
const reader = new FileReader();
reader.onload = () => {
data = JSON.parse(reader.result.toString()).results;
// set some global var
//set the displaymode
//This will determine if we show text.
OpenLP.curStatus = 'live';
//Showing Theme
curmode = data.theme;
if (curmode==true) {
OpenLP.curStatus = 'theme';
}
//Showing Desktop
curmode = data.display;
if (curmode==true) {
OpenLP.curStatus = 'display';
}
//Showing Black
curmode = data.blank;
if (curmode==true) {
OpenLP.curStatus = 'blank';
}
if (OpenLP.currentItem != data.item ||
OpenLP.currentService != data.service) {
//New item has been selected
OpenLP.currentItem = data.item;
OpenLP.currentService = data.service;
OpenLP.loadSlides();
}
else if (OpenLP.currentSlide != data.slide) {
// New Slide has been selected
OpenLP.currentSlide = parseInt(data.slide, 10);
OpenLP.updateSlide();
} else {
//catch all just reload
OpenLP.loadService();
}
};
reader.readAsText(event.data);
};
},
loadService: function (event) {
$.getJSON(
"/api/v2/service/items",
function (data, status) {
OpenLP.nextSong = "";
data.forEach(function(item, index, array) {
if (item.selected) {
OpenLP.currentItem = item;
OpenLP.curPlugin =data[index].plugin;
if (OpenLP.curPlugin == 'bibles' && OpenLP.curStatus == 'live') {
//hide the text if not slides
$("#songtitle").html(item.title);
} else {
$("#songtitle").html("");
}
OpenLP.updateSlide();
}
});
//
}
);
},
loadSlides: function (event) {
$.getJSON(
"/api/v2/controller/live-items",
function (data, status) {
OpenLP.currentSlides = data.slides;
OpenLP.currentSlide = 0;
$.each(data.slides, function(idx, slide) {
if (slide["selected"])
OpenLP.currentSlide = idx;
})
OpenLP.loadService();
}
);
},
updateSlide: function() {
// Show the current slide on top. Any trailing slides for the same verse
// are shown too underneath in grey.
// Then leave a blank line between following verses
var slide = OpenLP.currentSlides[OpenLP.currentSlide];
var text = "";
// use title as alternative
if (slide["text"]) {
text = slide["text"];
} else {
text = slide["title"];
}
text = text.replace(/\n/g, "<br />");
// confirm(curStatus);
if (OpenLP.curPlugin != 'bibles'|| OpenLP.curStatus != 'live') {
//hide the text if not bibles
text = "";
//set style to remove bg box
var element = document.querySelector("#bgslide");
element.classList.replace("slide", "slideclear");
} else {
//make sure correct background
var element = document.querySelector("#bgslide");
element.classList.replace("slideclear", "slide");
}
if (OpenLP.curtext != text) {
OpenLP.curtext = text
$("#currentslide").fadeOut(intfadeout, function(){
$("#currentslide").html(OpenLP.curtext);
}
);
$("#currentslide").fadeIn(intfadein);
}
},
}
$.ajaxSetup({ cache: false });
//setInterval("OpenLP.updateClock();", 500);
OpenLP.myWebSocket();