mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-30 10:34:28 +02:00
added vlads suggestion
This commit is contained in:
@ -2,7 +2,7 @@ import asyncio
|
|||||||
import json
|
import json
|
||||||
from binascii import unhexlify
|
from binascii import unhexlify
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
from typing import Dict, Optional, Tuple
|
from typing import Dict, Optional, Tuple, List
|
||||||
from urllib.parse import parse_qs, urlparse
|
from urllib.parse import parse_qs, urlparse
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
@ -384,25 +384,30 @@ def fee_reserve(amount_msat: int) -> int:
|
|||||||
return max(int(RESERVE_FEE_MIN), int(amount_msat * RESERVE_FEE_PERCENT / 100.0))
|
return max(int(RESERVE_FEE_MIN), int(amount_msat * RESERVE_FEE_PERCENT / 100.0))
|
||||||
|
|
||||||
|
|
||||||
class websocketConnectionManager:
|
class WebsocketConnectionManager:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.active_connections: List[WebSocket] = []
|
self.active_connections: List[WebSocket] = []
|
||||||
|
return
|
||||||
|
|
||||||
async def connect(self, websocket: WebSocket, item_id: str):
|
async def connect(self, websocket: WebSocket, item_id: str):
|
||||||
await websocket.accept()
|
await websocket.accept()
|
||||||
websocket.id = item_id
|
if item_id not in self.active_connections:
|
||||||
self.active_connections.append(websocket)
|
websocket.id = item_id
|
||||||
|
self.active_connections.append(websocket)
|
||||||
|
return
|
||||||
|
|
||||||
def disconnect(self, websocket: WebSocket):
|
def disconnect(self, websocket: WebSocket):
|
||||||
self.active_connections.remove(websocket)
|
self.active_connections.remove(websocket)
|
||||||
|
return
|
||||||
|
|
||||||
async def send_data(self, message: str, item_id: str):
|
async def send_data(self, message: str, item_id: str):
|
||||||
for connection in self.active_connections:
|
for connection in self.active_connections:
|
||||||
if connection.id == item_id:
|
if connection.id == item_id:
|
||||||
await connection.send_text(message)
|
await connection.send_text(message)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
websocketManager = websocketConnectionManager()
|
websocketManager = WebsocketConnectionManager()
|
||||||
|
|
||||||
|
|
||||||
async def websocketUpdater(item_id, data):
|
async def websocketUpdater(item_id, data):
|
||||||
|
Reference in New Issue
Block a user