forked from openlp/openlp
move live view to websockets
This commit is contained in:
parent
ea382e18bb
commit
251f197e45
@ -28,18 +28,23 @@ window.OpenLP = {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
pollServer: function () {
|
pollServer: function () {
|
||||||
$.getJSON(
|
if ("WebSocket" in window) {
|
||||||
"/main/poll",
|
// Let us open a web socket
|
||||||
function (data, status) {
|
var ws = new WebSocket('ws://' + location.hostname + ':4318/main_poll');
|
||||||
if (OpenLP.slideCount != data.results.slide_count) {
|
ws.binaryType = 'arraybuffer';
|
||||||
OpenLP.slideCount = data.results.slide_count;
|
ws.onmessage = function (evt) {
|
||||||
OpenLP.loadSlide();
|
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 });
|
$.ajaxSetup({ cache: false });
|
||||||
setInterval("OpenLP.pollServer();", 500);
|
|
||||||
OpenLP.pollServer();
|
OpenLP.pollServer();
|
||||||
|
|
||||||
|
@ -198,6 +198,7 @@ class OpenLPServer(RegistryProperties, OpenLPMixin):
|
|||||||
"""
|
"""
|
||||||
log.debug("web socket handler registered with client")
|
log.debug("web socket handler registered with client")
|
||||||
previous_poll = None
|
previous_poll = None
|
||||||
|
previous_main_poll = None
|
||||||
if path == '/poll':
|
if path == '/poll':
|
||||||
while True:
|
while True:
|
||||||
current_poll = OpenLPPoll().poll()
|
current_poll = OpenLPPoll().poll()
|
||||||
@ -205,6 +206,13 @@ class OpenLPServer(RegistryProperties, OpenLPMixin):
|
|||||||
await request.send(current_poll)
|
await request.send(current_poll)
|
||||||
previous_poll = current_poll
|
previous_poll = current_poll
|
||||||
await asyncio.sleep(0.2)
|
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):
|
def stop_server(self):
|
||||||
"""
|
"""
|
||||||
|
@ -50,3 +50,12 @@ class OpenLPPoll(RegistryProperties):
|
|||||||
'isAuthorised': False
|
'isAuthorised': False
|
||||||
}
|
}
|
||||||
return json.dumps({'results': result}).encode()
|
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()
|
||||||
|
@ -94,6 +94,7 @@ MODULES = [
|
|||||||
'mako',
|
'mako',
|
||||||
'uno',
|
'uno',
|
||||||
'websockets',
|
'websockets',
|
||||||
|
'asyncio',
|
||||||
'six'
|
'six'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user