initiating call should return call object when link is established

This commit is contained in:
liamcottle 2024-05-25 23:52:41 +12:00
commit a16393d07d
3 changed files with 11 additions and 35 deletions

View file

@ -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) {

View file

@ -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:

4
web.py
View file

@ -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: