Track people again trough their story

This commit is contained in:
Ruben van de Ven 2019-05-17 16:39:53 +02:00
parent 90e6fd1ed8
commit 4c7f15655e
3 changed files with 38 additions and 18 deletions

View file

@ -133,7 +133,7 @@ class CentralCommand(object):
return status
def getStatusSummary(self, selected_id = None):
def getStatusSummary(self, selected_ids = []):
status = {
'uptime': "-" if not self.start_time else (time.time() - self.start_time),
'languages': self.config['languages'],
@ -148,12 +148,12 @@ class CentralCommand(object):
# print(threading.enumerate())
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 self.hugveys[selected_id].recorder:
status['logbook'] = self.hugveys[selected_id].recorder.currentLog
status['logbookId'] = selected_id
# if selected_id and selected_id in self.hugveys:
# if self.hugveys[selected_id].recorder:
# status['logbook'] = self.hugveys[selected_id].recorder.currentLog
# status['logbookId'] = selected_id
return status

View file

@ -30,6 +30,7 @@ def getWebSocketHandler(central_command):
class WebSocketHandler(tornado.websocket.WebSocketHandler):
CORS_ORIGINS = ['localhost', 'hugveycmd.local']
connections = set()
selections = {}
def check_origin(self, origin):
parsed_origin = urlparse(origin)
@ -50,6 +51,8 @@ def getWebSocketHandler(central_command):
msg = json.loads(message)
if msg['action'] == 'init':
self.msgInit()
elif msg['action'] == 'selection':
self.selectHugvey(msg['selected_id'])
# elif msg['action'] == 'get_status':
# self.msgStatus(msg['selected_id'])
elif msg['action'] == 'block':
@ -85,25 +88,30 @@ def getWebSocketHandler(central_command):
# client disconnected
def on_close(self):
WebSocketHandler.connections.remove(self)
WebSocketHandler.rmConnection(self)
logger.info("Client disconnected")
@classmethod
def getStatusMsg(cls, selected_id = False):
msg = central_command.getStatusSummary(selected_id)
def getStatusMsg(cls):
msg = central_command.getStatusSummary(cls.selections.values())
msg['action'] = 'status'
return msg
@classmethod
def broadcastStatus(cls, selected_id = None):
cls.write_to_clients(cls.getStatusMsg(selected_id))
# self.send()
def broadcastStatus(cls):
cls.write_to_clients(cls.getStatusMsg())
def msgInit(self):
msg = self.getStatusMsg()
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):
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):
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
def write_to_clients(wsHandlerClass, msg):
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
for client in toRemove:
if client not in wsHandlerClass.connections:
continue
wsHandlerClass.connections.remove(client)
rmConnection(client)
return WebSocketHandler
@ -287,7 +302,7 @@ class Panopticon(object):
async def statusSender(self, wsHandler):
while True:
try:
self.wsHandler.broadcastStatus(self.wsHandler)
self.wsHandler.broadcastStatus()
await asyncio.sleep(3)
except Exception as e:
logger.exception(e)

View file

@ -27,7 +27,7 @@ class Panopticon {
return moment(time).utc().format("hh:mm:ss");
},
loadNarrative: function( code, file ) {
panopticon.hugveys.selectedId = null;
panopticon.selectHugvey(null);
if(panopticon.hasGraph) {
return panopticon.loadNarrative( code, file );
@ -68,7 +68,7 @@ class Panopticon {
return panopticon.change_light_id(hv_id, light_id);
},
showHugvey: function(hv) {
panopticon.hugveys.selectedId = hv.language ? hv.id : null;
panopticon.selectHugvey(hv.language ? hv.id : null);
panopticon.hugveys.logbook = [];
panopticon.hugveys.logbookId = null;
panopticon.updateSelectedHugvey();
@ -135,6 +135,11 @@ class Panopticon {
} );
}
selectHugvey(hv_id) {
this.hugveys.selectedId = hv_id;
this.send({ action: 'selection', selected_id: hv_id });
}
updateSelectedHugvey() {
let hv = null;