Skip to content

Commit

Permalink
Improve the stability of event subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Aug 16, 2021
1 parent 1bae053 commit 17f003c
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion macast/mpv.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def __init__(self):
self.eventSubcribes = {} # subscribe devices
self.stateQueue = Queue() # states needed be send to subscribe devices
self.removedDeviceQueue = Queue() # devices needed be removed
self.appendDeviceQueue = Queue() # devices needed be added
self._buildAction('AVTransport', self.av_transport)
self._buildAction('RenderingControl', self.rendering_control)
self._buildAction('ConnectionManager', self.conection_manager)
Expand Down Expand Up @@ -221,7 +222,7 @@ def addSubcribe(self, service, url, timeout=1800):
}
logger.error("SUBSCRIBE ADD")
client = ObserveClient(service, url, timeout)
self.eventSubcribes[client.sid] = client
self.appendDeviceQueue.put(client)
threading.Thread(target=self._sendInitEvent,
kwargs={
'service': service,
Expand Down Expand Up @@ -265,6 +266,11 @@ def _eventCallback(self, stateChangeList):
logger.info("Remove client: {}".format(sid))
del self.eventSubcribes[sid]
self.removedDeviceQueue.task_done()
# add clients
while not self.appendDeviceQueue.empty():
client = self.appendDeviceQueue.get()
self.eventSubcribes[client.sid] = client
self.appendDeviceQueue.task_done()
# send stateChangeList to client
for sid in self.eventSubcribes:
client = self.eventSubcribes[sid]
Expand Down

0 comments on commit 17f003c

Please sign in to comment.