forked from openlp/openlp
Migrate Stage view to web sockets
This commit is contained in:
parent
c0cc2dd141
commit
4b2aa784d4
@ -135,11 +135,11 @@ window.OpenLP = {
|
||||
$("#nextslide").html(text);
|
||||
}
|
||||
},
|
||||
updateClock: function(data) {
|
||||
updateClock: function() {
|
||||
var div = $("#clock");
|
||||
var t = new Date();
|
||||
var h = t.getHours();
|
||||
if (data.results.twelve && h > 12)
|
||||
if (OpenLP.twelve && h > 12)
|
||||
h = h - 12;
|
||||
var m = t.getMinutes();
|
||||
if (m < 10)
|
||||
@ -147,24 +147,32 @@ window.OpenLP = {
|
||||
div.html(h + ":" + m);
|
||||
},
|
||||
pollServer: function () {
|
||||
$.getJSON(
|
||||
"/api/poll",
|
||||
function (data, status) {
|
||||
OpenLP.updateClock(data);
|
||||
if (OpenLP.currentItem != data.results.item ||
|
||||
OpenLP.currentService != data.results.service) {
|
||||
OpenLP.currentItem = data.results.item;
|
||||
OpenLP.currentService = data.results.service;
|
||||
OpenLP.loadSlides();
|
||||
if ("WebSocket" in window) {
|
||||
// Let us open a web socket
|
||||
var ws = new WebSocket("ws://192.168.0.51:4318/poll");
|
||||
ws.binaryType = 'arraybuffer';
|
||||
ws.onmessage = function (evt) {
|
||||
var msg = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(evt.data)));
|
||||
OpenLP.twelve = msg.results.twelve;
|
||||
OpenLP.updateClock();
|
||||
if (OpenLP.currentItem != msg.results.item ||
|
||||
OpenLP.currentService != msg.results.service) {
|
||||
OpenLP.currentItem = msg.results.item;
|
||||
OpenLP.currentService = msg.results.service;
|
||||
OpenLP.loadSlides();
|
||||
}
|
||||
else if (OpenLP.currentSlide != msg.results.slide) {
|
||||
OpenLP.currentSlide = parseInt(mag.results.slide, 10);
|
||||
OpenLP.updateSlide();
|
||||
}
|
||||
}
|
||||
else if (OpenLP.currentSlide != data.results.slide) {
|
||||
OpenLP.currentSlide = parseInt(data.results.slide, 10);
|
||||
OpenLP.updateSlide();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// The browser doesn't support WebSocket
|
||||
alert("WebSocket NOT supported by your Browser!");
|
||||
}
|
||||
},
|
||||
};
|
||||
$.ajaxSetup({ cache: false });
|
||||
setInterval("OpenLP.pollServer();", 500);
|
||||
setInterval("OpenLP.updateClock();", 1000);
|
||||
OpenLP.pollServer();
|
||||
OpenLP.updateClock();
|
@ -116,7 +116,7 @@ from urllib.parse import urlparse, parse_qs
|
||||
|
||||
from mako.template import Template
|
||||
|
||||
from openlp.core.common import RegistryProperties, AppLocation, Settings, translate, UiStrings
|
||||
from openlp.core.common import OpenLPMixin, RegistryProperties, AppLocation, Settings, translate, UiStrings
|
||||
from openlp.core.lib import PluginStatus, StringContent, image_to_byte, ItemCapabilities, create_thumb
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -131,7 +131,7 @@ FILE_TYPES = {
|
||||
}
|
||||
|
||||
|
||||
class HttpRouter(RegistryProperties):
|
||||
class HttpRouter(RegistryProperties, OpenLPMixin):
|
||||
"""
|
||||
This code is called by the HttpServer upon a request and it processes it based on the routing table.
|
||||
This code is stateless and is created on each request.
|
||||
|
@ -197,7 +197,6 @@ class OpenLPServer(RegistryProperties, OpenLPMixin):
|
||||
:return:
|
||||
"""
|
||||
log.debug("web socket handler registered with client")
|
||||
print(path)
|
||||
previous_poll = None
|
||||
if path == '/poll':
|
||||
while True:
|
||||
|
@ -34,6 +34,7 @@ __default_settings__ = {
|
||||
'remotes/twelve hour': True,
|
||||
'remotes/port': 4316,
|
||||
'remotes/https port': 4317,
|
||||
'remotes/websocket port': 4318,
|
||||
'remotes/https enabled': False,
|
||||
'remotes/user id': 'openlp',
|
||||
'remotes/password': 'password',
|
||||
@ -60,7 +61,6 @@ class RemotesPlugin(Plugin, OpenLPMixin):
|
||||
"""
|
||||
Initialise the remotes plugin, and start the http server
|
||||
"""
|
||||
log.debug('Initialise Remote Plugin')
|
||||
super(RemotesPlugin, self).initialise()
|
||||
self.server = OpenLPServer()
|
||||
self.server_ws = OpenLPServer(websocket=True)
|
||||
@ -85,7 +85,6 @@ class RemotesPlugin(Plugin, OpenLPMixin):
|
||||
"""
|
||||
Tidy up and close down the http server
|
||||
"""
|
||||
log.debug('finalise')
|
||||
super(RemotesPlugin, self).finalise()
|
||||
if self.server:
|
||||
self.server.stop_server()
|
||||
|
Loading…
Reference in New Issue
Block a user