From 7835baa7a251077f9b33347626877074c1274846 Mon Sep 17 00:00:00 2001 From: Aleksander Nicacio da Silva Date: Mon, 30 Dec 2024 19:28:06 -0300 Subject: [PATCH] feat: improved session id --- app/lib/voip/VoipClient.ts | 10 +++++++++- app/sagas/voip.ts | 16 ++++++++-------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/lib/voip/VoipClient.ts b/app/lib/voip/VoipClient.ts index 9d92e977e6..03806984eb 100644 --- a/app/lib/voip/VoipClient.ts +++ b/app/lib/voip/VoipClient.ts @@ -612,6 +612,14 @@ class VoipClient { return null; } + public getSessionId(): string { + if (!this.session?.dialog) { + throw Error('no active call'); + } + + return this.session.dialog.id.substring(0, 36); // UUID + } + public getSession(): VoipSession | null { const type = this.getSessionType(); @@ -634,7 +642,7 @@ class VoipClient { return { type, - id: this.session.id, + id: this.getSessionId(), contact: this.getContactInfo() as ContactInfo, transferedBy: this.getReferredBy(), isMuted: this.isMuted(), diff --git a/app/sagas/voip.ts b/app/sagas/voip.ts index 037f7559ec..15246ef54e 100644 --- a/app/sagas/voip.ts +++ b/app/sagas/voip.ts @@ -118,11 +118,12 @@ function* initVoipClient() { function* attachCallKeepListeners(voipClient: VoipClient) { const channel = eventChannel(emit => { - RNCallKeep.addEventListener('answerCall', ({ callUUID }) => { + RNCallKeep.addEventListener('answerCall', () => { + const sessionId = voipClient.getSessionId(); RNCallKeep.backToForeground(); voipClient.answer(); - RNCallKeep.setCurrentCallActive(callUUID); - console.log(`anwerCall ${callUUID}`); + RNCallKeep.setCurrentCallActive(sessionId); + console.log(`anwerCall ${sessionId}`); }); RNCallKeep.addEventListener('endCall', () => { @@ -235,11 +236,10 @@ function* attachClientListeners(voipClient: VoipClient) { } function* takeVoipActions(voipClient: VoipClient) { - yield takeEvery(VOIP.START_CALL, ({ payload: number }) => { - voipClient.call(number).then(() => { - const session = voipClient.getSession() as VoipOutgoingSession; - RNCallKeep.startCall(session.id, number, number, 'number', false); - }); + yield takeEvery(VOIP.START_CALL, async ({ payload: number }) => { + await voipClient.call(number); + console.log(`STARTING CALL ${voipClient.getSessionId()}`); + RNCallKeep.startCall(voipClient.getSessionId(), number, number, 'number', false); }); yield takeEvery(VOIP.END_CALL, () => {