|
4 | 4 | import json |
5 | 5 | import logging |
6 | 6 | from datetime import datetime |
7 | | -from typing import Any, Dict, TypeVar, Union |
| 7 | +from typing import Any, TypeVar |
8 | 8 |
|
9 | 9 | from fastapi import APIRouter, WebSocket, WebSocketDisconnect |
10 | 10 | from sqlmodel import Session, select |
|
22 | 22 |
|
23 | 23 | class ConnectionManager: |
24 | 24 | def __init__(self): |
25 | | - self.active_connections: Dict[int | str, WebSocket] = {} |
| 25 | + self.active_connections: dict[int | str, WebSocket] = {} |
26 | 26 |
|
27 | 27 | async def connect( |
28 | 28 | self, websocket: WebSocket, client_id: int | str, register_client: bool = True |
@@ -93,7 +93,8 @@ async def websocket_endpoint(websocket: WebSocket, client_id: int): |
93 | 93 |
|
94 | 94 | @ws.websocket("/connect/{client_id}") |
95 | 95 | async def websocket_connection_endpoint( |
96 | | - websocket: WebSocket, client_id: Union[int, str] |
| 96 | + websocket: WebSocket, |
| 97 | + client_id: int | str, |
97 | 98 | ): |
98 | 99 | await manager.connect(websocket, client_id, register_client=False) |
99 | 100 | await manager.broadcast(f"Client {client_id} joined") |
@@ -157,7 +158,7 @@ async def close_ws_connection(client_id: int): |
157 | 158 |
|
158 | 159 |
|
159 | 160 | @ws.delete("/connect/{client_id}") |
160 | | -async def close_unrecorded_ws_connection(client_id: Union[int, str]): |
| 161 | +async def close_unrecorded_ws_connection(client_id: int | str): |
161 | 162 | client_id_str = str(client_id).replace("\r\n", "").replace("\n", "") |
162 | 163 | log.info(f"Disconnecting {client_id_str}") |
163 | 164 | manager.disconnect(client_id) |
|
0 commit comments