44import json
55import logging
66from datetime import datetime
7- from typing import Any , TypeVar , Union
7+ from typing import Any , TypeVar
88
99from fastapi import APIRouter , WebSocket , WebSocketDisconnect
1010from sqlmodel import Session , select
@@ -27,7 +27,7 @@ def __init__(self):
2727 async def connect (
2828 self ,
2929 websocket : WebSocket ,
30- client_id : Union [ int , str ] ,
30+ client_id : int | str ,
3131 register_client : bool = True ,
3232 ):
3333 await websocket .accept ()
@@ -48,7 +48,7 @@ def _register_new_client(client_id: int):
4848 murfey_db .commit ()
4949 murfey_db .close ()
5050
51- def disconnect (self , client_id : Union [ int , str ] , unregister_client : bool = True ):
51+ def disconnect (self , client_id : int | str , unregister_client : bool = True ):
5252 self .active_connections .pop (client_id )
5353 if unregister_client :
5454 murfey_db : Session = next (get_murfey_db_session ())
@@ -97,7 +97,7 @@ async def websocket_endpoint(websocket: WebSocket, client_id: int):
9797@ws .websocket ("/connect/{client_id}" )
9898async def websocket_connection_endpoint (
9999 websocket : WebSocket ,
100- client_id : Union [ int , str ] ,
100+ client_id : int | str ,
101101):
102102 await manager .connect (websocket , client_id , register_client = False )
103103 await manager .broadcast (f"Client { client_id } joined" )
@@ -161,7 +161,7 @@ async def close_ws_connection(client_id: int):
161161
162162
163163@ws .delete ("/connect/{client_id}" )
164- async def close_unrecorded_ws_connection (client_id : Union [ int , str ] ):
164+ async def close_unrecorded_ws_connection (client_id : int | str ):
165165 client_id_str = str (client_id ).replace ("\r \n " , "" ).replace ("\n " , "" )
166166 log .info (f"Disconnecting { client_id_str } " )
167167 manager .disconnect (client_id )
0 commit comments