Merge branch 'main' into FinalAdminUI
This commit is contained in:
commit
940615cb0b
2 changed files with 20 additions and 12 deletions
|
|
@ -388,7 +388,7 @@ async def subscribe_wallet_invoices(request: Request, wallet: Wallet):
|
||||||
|
|
||||||
yield dict(data=jdata, event=typ)
|
yield dict(data=jdata, event=typ)
|
||||||
except asyncio.CancelledError as e:
|
except asyncio.CancelledError as e:
|
||||||
logger.debug(f"CancelledError on listener {uid}: {e}")
|
logger.debug(f"removing listener for wallet {uid}")
|
||||||
api_invoice_listeners.pop(uid)
|
api_invoice_listeners.pop(uid)
|
||||||
task.cancel()
|
task.cancel()
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -148,18 +148,26 @@ class LNbitsWallet(Wallet):
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
async with httpx.AsyncClient(timeout=None, headers=self.key) as client:
|
async with httpx.AsyncClient(timeout=None, headers=self.key) as client:
|
||||||
async with client.stream("GET", url) as r:
|
del client.headers[
|
||||||
|
"accept-encoding"
|
||||||
|
] # we have to disable compression for SSEs
|
||||||
|
async with client.stream(
|
||||||
|
"GET", url, content="text/event-stream"
|
||||||
|
) as r:
|
||||||
|
sse_trigger = False
|
||||||
async for line in r.aiter_lines():
|
async for line in r.aiter_lines():
|
||||||
if line.startswith("data:"):
|
# The data we want to listen to is of this shape:
|
||||||
try:
|
# event: payment-received
|
||||||
data = json.loads(line[5:])
|
# data: {.., "payment_hash" : "asd"}
|
||||||
except json.decoder.JSONDecodeError:
|
if line.startswith("event: payment-received"):
|
||||||
continue
|
sse_trigger = True
|
||||||
|
continue
|
||||||
if type(data) is not dict:
|
elif sse_trigger and line.startswith("data:"):
|
||||||
continue
|
data = json.loads(line[len("data:") :])
|
||||||
|
sse_trigger = False
|
||||||
yield data["payment_hash"] # payment_hash
|
yield data["payment_hash"]
|
||||||
|
else:
|
||||||
|
sse_trigger = False
|
||||||
|
|
||||||
except (OSError, httpx.ReadError, httpx.ConnectError, httpx.ReadTimeout):
|
except (OSError, httpx.ReadError, httpx.ConnectError, httpx.ReadTimeout):
|
||||||
pass
|
pass
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue