mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
add event listeners in sioserver.py
added event listeners for sending csv data from blender and receiving operator data from web UI
This commit is contained in:
@@ -2,8 +2,9 @@ import argparse
|
||||
from aiohttp import web
|
||||
import socketio
|
||||
import pystache
|
||||
import json
|
||||
|
||||
sio_port = 8080
|
||||
sio_port = 8080 # default port
|
||||
|
||||
sio = socketio.AsyncServer(
|
||||
cors_allowed_origins="*",
|
||||
@@ -34,6 +35,11 @@ class WebNamespace(socketio.AsyncNamespace):
|
||||
async def on_disconnect(self, sid):
|
||||
print(f"Web client disconnected: {sid}")
|
||||
|
||||
async def on_operator(self, sid, data):
|
||||
print(f"Web client {sid} operator: {data}")
|
||||
json_data = json.loads(data)
|
||||
await sio.emit("web_operator", json_data, namespace="/blender", room=json_data["blenderId"])
|
||||
|
||||
|
||||
# Blender namespace
|
||||
class BlenderNamespace(socketio.AsyncNamespace):
|
||||
@@ -58,6 +64,17 @@ class BlenderNamespace(socketio.AsyncNamespace):
|
||||
blender_messages[sid] = data
|
||||
await sio.emit("blender_data", {"blenderId": sid, "data": data}, namespace="/web")
|
||||
|
||||
async def on_default_data(self, sid, data):
|
||||
print(f"Default data from Blender client {sid}: {data}")
|
||||
# blender_messages[sid] = data
|
||||
# await sio.emit("blender_data", {"blenderId": sid, "data": data}, namespace="/web")
|
||||
|
||||
async def on_csv_data(self, sid, data):
|
||||
print(f"CSV data from Blender client {sid}: {data}")
|
||||
# Store the message and forward it to the web client
|
||||
blender_messages[sid] = data
|
||||
await sio.emit("csv_data", {"blenderId": sid, "data": data}, namespace="/web")
|
||||
|
||||
|
||||
# Attach namespaces
|
||||
sio.register_namespace(WebNamespace("/web"))
|
||||
|
||||
Reference in New Issue
Block a user