Work on websockets end points and management
This commit is contained in:
@@ -66,6 +66,7 @@ async def get(response: Response = Response):
|
||||
|
||||
class ConnectionManager:
|
||||
def __init__(self):
|
||||
# NOTE: The active_connections list should be in Redis
|
||||
self.active_connections: List[WebSocket] = []
|
||||
|
||||
async def connect(self, websocket: WebSocket):
|
||||
@@ -76,6 +77,10 @@ class ConnectionManager:
|
||||
def disconnect(self, websocket: WebSocket):
|
||||
self.active_connections.remove(websocket)
|
||||
|
||||
|
||||
# Targets: echo, direct, group, broadcast
|
||||
# send_ text, bytes, json
|
||||
# receive_ text, bytes, json
|
||||
async def echo(self, message: str, websocket: WebSocket):
|
||||
log.setLevel(logging.DEBUG)
|
||||
# log.debug(dir(websocket))
|
||||
@@ -94,7 +99,7 @@ class ConnectionManager:
|
||||
log.debug(connection)
|
||||
await connection.send_text(message)
|
||||
|
||||
async def group(self, group_id: str, data: str):
|
||||
async def group(self, group_id: str, data: dict):
|
||||
log.setLevel(logging.DEBUG)
|
||||
log.debug(locals())
|
||||
|
||||
@@ -205,6 +210,9 @@ async def ws_client_id(
|
||||
log.debug(f'Command: {cmd}')
|
||||
log.debug(f'Message: {msg}')
|
||||
|
||||
data['client_id'] = client_id
|
||||
data['group_id'] = group_id
|
||||
|
||||
await manager.group(group_id=group_id, data=data)
|
||||
|
||||
# if msg_type:
|
||||
|
||||
Reference in New Issue
Block a user