From a16393d07dc3c176c16ec2cde4d05e13c7c74f5d Mon Sep 17 00:00:00 2001 From: liamcottle Date: Sat, 25 May 2024 23:52:41 +1200 Subject: [PATCH] initiating call should return call object when link is established --- public/call.html | 25 +++---------------------- src/audio_call_manager.py | 19 +++++++------------ web.py | 4 ++-- 3 files changed, 12 insertions(+), 36 deletions(-) diff --git a/public/call.html b/public/call.html index 5fc7c49..b22dd0d 100644 --- a/public/call.html +++ b/public/call.html @@ -364,30 +364,11 @@ }, }); - // get call hash from response - const hash = response.data.hash; + // get audio call from response + const audioCall = response.data.audio_call; // join call - const maxJoinAttempts = 15; - for(var i = 0; i < maxJoinAttempts; i++){ - try { - - // wait 1 second before attempting to join call - await new Promise((resolve, reject) => setTimeout(resolve, 1000)); - - // attempt to join call - await this.joinCall(hash); - - // success, we no longer need to attempt to join - return; - - } catch(e) { - console.log(e); - } - } - - // failed to join call - alert("timed out attempting to join call"); + await this.joinCall(audioCall.hash); } catch(e) { diff --git a/src/audio_call_manager.py b/src/audio_call_manager.py index 2ebb713..b277099 100644 --- a/src/audio_call_manager.py +++ b/src/audio_call_manager.py @@ -145,7 +145,7 @@ class AudioCallManager: return None # 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: + async def initiate(self, destination_hash: bytes, timeout_seconds: int = 15) -> AudioCall: # determine when to timeout timeout_after_seconds = time.time() + timeout_seconds @@ -177,9 +177,6 @@ class AudioCallManager: # create link link = RNS.Link(server_destination) - # register link state callbacks - link.set_link_established_callback(self.on_link_established) - # wait until we have established a link, or give up after the configured timeout while link.status is not RNS.Link.ACTIVE and time.time() < timeout_after_seconds: await asyncio.sleep(0.1) @@ -188,19 +185,17 @@ class AudioCallManager: if link.status is not RNS.Link.ACTIVE: raise CallFailedException("Could not establish link to destination.") - return link.hash - - def on_link_established(self, link: RNS.Link): - - # todo: this can be optional, it's only being sent by default for ui, can be removed - link.identify(self.identity) - - # create audio call + # link is now established, create audio call audio_call = AudioCall(link, is_outbound=True) # handle new outgoing call self.handle_outgoing_call(audio_call) + # todo: this can be optional, it's only being sent by default for ui, can be removed + link.identify(self.identity) + + return audio_call + class AudioCallReceiver: diff --git a/web.py b/web.py index 787ef81..84d605f 100644 --- a/web.py +++ b/web.py @@ -260,9 +260,9 @@ class ReticulumWebChat: # initiate audio call try: - link_hash = await self.audio_call_manager.initiate(destination_hash, timeout_seconds) + audio_call = await self.audio_call_manager.initiate(destination_hash, timeout_seconds) return web.json_response({ - "hash": link_hash.hex(), + "audio_call": self.convert_audio_call_to_dict(audio_call), }) except Exception as e: