Merge branch 'master' of gitlab.com:hugvey/hugvey
This commit is contained in:
commit
f16bac9c3e
3 changed files with 38 additions and 18 deletions
|
@ -133,7 +133,7 @@ class CentralCommand(object):
|
||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
def getStatusSummary(self, selected_id = None):
|
def getStatusSummary(self, selected_ids = []):
|
||||||
status = {
|
status = {
|
||||||
'uptime': "-" if not self.start_time else (time.time() - self.start_time),
|
'uptime': "-" if not self.start_time else (time.time() - self.start_time),
|
||||||
'languages': self.config['languages'],
|
'languages': self.config['languages'],
|
||||||
|
@ -148,12 +148,12 @@ class CentralCommand(object):
|
||||||
# print(threading.enumerate())
|
# print(threading.enumerate())
|
||||||
|
|
||||||
for hv_id in self.hugvey_ids:
|
for hv_id in self.hugvey_ids:
|
||||||
status['hugveys'].append(self.getHugveyStatus(hv_id, selected_id == hv_id))
|
status['hugveys'].append(self.getHugveyStatus(hv_id, hv_id in selected_ids))
|
||||||
|
|
||||||
if selected_id and selected_id in self.hugveys:
|
# if selected_id and selected_id in self.hugveys:
|
||||||
if self.hugveys[selected_id].recorder:
|
# if self.hugveys[selected_id].recorder:
|
||||||
status['logbook'] = self.hugveys[selected_id].recorder.currentLog
|
# status['logbook'] = self.hugveys[selected_id].recorder.currentLog
|
||||||
status['logbookId'] = selected_id
|
# status['logbookId'] = selected_id
|
||||||
|
|
||||||
return status
|
return status
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ def getWebSocketHandler(central_command):
|
||||||
class WebSocketHandler(tornado.websocket.WebSocketHandler):
|
class WebSocketHandler(tornado.websocket.WebSocketHandler):
|
||||||
CORS_ORIGINS = ['localhost', 'hugveycmd.local']
|
CORS_ORIGINS = ['localhost', 'hugveycmd.local']
|
||||||
connections = set()
|
connections = set()
|
||||||
|
selections = {}
|
||||||
|
|
||||||
def check_origin(self, origin):
|
def check_origin(self, origin):
|
||||||
parsed_origin = urlparse(origin)
|
parsed_origin = urlparse(origin)
|
||||||
|
@ -50,6 +51,8 @@ def getWebSocketHandler(central_command):
|
||||||
msg = json.loads(message)
|
msg = json.loads(message)
|
||||||
if msg['action'] == 'init':
|
if msg['action'] == 'init':
|
||||||
self.msgInit()
|
self.msgInit()
|
||||||
|
elif msg['action'] == 'selection':
|
||||||
|
self.selectHugvey(msg['selected_id'])
|
||||||
# elif msg['action'] == 'get_status':
|
# elif msg['action'] == 'get_status':
|
||||||
# self.msgStatus(msg['selected_id'])
|
# self.msgStatus(msg['selected_id'])
|
||||||
elif msg['action'] == 'block':
|
elif msg['action'] == 'block':
|
||||||
|
@ -85,24 +88,29 @@ def getWebSocketHandler(central_command):
|
||||||
|
|
||||||
# client disconnected
|
# client disconnected
|
||||||
def on_close(self):
|
def on_close(self):
|
||||||
WebSocketHandler.connections.remove(self)
|
WebSocketHandler.rmConnection(self)
|
||||||
logger.info("Client disconnected")
|
logger.info("Client disconnected")
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def getStatusMsg(cls, selected_id = False):
|
def getStatusMsg(cls):
|
||||||
msg = central_command.getStatusSummary(selected_id)
|
msg = central_command.getStatusSummary(cls.selections.values())
|
||||||
msg['action'] = 'status'
|
msg['action'] = 'status'
|
||||||
|
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def broadcastStatus(cls, selected_id = None):
|
def broadcastStatus(cls):
|
||||||
cls.write_to_clients(cls.getStatusMsg(selected_id))
|
cls.write_to_clients(cls.getStatusMsg())
|
||||||
# self.send()
|
|
||||||
|
|
||||||
def msgInit(self):
|
def msgInit(self):
|
||||||
msg = self.getStatusMsg()
|
msg = self.getStatusMsg()
|
||||||
self.send(msg)
|
self.send(msg)
|
||||||
|
|
||||||
|
def selectHugvey(self, hv_id):
|
||||||
|
if hv_id is None:
|
||||||
|
self.__class__.selections.pop(self, None)
|
||||||
|
else:
|
||||||
|
self.__class__.selections[self] = int(hv_id)
|
||||||
|
|
||||||
def msgBlock(self, hv_id):
|
def msgBlock(self, hv_id):
|
||||||
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'block'})
|
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'block'})
|
||||||
|
@ -131,6 +139,15 @@ def getWebSocketHandler(central_command):
|
||||||
def msgPlayMsg(self, hv_id, msg_id, reloadStory):
|
def msgPlayMsg(self, hv_id, msg_id, reloadStory):
|
||||||
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'play_msg', 'msg_id': msg_id, 'reloadStory':bool(reloadStory)})
|
central_command.hugveys[hv_id].eventQueue.put_nowait({'event': 'play_msg', 'msg_id': msg_id, 'reloadStory':bool(reloadStory)})
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def rmConnection(cls, client):
|
||||||
|
if client not in cls.connections:
|
||||||
|
return
|
||||||
|
|
||||||
|
if client in cls.selections:
|
||||||
|
cls.selections.pop(client, None)
|
||||||
|
cls.connections.remove(client)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def write_to_clients(wsHandlerClass, msg):
|
def write_to_clients(wsHandlerClass, msg):
|
||||||
if msg is None:
|
if msg is None:
|
||||||
|
@ -146,9 +163,7 @@ def getWebSocketHandler(central_command):
|
||||||
toRemove.append(client) # If we remove it here from the set we get an exception about changing set size during iteration
|
toRemove.append(client) # If we remove it here from the set we get an exception about changing set size during iteration
|
||||||
|
|
||||||
for client in toRemove:
|
for client in toRemove:
|
||||||
if client not in wsHandlerClass.connections:
|
rmConnection(client)
|
||||||
continue
|
|
||||||
wsHandlerClass.connections.remove(client)
|
|
||||||
|
|
||||||
return WebSocketHandler
|
return WebSocketHandler
|
||||||
|
|
||||||
|
@ -287,7 +302,7 @@ class Panopticon(object):
|
||||||
async def statusSender(self, wsHandler):
|
async def statusSender(self, wsHandler):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
self.wsHandler.broadcastStatus(self.wsHandler)
|
self.wsHandler.broadcastStatus()
|
||||||
await asyncio.sleep(3)
|
await asyncio.sleep(3)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception(e)
|
logger.exception(e)
|
||||||
|
|
|
@ -27,7 +27,7 @@ class Panopticon {
|
||||||
return moment(time).utc().format("hh:mm:ss");
|
return moment(time).utc().format("hh:mm:ss");
|
||||||
},
|
},
|
||||||
loadNarrative: function( code, file ) {
|
loadNarrative: function( code, file ) {
|
||||||
panopticon.hugveys.selectedId = null;
|
panopticon.selectHugvey(null);
|
||||||
|
|
||||||
if(panopticon.hasGraph) {
|
if(panopticon.hasGraph) {
|
||||||
return panopticon.loadNarrative( code, file );
|
return panopticon.loadNarrative( code, file );
|
||||||
|
@ -68,7 +68,7 @@ class Panopticon {
|
||||||
return panopticon.change_light_id(hv_id, light_id);
|
return panopticon.change_light_id(hv_id, light_id);
|
||||||
},
|
},
|
||||||
showHugvey: function(hv) {
|
showHugvey: function(hv) {
|
||||||
panopticon.hugveys.selectedId = hv.language ? hv.id : null;
|
panopticon.selectHugvey(hv.language ? hv.id : null);
|
||||||
panopticon.hugveys.logbook = [];
|
panopticon.hugveys.logbook = [];
|
||||||
panopticon.hugveys.logbookId = null;
|
panopticon.hugveys.logbookId = null;
|
||||||
panopticon.updateSelectedHugvey();
|
panopticon.updateSelectedHugvey();
|
||||||
|
@ -134,6 +134,11 @@ class Panopticon {
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectHugvey(hv_id) {
|
||||||
|
this.hugveys.selectedId = hv_id;
|
||||||
|
this.send({ action: 'selection', selected_id: hv_id });
|
||||||
|
}
|
||||||
|
|
||||||
updateSelectedHugvey() {
|
updateSelectedHugvey() {
|
||||||
let hv = null;
|
let hv = null;
|
||||||
|
|
Loading…
Reference in a new issue