From 055280860cfa4842ffe14d7ee785defb4681b78c Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sat, 4 Jun 2016 22:00:56 +0100 Subject: [PATCH] move main to websockets --- openlp/plugins/remotes/html/js/openlp.js | 32 ++++++++++++++---------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/openlp/plugins/remotes/html/js/openlp.js b/openlp/plugins/remotes/html/js/openlp.js index 128c78cb6..31c12079d 100644 --- a/openlp/plugins/remotes/html/js/openlp.js +++ b/openlp/plugins/remotes/html/js/openlp.js @@ -159,15 +159,19 @@ window.OpenLP = { ); }, pollServer: function () { - $.getJSON( - "/api/poll", - function (data, status) { - var prevItem = OpenLP.currentItem; - OpenLP.currentSlide = data.results.slide; - OpenLP.currentItem = data.results.item; - OpenLP.isSecure = data.results.isSecure; - OpenLP.isAuthorised = data.results.isAuthorised; - if ($("#service-manager").is(":visible")) { + if ("WebSocket" in window) { + // Let us open a web socket + var ws = new WebSocket('ws://' + location.hostname + ':4318/poll'); + ws.binaryType = 'arraybuffer'; + ws.onmessage = function (evt) { + var data = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(evt.data))); + + var prevItem = OpenLP.currentItem; + OpenLP.currentSlide = data.results.slide; + OpenLP.currentItem = data.results.item; + OpenLP.isSecure = data.results.isSecure; + OpenLP.isAuthorised = data.results.isAuthorised; + if ($("#service-manager").is(":visible")) { if (OpenLP.currentService != data.results.service) { OpenLP.currentService = data.results.service; OpenLP.loadService(); @@ -185,7 +189,7 @@ window.OpenLP = { }); $("#service-manager div[data-role=content] ul[data-role=listview]").listview("refresh"); } - if ($("#slide-controller").is(":visible")) { + if ($("#slide-controller").is(":visible")) { if (prevItem != OpenLP.currentItem) { OpenLP.loadController(); return; @@ -205,8 +209,11 @@ window.OpenLP = { }); $("#slide-controller div[data-role=content] ul[data-role=listview]").listview("refresh"); } - } - ); + } + } else { + // The browser doesn't support WebSocket + alert("WebSocket NOT supported by your Browser!"); + } }, nextItem: function (event) { event.preventDefault(); @@ -380,5 +387,4 @@ $.ajaxSetup({cache: false}); $("#search").live("pageinit", function (event) { OpenLP.getSearchablePlugins(); }); -setInterval("OpenLP.pollServer();", 500); OpenLP.pollServer();