forked from openlp/openlp
more updates
This commit is contained in:
parent
8ce073d83f
commit
41d3ea59a0
|
@ -22,9 +22,6 @@
|
|||
|
||||
import os
|
||||
from openlp.core.common import AppLocation
|
||||
from .poll import OpenLPPoll
|
||||
from .wsserver import OpenWSServer
|
||||
from .remotecontroller import RemoteController
|
||||
|
||||
|
||||
def get_cert_file(file_type):
|
||||
|
@ -36,4 +33,9 @@ def get_cert_file(file_type):
|
|||
local_data = AppLocation.get_directory(AppLocation.DataDir)
|
||||
return os.path.join(local_data, 'remotes', 'openlp.{type}'.format(type=file_type))
|
||||
|
||||
|
||||
from .poll import OpenLPPoll
|
||||
from .wsserver import OpenWSServer
|
||||
from .remotecontroller import RemoteController
|
||||
|
||||
__all__ = ['OpenLPPoll', 'RemoteController', 'get_cert_file']
|
||||
|
|
|
@ -22,11 +22,13 @@
|
|||
|
||||
import json
|
||||
|
||||
from openlp.core.common import RegistryProperties, Settings
|
||||
from openlp.core.common import RegistryProperties, Settings, OpenLPMixin
|
||||
|
||||
|
||||
class OpenLPPoll(RegistryProperties):
|
||||
|
||||
class OpenLPPoll(RegistryProperties, OpenLPMixin):
|
||||
"""
|
||||
Access by the web layer to get status type information from the application
|
||||
"""
|
||||
def __init__(self):
|
||||
"""
|
||||
Constructor for the poll builder class.
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
from openlp.core.common import OpenLPMixin, Registry, RegistryMixin, RegistryProperties
|
||||
from openlp.core.lib.remote import OpenWSServer
|
||||
from openlp.core.lib.remote import OpenWSServer, OpenLPPoll
|
||||
|
||||
|
||||
class RemoteController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||
|
@ -41,13 +41,12 @@ class RemoteController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
|||
Constructor
|
||||
"""
|
||||
super(RemoteController, self).__init__(parent)
|
||||
self.media_players = {}
|
||||
self.display_controllers = {}
|
||||
self.current_media_players = {}
|
||||
# Registry().register_function('playbackPlay', self.media_play_msg)
|
||||
|
||||
def bootstrap_post_set_up(self):
|
||||
"""
|
||||
process the bootstrap post setup request
|
||||
"""
|
||||
self.poll = OpenLPPoll()
|
||||
Registry().register('OpenLPPoll', self.poll)
|
||||
self.wsserver = OpenWSServer()
|
||||
|
|
|
@ -29,12 +29,12 @@ import asyncio
|
|||
import websockets
|
||||
import logging
|
||||
import time
|
||||
import ssl
|
||||
|
||||
from PyQt5 import QtCore
|
||||
|
||||
from openlp.core.common import Settings, RegistryProperties, OpenLPMixin
|
||||
from openlp.core.lib.remote import OpenLPPoll
|
||||
|
||||
from openlp.core.common import Settings, RegistryProperties, OpenLPMixin, Registry
|
||||
from openlp.core.lib.remote import get_cert_file
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -81,7 +81,6 @@ class OpenWSServer(RegistryProperties, OpenLPMixin):
|
|||
Start the correct server and save the handler
|
||||
"""
|
||||
address = Settings().value(self.settings_section + '/ip address')
|
||||
is_secure = Settings().value(self.settings_section + '/https enabled')
|
||||
port = '4318'
|
||||
self.start_websocket_instance(address, port)
|
||||
# If web socket server start listening
|
||||
|
@ -101,9 +100,15 @@ class OpenWSServer(RegistryProperties, OpenLPMixin):
|
|||
:param port: The run port
|
||||
"""
|
||||
loop = 1
|
||||
is_secure = Settings().value(self.settings_section + '/https enabled')
|
||||
while loop < 4:
|
||||
try:
|
||||
self.ws_server = websockets.serve(self.handle_websocket, address, port)
|
||||
if is_secure:
|
||||
context = ssl.create_default_context()
|
||||
context.load_cert_chain(certfile=get_cert_file('crt'), keyfile=get_cert_file('key'))
|
||||
self.ws_server = websockets.serve(self.handle_websocket, address, port, ssl=context)
|
||||
else:
|
||||
self.ws_server = websockets.serve(self.handle_websocket, address, port)
|
||||
log.debug("Web Socket Server started for class {address} {port}".format(address=address, port=port))
|
||||
break
|
||||
except Exception as e:
|
||||
|
@ -124,16 +129,17 @@ class OpenWSServer(RegistryProperties, OpenLPMixin):
|
|||
log.debug("web socket handler registered with client")
|
||||
previous_poll = None
|
||||
previous_main_poll = None
|
||||
openlppoll = Registry().get('OpenLPPoll')
|
||||
if path == '/poll':
|
||||
while True:
|
||||
current_poll = OpenLPPoll().poll()
|
||||
current_poll = openlppoll.poll()
|
||||
if current_poll != previous_poll:
|
||||
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()
|
||||
main_poll = openlppoll.main_poll()
|
||||
if main_poll != previous_main_poll:
|
||||
await request.send(main_poll)
|
||||
previous_main_poll = main_poll
|
||||
|
|
|
@ -162,7 +162,7 @@ window.OpenLP = {
|
|||
OpenLP.loadSlides();
|
||||
}
|
||||
else if (OpenLP.currentSlide != msg.results.slide) {
|
||||
OpenLP.currentSlide = parseInt(mag.results.slide, 10);
|
||||
OpenLP.currentSlide = parseInt(msg.results.slide, 10);
|
||||
OpenLP.updateSlide();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ from urllib.parse import urlparse, parse_qs
|
|||
|
||||
from mako.template import Template
|
||||
|
||||
from openlp.core.common import OpenLPMixin, RegistryProperties, AppLocation, Settings, translate, UiStrings
|
||||
from openlp.core.common import OpenLPMixin, RegistryProperties, AppLocation, Settings, Registry, translate, UiStrings
|
||||
from openlp.core.lib import PluginStatus, StringContent, image_to_byte, ItemCapabilities, create_thumb
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
@ -143,6 +143,7 @@ class HttpRouter(RegistryProperties, OpenLPMixin):
|
|||
"""
|
||||
auth_code = "{user}:{password}".format(user=Settings().value('remotes/user id'),
|
||||
password=Settings().value('remotes/password'))
|
||||
self.openlppoll = Registry().get('OpenLPPoll')
|
||||
try:
|
||||
self.auth = base64.b64encode(auth_code)
|
||||
except TypeError:
|
||||
|
@ -154,8 +155,8 @@ class HttpRouter(RegistryProperties, OpenLPMixin):
|
|||
('^/(stage)/(.*)$', {'function': self.stages, 'secure': False}),
|
||||
('^/(main)$', {'function': self.serve_file, 'secure': False}),
|
||||
(r'^/(\w+)/thumbnails([^/]+)?/(.*)$', {'function': self.serve_thumbnail, 'secure': False}),
|
||||
(r'^/api/poll$', {'function': self.poll, 'secure': False}),
|
||||
(r'^/main/poll$', {'function': self.main_poll, 'secure': False}),
|
||||
(r'^/api/poll$', {'function': self.openlppoll.poll, 'secure': False}),
|
||||
(r'^/main/poll$', {'function': self.openlppoll.main_poll, 'secure': False}),
|
||||
(r'^/main/image$', {'function': self.main_image, 'secure': False}),
|
||||
(r'^/api/controller/(live|preview)/text$', {'function': self.controller_text, 'secure': False}),
|
||||
(r'^/api/controller/(live|preview)/(.*)$', {'function': self.controller, 'secure': True}),
|
||||
|
@ -468,35 +469,6 @@ class HttpRouter(RegistryProperties, OpenLPMixin):
|
|||
self.end_headers()
|
||||
return content
|
||||
|
||||
def poll(self):
|
||||
"""
|
||||
Poll OpenLP to determine the current slide number and item name.
|
||||
"""
|
||||
result = {
|
||||
'service': self.service_manager.service_id,
|
||||
'slide': self.live_controller.selected_row or 0,
|
||||
'item': self.live_controller.service_item.unique_identifier if self.live_controller.service_item else '',
|
||||
'twelve': Settings().value('remotes/twelve hour'),
|
||||
'blank': self.live_controller.blank_screen.isChecked(),
|
||||
'theme': self.live_controller.theme_screen.isChecked(),
|
||||
'display': self.live_controller.desktop_screen.isChecked(),
|
||||
'version': 2,
|
||||
'isSecure': Settings().value(self.settings_section + '/authentication enabled'),
|
||||
'isAuthorised': self.authorised
|
||||
}
|
||||
self.do_json_header()
|
||||
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
|
||||
}
|
||||
self.do_json_header()
|
||||
return json.dumps({'results': result}).encode()
|
||||
|
||||
def main_image(self):
|
||||
"""
|
||||
Return the latest display image as a byte stream.
|
||||
|
|
Loading…
Reference in New Issue