mirror of
https://github.com/kawasaki/pyscrlink.git
synced 2025-09-07 18:20:07 +02: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.
|
Notify BT/BLE device events to scratch.
|
||||||
"""
|
"""
|
||||||
logger.debug("start to notify")
|
logger.debug("start to notify")
|
||||||
# merge all notifications queued
|
# flush notification queue
|
||||||
notifications = []
|
|
||||||
while not self.notification_queue.empty():
|
while not self.notification_queue.empty():
|
||||||
method, params = self.notification_queue.get()
|
method, params = self.notification_queue.get()
|
||||||
notifications.append(self._build_notification(method, params))
|
self._send_notification(method, params)
|
||||||
# send merged notifications
|
|
||||||
future = asyncio.run_coroutine_threadsafe(
|
|
||||||
self.websocket.send('\n'.join(notifications)), self.loop)
|
|
||||||
result = future.result()
|
|
||||||
|
|
||||||
def _build_notification(self, method, params):
|
def _send_notification(self, method, params):
|
||||||
jsonn = { 'jsonrpc': "2.0", 'method': method }
|
jsonn = { 'jsonrpc': "2.0", 'method': method }
|
||||||
jsonn['params'] = params
|
jsonn['params'] = params
|
||||||
notification = json.dumps(jsonn)
|
notification = json.dumps(jsonn)
|
||||||
logger.debug(f"notification: {notification}")
|
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):
|
async def handle(self):
|
||||||
logger.debug("start session hanlder")
|
logger.debug("start session hanlder")
|
||||||
|
Reference in New Issue
Block a user