mirror of
https://github.com/kawasaki/pyscrlink.git
synced 2026-01-05 03:00:13 +01:00
Revert "BLESession.notify: Send out notifications at once to avoid interruption"
This reverts commit 2c7a10f848.
It turned out that string join with '\n' is not the proper way to pack
multiple JSON messages to Scratch Lego Boost extension.
This commit is contained in:
@@ -95,22 +95,20 @@ class Session():
|
||||
Notify BT/BLE device events to scratch.
|
||||
"""
|
||||
logger.debug("start to notify")
|
||||
# merge all notifications queued
|
||||
notifications = []
|
||||
# flush notification queue
|
||||
while not self.notification_queue.empty():
|
||||
method, params = self.notification_queue.get()
|
||||
notifications.append(self._build_notification(method, params))
|
||||
# send merged notifications
|
||||
future = asyncio.run_coroutine_threadsafe(
|
||||
self.websocket.send('\n'.join(notifications)), self.loop)
|
||||
result = future.result()
|
||||
self._send_notification(method, params)
|
||||
|
||||
def _build_notification(self, method, params):
|
||||
def _send_notification(self, method, params):
|
||||
jsonn = { 'jsonrpc': "2.0", 'method': method }
|
||||
jsonn['params'] = params
|
||||
notification = json.dumps(jsonn)
|
||||
logger.debug(f"notification: {notification}")
|
||||
return notification
|
||||
|
||||
future = asyncio.run_coroutine_threadsafe(
|
||||
self.websocket.send(notification), self.loop)
|
||||
result = future.result()
|
||||
|
||||
async def handle(self):
|
||||
logger.debug("start session hanlder")
|
||||
|
||||
Reference in New Issue
Block a user