|
| 1 | +/****************************************************************************** |
| 2 | + * OpenLP - Open Source Lyrics Projection * |
| 3 | + * --------------------------------------------------------------------------- * |
| 4 | + * Copyright (c) 2008-2021 OpenLP Developers * |
| 5 | + * --------------------------------------------------------------------------- * |
| 6 | + * This program is free software; you can redistribute it and/or modify it * |
| 7 | + * under the terms of the GNU General Public License as published by the Free * |
| 8 | + * Software Foundation; version 2 of the License. * |
| 9 | + * * |
| 10 | + * This program is distributed in the hope that it will be useful, but WITHOUT * |
| 11 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * |
| 12 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * |
| 13 | + * more details. * |
| 14 | + * * |
| 15 | + * You should have received a copy of the GNU General Public License along * |
| 16 | + * with this program; if not, write to the Free Software Foundation, Inc., 59 * |
| 17 | + * Temple Place, Suite 330, Boston, MA 02111-1307 USA * |
| 18 | + ******************************************************************************/ |
| 19 | +var intfadein = 300; |
| 20 | +var intfadeout= 300; |
| 21 | +var strtype="songs"; |
| 22 | + |
| 23 | + |
| 24 | +window.OpenLP = { // Connect to the OpenLP Remote WebSocket to get pushed updates |
| 25 | + myWebSocket: function (data, status) { |
| 26 | + const host = window.location.hostname; |
| 27 | + const websocket_port = 4317; |
| 28 | + var curmode; |
| 29 | + |
| 30 | + ws = new WebSocket(`ws://${host}:${websocket_port}`); |
| 31 | + ws.onmessage = (event) => { |
| 32 | + |
| 33 | + const reader = new FileReader(); |
| 34 | + |
| 35 | + reader.onload = () => { |
| 36 | + data = JSON.parse(reader.result.toString()).results; |
| 37 | + // set some global var |
| 38 | + //set the displaymode |
| 39 | + //This will determine if we show text. |
| 40 | + OpenLP.curStatus = 'live'; |
| 41 | + //Showing Theme |
| 42 | + curmode = data.theme; |
| 43 | + if (curmode==true) { |
| 44 | + OpenLP.curStatus = 'theme'; |
| 45 | + } |
| 46 | + //Showing Desktop |
| 47 | + curmode = data.display; |
| 48 | + if (curmode==true) { |
| 49 | + OpenLP.curStatus = 'display'; |
| 50 | + } |
| 51 | + //Showing Black |
| 52 | + curmode = data.blank; |
| 53 | + if (curmode==true) { |
| 54 | + OpenLP.curStatus = 'blank'; |
| 55 | + } |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | + if (OpenLP.currentItem != data.item || |
| 60 | + OpenLP.currentService != data.service) { |
| 61 | + //New item has been selected |
| 62 | + OpenLP.currentItem = data.item; |
| 63 | + OpenLP.currentService = data.service; |
| 64 | + |
| 65 | + OpenLP.loadSlides(); |
| 66 | + } |
| 67 | + else if (OpenLP.currentSlide != data.slide) { |
| 68 | + // New Slide has been selected |
| 69 | + OpenLP.currentSlide = parseInt(data.slide, 10); |
| 70 | + |
| 71 | + OpenLP.updateSlide(); |
| 72 | + |
| 73 | + } else { |
| 74 | + //catch all just reload |
| 75 | + OpenLP.loadService(); |
| 76 | + } |
| 77 | + }; |
| 78 | + reader.readAsText(event.data); |
| 79 | + }; |
| 80 | + }, |
| 81 | + |
| 82 | + loadService: function (event) { |
| 83 | + $.getJSON( |
| 84 | + "/api/v2/service/items", |
| 85 | + function (data, status) { |
| 86 | + OpenLP.nextSong = ""; |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | + data.forEach(function(item, index, array) { |
| 91 | + |
| 92 | + if (item.selected) { |
| 93 | + |
| 94 | + OpenLP.currentItem = item; |
| 95 | + OpenLP.curPlugin =data[index].plugin; |
| 96 | + |
| 97 | + if (OpenLP.curPlugin == strtype && OpenLP.curStatus == 'live') { |
| 98 | + //hide the text |
| 99 | + $("#songtitle").html(item.title); |
| 100 | + } else { |
| 101 | + $("#songtitle").html(""); |
| 102 | + } |
| 103 | + |
| 104 | + OpenLP.updateSlide(); |
| 105 | + |
| 106 | + |
| 107 | + } |
| 108 | + }); |
| 109 | + |
| 110 | + // |
| 111 | + } |
| 112 | + ); |
| 113 | + }, |
| 114 | + |
| 115 | + loadSlides: function (event) { |
| 116 | + $.getJSON( |
| 117 | + "/api/v2/controller/live-items", |
| 118 | + function (data, status) { |
| 119 | + OpenLP.currentSlides = data.slides; |
| 120 | + OpenLP.currentSlide = 0; |
| 121 | + |
| 122 | + $.each(data.slides, function(idx, slide) { |
| 123 | + |
| 124 | + |
| 125 | + if (slide["selected"]) |
| 126 | + OpenLP.currentSlide = idx; |
| 127 | + }) |
| 128 | + |
| 129 | + OpenLP.loadService(); |
| 130 | + |
| 131 | + } |
| 132 | + ); |
| 133 | + }, |
| 134 | + |
| 135 | + updateSlide: function() { |
| 136 | + // Show the current slide on top. Any trailing slides for the same verse |
| 137 | + // are shown too underneath in grey. |
| 138 | + // Then leave a blank line between following verses |
| 139 | + |
| 140 | + var slide = OpenLP.currentSlides[OpenLP.currentSlide]; |
| 141 | + var text = ""; |
| 142 | + |
| 143 | + // use title as alternative |
| 144 | + if (slide["text"]) { |
| 145 | + text = slide["text"]; |
| 146 | + } else { |
| 147 | + text = slide["title"]; |
| 148 | + } |
| 149 | + |
| 150 | + text = text.replace(/\n/g, "<br />"); |
| 151 | + // confirm(curStatus); |
| 152 | + if (OpenLP.curPlugin != strtype|| OpenLP.curStatus != 'live') { |
| 153 | + //hide the text |
| 154 | + text = ""; |
| 155 | + //set style to remove bg box |
| 156 | + var element = document.querySelector("#bgslide"); |
| 157 | + element.classList.replace("slide", "slideclear"); |
| 158 | + } else { |
| 159 | + //make sure correct background |
| 160 | + var element = document.querySelector("#bgslide"); |
| 161 | + element.classList.replace("slideclear", "slide"); |
| 162 | + |
| 163 | + } |
| 164 | + |
| 165 | + if (OpenLP.curtext != text) { |
| 166 | + OpenLP.curtext = text |
| 167 | + $("#currentslide").fadeOut(intfadeout, function(){ |
| 168 | + |
| 169 | + $("#currentslide").html(OpenLP.curtext); |
| 170 | + |
| 171 | + } |
| 172 | + ); |
| 173 | + $("#currentslide").fadeIn(intfadein); |
| 174 | + } |
| 175 | + |
| 176 | + |
| 177 | + }, |
| 178 | + |
| 179 | +} |
| 180 | +$.ajaxSetup({ cache: false }); |
| 181 | +//setInterval("OpenLP.updateClock();", 500); |
| 182 | +OpenLP.myWebSocket(); |
0 commit comments