add caching of blender messages

This commit is contained in:
Ziad-I
2024-07-17 22:48:01 +03:00
committed by Dion Moult
parent 84d4bf16c3
commit b0fe30c597
@@ -29,6 +29,8 @@ sio = socketio.AsyncServer(
app = web.Application()
sio.attach(app)
# represents a caching for blender messages
blender_messages = {}
@@ -39,6 +41,8 @@ class WebNamespace(socketio.AsyncNamespace):
async def on_connect(self, sid, environ):
print(f"Web client connected: {sid}")
if blender_messages:
await self.send_cached_messages(sid)
async def on_disconnect(self, sid):
print(f"Web client disconnected: {sid}")
@@ -51,6 +55,14 @@ class WebNamespace(socketio.AsyncNamespace):
room=data["blenderId"],
)
async def send_cached_messages(self, sid):
# Send cached messages to the connected web client
for blenderId, messages in blender_messages.items():
if "csv_data" in messages:
await self.emit("csv_data", {"blenderId": blenderId, "data": messages["csv_data"]}, room=sid)
if "gantt_data" in messages:
await self.emit("gantt_data", {"blenderId": blenderId, "data": messages["gantt_data"]}, room=sid)
# Blender namespace
class BlenderNamespace(socketio.AsyncNamespace):