getStatus now every 3s from panopticon instead of requests - allows for more connected clients
This commit is contained in:
parent
4b67e0a6f2
commit
f3188bb862
3 changed files with 28 additions and 14 deletions
|
@ -365,7 +365,7 @@ class CommandHandler(object):
|
|||
return
|
||||
|
||||
# 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()
|
||||
|
||||
def cmdStop(self, msgId):
|
||||
|
@ -479,7 +479,7 @@ class Hugvey(object):
|
|||
hugvey=self,
|
||||
config=self.config
|
||||
)
|
||||
|
||||
|
||||
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))
|
||||
self.cmd_server = CommandHandler(
|
||||
|
|
|
@ -50,8 +50,8 @@ def getWebSocketHandler(central_command):
|
|||
msg = json.loads(message)
|
||||
if msg['action'] == 'init':
|
||||
self.msgInit()
|
||||
elif msg['action'] == 'get_status':
|
||||
self.msgStatus(msg['selected_id'])
|
||||
# elif msg['action'] == 'get_status':
|
||||
# self.msgStatus(msg['selected_id'])
|
||||
elif msg['action'] == 'block':
|
||||
self.msgBlock(msg['hugvey'])
|
||||
elif msg['action'] == 'unblock':
|
||||
|
@ -71,11 +71,11 @@ def getWebSocketHandler(central_command):
|
|||
elif msg['action'] == 'play_msg':
|
||||
self.msgPlayMsg(msg['hugvey'], msg['msg_id'], msg['reloadStory'])
|
||||
else:
|
||||
self.send({'alert': 'Unknown request: {}'.format(message)})
|
||||
# self.send({'alert': 'Unknown request: {}'.format(message)})
|
||||
logger.warn('Unknown request: {}'.format(message))
|
||||
|
||||
except Exception as e:
|
||||
self.send({'alert': 'Invalid request: {}'.format(e)})
|
||||
# self.send({'alert': 'Invalid request: {}'.format(e)})
|
||||
logger.exception(e)
|
||||
|
||||
def send(self, message):
|
||||
|
@ -88,14 +88,16 @@ def getWebSocketHandler(central_command):
|
|||
WebSocketHandler.connections.remove(self)
|
||||
logger.info("Client disconnected")
|
||||
|
||||
def getStatusMsg(self, selected_id = False):
|
||||
@classmethod
|
||||
def getStatusMsg(cls, selected_id = False):
|
||||
msg = central_command.getStatusSummary(selected_id)
|
||||
msg['action'] = 'status'
|
||||
|
||||
return msg
|
||||
|
||||
def msgStatus(self, selected_id = None):
|
||||
self.write_to_clients(self.getStatusMsg(selected_id))
|
||||
@classmethod
|
||||
def broadcastStatus(cls, selected_id = None):
|
||||
cls.write_to_clients(cls.getStatusMsg(selected_id))
|
||||
# self.send()
|
||||
|
||||
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")
|
||||
thread.start()
|
||||
|
||||
|
||||
task = evt_loop.create_task(
|
||||
self.statusSender(self.wsHandler))
|
||||
|
||||
logger.info(f"Start Panopticon on http://localhost:{self.config['web']['port']}")
|
||||
self.loop.start()
|
||||
|
||||
def stop(self):
|
||||
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):
|
||||
while True:
|
||||
record = q.get()
|
||||
|
|
|
@ -173,13 +173,13 @@ class Panopticon {
|
|||
}
|
||||
}
|
||||
|
||||
getStatus() {
|
||||
// console.log('get status', this, panopticon);
|
||||
panopticon.send( { action: 'get_status', selected_id: panopticon.hugveys.selectedId } );
|
||||
}
|
||||
// getStatus() {
|
||||
// // console.log('get status', this, panopticon);
|
||||
// panopticon.send( { action: 'get_status', selected_id: panopticon.hugveys.selectedId } );
|
||||
// }
|
||||
|
||||
init() {
|
||||
setInterval( this.getStatus, 3000 );
|
||||
// setInterval( this.getStatus, 3000 );
|
||||
}
|
||||
|
||||
stringToHHMMSS( string ) {
|
||||
|
|
Loading…
Reference in a new issue