throw helpful exception when initiating a call fails

This commit is contained in:
liamcottle
2024-05-23 22:28:34 +12:00
parent c9541fd532
commit bc865615d4
2 changed files with 17 additions and 10 deletions

View File

@@ -8,6 +8,10 @@ import RNS
# todo allowlist/denylist for incoming calls
class CallFailedException(Exception):
pass
class AudioCall:
def __init__(self, link: RNS.Link, is_outbound: bool):
@@ -131,7 +135,7 @@ class AudioCallManager:
self.audio_calls.remove(audio_call)
# attempts to initiate a call to the provided destination and returns the link hash on success
async def initiate(self, destination_hash: bytes, timeout_seconds: int = 15) -> bytes | None:
async def initiate(self, destination_hash: bytes, timeout_seconds: int = 15) -> bytes:
# check if we have a path to the destination
if not RNS.Transport.has_path(destination_hash):
@@ -146,7 +150,7 @@ class AudioCallManager:
# if we still don't have a path, we can't establish a link, so bail out
if not RNS.Transport.has_path(destination_hash):
return None
raise CallFailedException("Could not find path to destination.")
# create outbound destination to initiate audio calls
server_identity = RNS.Identity.recall(destination_hash)

19
web.py
View File

@@ -227,15 +227,18 @@ class ReticulumWebChat:
destination_hash = bytes.fromhex(destination_hash)
# initiate audio call
link_hash = await self.audio_call_manager.initiate(destination_hash, timeout_seconds)
if link_hash is None:
return web.json_response({
"message": "timed out initiating call",
}, status=503)
try:
return web.json_response({
"hash": link_hash.hex(),
})
link_hash = await self.audio_call_manager.initiate(destination_hash, timeout_seconds)
return web.json_response({
"hash": link_hash.hex(),
})
except Exception as e:
return web.json_response({
"message": "Call Failed: {}".format(str(e)),
}, status=503)
# handle websocket client for sending and receiving audio packets in a call
@routes.get("/api/v1/calls/{audio_call_link_hash}/audio")