server: use websocket's own broadcast method()
I hope this will reduce latency. Initial tests looked a bit better but not great.
This commit is contained in:
parent
0de9c11fc7
commit
615840ac9f
|
@ -4,6 +4,7 @@ import json
|
|||
import logging
|
||||
import re
|
||||
|
||||
from websockets.asyncio.connection import broadcast
|
||||
from websockets.asyncio.server import serve
|
||||
|
||||
__VERSION__ = "0.0.1"
|
||||
|
@ -175,9 +176,7 @@ class Client:
|
|||
raise
|
||||
|
||||
async def _send_to_group(self, group, **kwargs):
|
||||
async with asyncio.TaskGroup() as tg:
|
||||
for member in group:
|
||||
tg.create_task(member._send(ignore_exceptions=True, **kwargs))
|
||||
broadcast([c.websocket for c in group], json.dumps(kwargs).encode() + b"\n")
|
||||
|
||||
async def _send_error(self, msg: str):
|
||||
await self._send(type="error", message=msg)
|
||||
|
|
Loading…
Reference in New Issue