forked from openlp/openlp
Fix up to work with python 3.4 and 3.5
This commit is contained in:
parent
ad485bd2c9
commit
ba1eac8cd3
@ -29,6 +29,7 @@ import asyncio
|
|||||||
import websockets
|
import websockets
|
||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
import sys
|
||||||
|
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
|
|
||||||
@ -110,34 +111,65 @@ class OpenWSServer(RegistryProperties, OpenLPMixin):
|
|||||||
loop += 1
|
loop += 1
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
@staticmethod
|
if sys.version_info >= (3, 5):
|
||||||
async def handle_websocket(request, path):
|
@staticmethod
|
||||||
"""
|
async def handle_websocket(request, path):
|
||||||
Handle web socket requests and return the poll information.
|
"""
|
||||||
Check ever 0.5 seconds to get the latest postion and send if changed.
|
Handle web socket requests and return the poll information.
|
||||||
Only gets triggered when 1st client attaches
|
Check ever 0.5 seconds to get the latest postion and send if changed.
|
||||||
:param request: request from client
|
Only gets triggered when 1st client attaches
|
||||||
:param path: not used - future to register for a different end point
|
:param request: request from client
|
||||||
:return:
|
:param path: not used - future to register for a different end point
|
||||||
"""
|
:return:
|
||||||
log.debug("web socket handler registered with client")
|
"""
|
||||||
previous_poll = None
|
log.debug("web socket handler registered with client")
|
||||||
previous_main_poll = None
|
previous_poll = None
|
||||||
openlppoll = Registry().get('OpenLPPoll')
|
previous_main_poll = None
|
||||||
if path == '/poll':
|
openlppoll = Registry().get('OpenLPPoll')
|
||||||
while True:
|
if path == '/poll':
|
||||||
current_poll = openlppoll.poll()
|
while True:
|
||||||
if current_poll != previous_poll:
|
current_poll = openlppoll.poll()
|
||||||
await request.send(current_poll)
|
if current_poll != previous_poll:
|
||||||
previous_poll = current_poll
|
await request.send(current_poll)
|
||||||
await asyncio.sleep(0.2)
|
previous_poll = current_poll
|
||||||
elif path == '/main_poll':
|
await asyncio.sleep(0.2)
|
||||||
while True:
|
elif path == '/main_poll':
|
||||||
main_poll = openlppoll.main_poll()
|
while True:
|
||||||
if main_poll != previous_main_poll:
|
main_poll = openlppoll.main_poll()
|
||||||
await request.send(main_poll)
|
if main_poll != previous_main_poll:
|
||||||
previous_main_poll = main_poll
|
await request.send(main_poll)
|
||||||
await asyncio.sleep(0.2)
|
previous_main_poll = main_poll
|
||||||
|
await asyncio.sleep(0.2)
|
||||||
|
else:
|
||||||
|
@staticmethod
|
||||||
|
@asyncio.coroutine
|
||||||
|
def handle_websocket(request, path):
|
||||||
|
"""
|
||||||
|
Handle web socket requests and return the poll information.
|
||||||
|
Check ever 0.5 seconds to get the latest postion and send if changed.
|
||||||
|
Only gets triggered when 1st client attaches
|
||||||
|
:param request: request from client
|
||||||
|
:param path: not used - future to register for a different end point
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
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()
|
||||||
|
if current_poll != previous_poll:
|
||||||
|
yield from request.send(current_poll)
|
||||||
|
previous_poll = current_poll
|
||||||
|
yield from asyncio.sleep(0.2)
|
||||||
|
elif path == '/main_poll':
|
||||||
|
while True:
|
||||||
|
main_poll = openlppoll.main_poll()
|
||||||
|
if main_poll != previous_main_poll:
|
||||||
|
yield from request.send(main_poll)
|
||||||
|
previous_main_poll = main_poll
|
||||||
|
yield from asyncio.sleep(0.2)
|
||||||
|
|
||||||
def stop_server(self):
|
def stop_server(self):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user