From d35d4f0b926209ff90af23dcdd1f1369a6106ada Mon Sep 17 00:00:00 2001 From: j2gg0s Date: Tue, 27 May 2025 14:02:27 +0800 Subject: [PATCH] feat(server): add happen_at to event Using call_soon_threadsafe in send_sync may cause a discrepancy between the time the client receives the message and the actual time the event occurred. We add the sending timestamp so that clients with such needs can be aware of when the event actually occurred. --- server.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server.py b/server.py index 1b0a7360127..d95755063e8 100644 --- a/server.py +++ b/server.py @@ -1,5 +1,6 @@ import os import sys +import time import asyncio import traceback @@ -819,6 +820,8 @@ async def send_json(self, event, data, sid=None): await send_socket_catch_exception(self.sockets[sid].send_json, message) def send_sync(self, event, data, sid=None): + if isinstance(data, dict): + data["happen_at"] = time.time() self.loop.call_soon_threadsafe( self.messages.put_nowait, (event, data, sid))