Commit 08db5071 authored by D1plo1d's avatar D1plo1d

Informing the websockets of the number of active connections to prontserve.

parent 339b2a55
...@@ -242,9 +242,16 @@ class ConstructSocketHandler(tornado.websocket.WebSocketHandler): ...@@ -242,9 +242,16 @@ class ConstructSocketHandler(tornado.websocket.WebSocketHandler):
for k, v in prontserve.target_values.iteritems(): for k, v in prontserve.target_values.iteritems():
self.on_uncaught_event("target_temp_changed", {k: v}) self.on_uncaught_event("target_temp_changed", {k: v})
self.on_uncaught_event("job_progress_changed", prontserve.previous_job_progress) self.on_uncaught_event("job_progress_changed", prontserve.previous_job_progress)
# Alerting all websockets of the new client
self._on_connections_changed()
self.send(initialized= {'session_uuid': self.session_uuid} ) self.send(initialized= {'session_uuid': self.session_uuid} )
print "WebSocket opened. %i sockets currently open." % len(prontserve.listeners) print "WebSocket opened. %i sockets currently open." % len(prontserve.listeners)
def _on_connections_changed(self):
for c in self.clients:
c.send(connections_changed= len(prontserve.listeners))
def send(self, dict_args = {}, **kwargs): def send(self, dict_args = {}, **kwargs):
args = dict(dict_args.items() + kwargs.items()) args = dict(dict_args.items() + kwargs.items())
args['timestamp']= time.time() args['timestamp']= time.time()
...@@ -353,6 +360,7 @@ class ConstructSocketHandler(tornado.websocket.WebSocketHandler): ...@@ -353,6 +360,7 @@ class ConstructSocketHandler(tornado.websocket.WebSocketHandler):
if self in self.clients: if self in self.clients:
self.clients.remove(self) self.clients.remove(self)
prontserve.listeners.remove(self) prontserve.listeners.remove(self)
self._on_connections_changed()
print "WebSocket closed. %i sockets currently open." % len(prontserve.listeners) print "WebSocket closed. %i sockets currently open." % len(prontserve.listeners)
dir = os.path.dirname(__file__) dir = os.path.dirname(__file__)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment