mirror of
https://github.com/lnbits/lnbits.git
synced 2025-09-28 21:02:31 +02:00
black
This commit is contained in:
@@ -701,6 +701,7 @@ async def api_auditor(wallet: WalletTypeInfo = Depends(get_key_type)):
|
|||||||
|
|
||||||
##################UNIVERSAL WEBSOCKET MANAGER########################
|
##################UNIVERSAL WEBSOCKET MANAGER########################
|
||||||
|
|
||||||
|
|
||||||
class websocketConnectionManager:
|
class websocketConnectionManager:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.active_connections: List[WebSocket] = []
|
self.active_connections: List[WebSocket] = []
|
||||||
@@ -718,8 +719,10 @@ class websocketConnectionManager:
|
|||||||
if connection.id == item_id:
|
if connection.id == item_id:
|
||||||
await connection.send_text(message)
|
await connection.send_text(message)
|
||||||
|
|
||||||
|
|
||||||
manager = websocketConnectionManager()
|
manager = websocketConnectionManager()
|
||||||
|
|
||||||
|
|
||||||
@core_app.websocket("/api/v1/ws/{item_id}")
|
@core_app.websocket("/api/v1/ws/{item_id}")
|
||||||
async def websocket_connect(websocket: WebSocket, item_id: str):
|
async def websocket_connect(websocket: WebSocket, item_id: str):
|
||||||
await manager.connect(websocket, item_id)
|
await manager.connect(websocket, item_id)
|
||||||
@@ -729,6 +732,7 @@ async def websocket_connect(websocket: WebSocket, item_id: str):
|
|||||||
except WebSocketDisconnect:
|
except WebSocketDisconnect:
|
||||||
manager.disconnect(websocket)
|
manager.disconnect(websocket)
|
||||||
|
|
||||||
|
|
||||||
@core_app.post("/api/v1/ws/{item_id}")
|
@core_app.post("/api/v1/ws/{item_id}")
|
||||||
async def websocket_update(item_id: str, data: str):
|
async def websocket_update(item_id: str, data: str):
|
||||||
try:
|
try:
|
||||||
@@ -737,6 +741,7 @@ async def websocket_update(item_id: str, data: str):
|
|||||||
except:
|
except:
|
||||||
return {"sent": False, "data": data}
|
return {"sent": False, "data": data}
|
||||||
|
|
||||||
|
|
||||||
@core_app.get("/api/v1/ws/{item_id}/{data}")
|
@core_app.get("/api/v1/ws/{item_id}/{data}")
|
||||||
async def websocket_update(item_id: str, data: str):
|
async def websocket_update(item_id: str, data: str):
|
||||||
try:
|
try:
|
||||||
@@ -745,7 +750,6 @@ async def websocket_update(item_id: str, data: str):
|
|||||||
except:
|
except:
|
||||||
return {"sent": False, "data": data}
|
return {"sent": False, "data": data}
|
||||||
|
|
||||||
|
|
||||||
async def updater(item_id, data):
|
async def updater(item_id, data):
|
||||||
return await manager.send_data(
|
return await manager.send_data(f"{data}", item_id)
|
||||||
f"{data}", item_id
|
|
||||||
)
|
|
||||||
|
Reference in New Issue
Block a user