diff --git a/openlp/plugins/remotes/html/js/main.js b/openlp/plugins/remotes/html/js/main.js index 614db4bd1..053456fdc 100644 --- a/openlp/plugins/remotes/html/js/main.js +++ b/openlp/plugins/remotes/html/js/main.js @@ -28,18 +28,23 @@ window.OpenLP = { ); }, pollServer: function () { - $.getJSON( - "/main/poll", - function (data, status) { - if (OpenLP.slideCount != data.results.slide_count) { - OpenLP.slideCount = data.results.slide_count; - OpenLP.loadSlide(); + if ("WebSocket" in window) { + // Let us open a web socket + var ws = new WebSocket('ws://' + location.hostname + ':4318/main_poll'); + ws.binaryType = 'arraybuffer'; + ws.onmessage = function (evt) { + var msg = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(evt.data))); + if (OpenLP.slideCount != msg.results.slide_count) { + OpenLP.slideCount = msg.results.slide_count; + OpenLP.loadSlide(); + } } - } - ); + } else { + // The browser doesn't support WebSocket + alert("WebSocket NOT supported by your Browser!"); + } } -} +}; $.ajaxSetup({ cache: false }); -setInterval("OpenLP.pollServer();", 500); OpenLP.pollServer(); diff --git a/openlp/plugins/remotes/lib/httpserver.py b/openlp/plugins/remotes/lib/httpserver.py index 6ad145595..efc9d3e43 100644 --- a/openlp/plugins/remotes/lib/httpserver.py +++ b/openlp/plugins/remotes/lib/httpserver.py @@ -198,6 +198,7 @@ class OpenLPServer(RegistryProperties, OpenLPMixin): """ log.debug("web socket handler registered with client") previous_poll = None + previous_main_poll = None if path == '/poll': while True: current_poll = OpenLPPoll().poll() @@ -205,6 +206,13 @@ class OpenLPServer(RegistryProperties, OpenLPMixin): await request.send(current_poll) previous_poll = current_poll await asyncio.sleep(0.2) + elif path == '/main_poll': + while True: + main_poll = OpenLPPoll().main_poll() + if main_poll != previous_main_poll: + await request.send(main_poll) + previous_main_poll = main_poll + await asyncio.sleep(0.2) def stop_server(self): """ diff --git a/openlp/plugins/remotes/lib/poll.py b/openlp/plugins/remotes/lib/poll.py index b1b4bdbd5..7c94ae4df 100644 --- a/openlp/plugins/remotes/lib/poll.py +++ b/openlp/plugins/remotes/lib/poll.py @@ -50,3 +50,12 @@ class OpenLPPoll(RegistryProperties): 'isAuthorised': False } return json.dumps({'results': result}).encode() + + def main_poll(self): + """ + Poll OpenLP to determine the current slide count. + """ + result = { + 'slide_count': self.live_controller.slide_count + } + return json.dumps({'results': result}).encode() diff --git a/scripts/check_dependencies.py b/scripts/check_dependencies.py index 14e68248b..079965092 100755 --- a/scripts/check_dependencies.py +++ b/scripts/check_dependencies.py @@ -94,6 +94,7 @@ MODULES = [ 'mako', 'uno', 'websockets', + 'asyncio', 'six' ]