diff --git a/src/bonsai/bonsai/bim/data/webui/templates/demo.html b/src/bonsai/bonsai/bim/data/webui/templates/demo.html index 40576aca69..151a7948e8 100644 --- a/src/bonsai/bonsai/bim/data/webui/templates/demo.html +++ b/src/bonsai/bonsai/bim/data/webui/templates/demo.html @@ -81,7 +81,7 @@
This demo showcases how Bonsai's Web UI interacts with a WebSocket server. The demo illustrates how the Web UI establishes a connection, exchanges data with the server, and updates the UI dynamically based on incoming data.
-You can use the above textbox to send a message to Bonsai!
+You can use the above textbox to send a message to Bonsai which will be printed to the console!
If you prefer, you can explore the source code directly in the data/webui directory:
The server forwards this operator to the appropriate Bonsai instance, where it is processed by functions like sio_listen_web_operator and check_operator_queue in tool/web.py.
+ +the sio_listen_web_operator function is automatically called when the event web_operator is emitted to Bonsai. It takes the web operator and attempts to put it in a web operators queue.
+ +@classmethod
+async def sio_listen_web_operator(cls, data):
+ try:
+ web_operator_queue.put_nowait(data)
+ except queue.Full:
+ pass
+
+
+ then the check_operator_queue function is called by a timer that is run every second to retrieve operators from the queue and handle them
+ +@classmethod
+def check_operator_queue(cls):
+ if not bpy.context.scene.WebProperties.is_connected:
+ with web_operator_queue.mutex:
+ web_operator_queue.queue.clear()
+ return None # unregister timer if not connected
+
+ while not web_operator_queue.empty():
+ operator = web_operator_queue.get_nowait()
+ if not operator:
+ continue
+ if operator["sourcePage"] == "csv":
+ cls.handle_csv_operator(operator["operator"])
+ elif operator["sourcePage"] == "gantt":
+ cls.handle_gantt_operator(operator["operator"])
+ elif operator["sourcePage"] == "drawings":
+ cls.handle_drawings_operator(operator["operator"])
+ elif operator["sourcePage"] == "demo":
+ message = operator["operator"]["message"]
+ print(f"Message from demo page: {message}")
+ return 1.0
+
+
+ Here we check the source page of the operator and call the appropriate handler for that page.