def print_event(event: Event) -> None: """ Used from main script to print event as JSON. """ print(event.to_json()) sys.stdout.flush()
async def broadcast_event(event: events.Event) -> None: logger.debug(event) if glob.USERS.interfaces: message = event.to_json() await asyncio.gather(*[ws_server.send_json_to_client(intf, message) for intf in glob.USERS.interfaces])
async def broadcast_event( event: events.Event, exclude_ui: Optional[WebSocketServerProtocol] = None) -> None: if (exclude_ui is None and glob.INTERFACES) or (exclude_ui and len(glob.INTERFACES) > 1): message = event.to_json() await asyncio.gather(*[ ws_server.send_json_to_client(intf, message) for intf in glob.INTERFACES if intf != exclude_ui ])
async def event(interface: WebSocketServerProtocol, event: events.Event) -> None: await ws_server.send_json_to_client(interface, event.to_json())
async def send_to_clients(event: Event) -> None: if CLIENTS: data = event.to_json() await asyncio.wait([client.send(data) for client in CLIENTS])