feat: Упрощено взаимодействие по вебсокетам между клиентом и сервером
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import inspect
|
||||
import server
|
||||
from fastapi import WebSocket
|
||||
|
||||
_EVENTS = {}
|
||||
|
||||
@@ -15,9 +17,12 @@ def event(event_name: str, priority: int = 9999):
|
||||
return func
|
||||
return inlineEvent
|
||||
|
||||
async def call_event(event_name: str, *args, **kwargs):
|
||||
async def call_event(event_name: str, connection: WebSocket, uuid: str | None, *args, **kwargs):
|
||||
if event_name not in _EVENTS:
|
||||
return
|
||||
|
||||
for item in _EVENTS[event_name]:
|
||||
await item['function'](*args, **kwargs)
|
||||
result = await item['function'](*args, **kwargs)
|
||||
if uuid is None or result is None:
|
||||
return
|
||||
await server.Server.send(connection = connection, uuid = uuid, message = result)
|
||||
|
||||
Reference in New Issue
Block a user