getStatus now every 3s from panopticon instead of requests - allows for more connected clients

This commit is contained in:
Hugvey Central Command 2019-05-16 15:23:36 +02:00
parent 4b67e0a6f2
commit f3188bb862
3 changed files with 28 additions and 14 deletions

View file

@ -365,7 +365,7 @@ class CommandHandler(object):
return return
# prevent a lock of the story, no repeat or anything for now # prevent a lock of the story, no repeat or anything for now
logger.critical("Interrupting playback after timeout") logger.critical("Interrupting playback after timeout: {}".format(self.playingMsgId))
self.playPopen.terminate() self.playPopen.terminate()
def cmdStop(self, msgId): def cmdStop(self, msgId):
@ -479,7 +479,7 @@ class Hugvey(object):
hugvey=self, hugvey=self,
config=self.config config=self.config
) )
remote_ip = self.config['events']['remote_ip'] if 'remote_ip' in self.config['events'] else '8.8.8.8' remote_ip = self.config['events']['remote_ip'] if 'remote_ip' in self.config['events'] else '8.8.8.8'
logger.debug("Using remote_ip for getIp: {}".format(remote_ip)) logger.debug("Using remote_ip for getIp: {}".format(remote_ip))
self.cmd_server = CommandHandler( self.cmd_server = CommandHandler(

View file

@ -50,8 +50,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'] == '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':
self.msgBlock(msg['hugvey']) self.msgBlock(msg['hugvey'])
elif msg['action'] == 'unblock': elif msg['action'] == 'unblock':
@ -71,11 +71,11 @@ def getWebSocketHandler(central_command):
elif msg['action'] == 'play_msg': elif msg['action'] == 'play_msg':
self.msgPlayMsg(msg['hugvey'], msg['msg_id'], msg['reloadStory']) self.msgPlayMsg(msg['hugvey'], msg['msg_id'], msg['reloadStory'])
else: else:
self.send({'alert': 'Unknown request: {}'.format(message)}) # self.send({'alert': 'Unknown request: {}'.format(message)})
logger.warn('Unknown request: {}'.format(message)) logger.warn('Unknown request: {}'.format(message))
except Exception as e: except Exception as e:
self.send({'alert': 'Invalid request: {}'.format(e)}) # self.send({'alert': 'Invalid request: {}'.format(e)})
logger.exception(e) logger.exception(e)
def send(self, message): def send(self, message):
@ -88,14 +88,16 @@ def getWebSocketHandler(central_command):
WebSocketHandler.connections.remove(self) WebSocketHandler.connections.remove(self)
logger.info("Client disconnected") logger.info("Client disconnected")
def getStatusMsg(self, selected_id = False): @classmethod
def getStatusMsg(cls, selected_id = False):
msg = central_command.getStatusSummary(selected_id) msg = central_command.getStatusSummary(selected_id)
msg['action'] = 'status' msg['action'] = 'status'
return msg return msg
def msgStatus(self, selected_id = None): @classmethod
self.write_to_clients(self.getStatusMsg(selected_id)) def broadcastStatus(cls, selected_id = None):
cls.write_to_clients(cls.getStatusMsg(selected_id))
# self.send() # self.send()
def msgInit(self): def msgInit(self):
@ -272,12 +274,24 @@ class Panopticon(object):
target=self.broadcastLoggingQueueToWs, kwargs={'wsHandler': self.wsHandler, 'q': self.command.logQueue}, name=f"panopticon/logws") target=self.broadcastLoggingQueueToWs, kwargs={'wsHandler': self.wsHandler, 'q': self.command.logQueue}, name=f"panopticon/logws")
thread.start() thread.start()
task = evt_loop.create_task(
self.statusSender(self.wsHandler))
logger.info(f"Start Panopticon on http://localhost:{self.config['web']['port']}") logger.info(f"Start Panopticon on http://localhost:{self.config['web']['port']}")
self.loop.start() self.loop.start()
def stop(self): def stop(self):
self.loop.stop() self.loop.stop()
async def statusSender(self, wsHandler):
while True:
try:
self.wsHandler.broadcastStatus(self.wsHandler)
await asyncio.sleep(3)
except Exception as e:
logger.exception(e)
def broadcastLoggingQueueToWs(self, wsHandler, q: Queue): def broadcastLoggingQueueToWs(self, wsHandler, q: Queue):
while True: while True:
record = q.get() record = q.get()

View file

@ -173,13 +173,13 @@ class Panopticon {
} }
} }
getStatus() { // getStatus() {
// console.log('get status', this, panopticon); // // console.log('get status', this, panopticon);
panopticon.send( { action: 'get_status', selected_id: panopticon.hugveys.selectedId } ); // panopticon.send( { action: 'get_status', selected_id: panopticon.hugveys.selectedId } );
} // }
init() { init() {
setInterval( this.getStatus, 3000 ); // setInterval( this.getStatus, 3000 );
} }
stringToHHMMSS( string ) { stringToHHMMSS( string ) {