Skip to content

Commit

Permalink
feat: improved session id
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva committed Dec 30, 2024
1 parent 9669042 commit 7835baa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 9 additions & 1 deletion app/lib/voip/VoipClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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(),
Expand Down
16 changes: 8 additions & 8 deletions app/sagas/voip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,12 @@ function* initVoipClient() {

function* attachCallKeepListeners(voipClient: VoipClient) {
const channel = eventChannel<TActionVoip>(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', () => {
Expand Down Expand Up @@ -235,11 +236,10 @@ function* attachClientListeners(voipClient: VoipClient) {
}

function* takeVoipActions(voipClient: VoipClient) {
yield takeEvery<TStartCallAction>(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<TStartCallAction>(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<TEndCallAction>(VOIP.END_CALL, () => {
Expand Down

0 comments on commit 7835baa

Please sign in to comment.