@@ -21,7 +21,7 @@ export function getCallDisplayName(
2121 callMembers : MemberResponse [ ] | undefined ,
2222 participants : StreamVideoParticipant [ ] | undefined ,
2323 currentUserId : string | undefined ,
24- ) {
24+ ) : string {
2525 if ( ! callMembers || ! participants || ! currentUserId ) {
2626 return 'Call' ;
2727 }
@@ -53,6 +53,42 @@ export function getCallDisplayName(
5353 return names . sort ( ) . join ( ', ' ) ;
5454}
5555
56+ function getCallDisplayNameFromCall ( call : Call ) : string {
57+ return getCallDisplayName (
58+ call . state . members ,
59+ call . state . participants ,
60+ call . currentUserId ,
61+ ) ;
62+ }
63+
64+ export async function registerOutgoingCall ( call : Call ) {
65+ if ( ! CallingxModule || ! CallingxModule . isSetup ) {
66+ return ;
67+ }
68+
69+ const isOutcomingCall = call . ringing && call . isCreatedByMe ;
70+ if ( ! isOutcomingCall ) {
71+ return ;
72+ }
73+
74+ const logger = videoLoggerSystem . getLogger ( 'callingx' ) ;
75+
76+ try {
77+ logger . debug ( `registerOutgoingCall: Registering outgoing call ${ call . cid } ` ) ;
78+ await CallingxModule . startCall (
79+ call . cid , // unique id for call
80+ call . id , // phone number for display in dialer (we use call id as phone number)
81+ getCallDisplayNameFromCall ( call ) , // display name for display in call screen
82+ call . state . settings ?. video ?. enabled ?? false , // is video call?
83+ ) ;
84+ } catch ( error ) {
85+ logger . error (
86+ `registerOutgoingCall: Error registering outgoing call in callingx: ${ call . cid } ` ,
87+ error ,
88+ ) ;
89+ }
90+ }
91+
5692/**
5793 * Starts the call in the callingx library.
5894 * It is done by client on every join
@@ -61,7 +97,7 @@ export function getCallDisplayName(
6197 * 2. Displays the incoming call in the callingx library
6298 * 3. Optionally for non-ringing calls also when ongoing calls are enabled.
6399 */
64- export async function startCallingxCall ( call : Call , activeCalls : Call [ ] ) {
100+ export async function joinCallingxCall ( call : Call , activeCalls : Call [ ] ) {
65101 if ( ! CallingxModule || ! CallingxModule . isSetup ) {
66102 return ;
67103 }
@@ -70,38 +106,31 @@ export async function startCallingxCall(call: Call, activeCalls: Call[]) {
70106 const isOutcomingCall = call . ringing && call . isCreatedByMe ;
71107 const isIncomingCall = call . ringing && ! call . isCreatedByMe ;
72108
73- const callDisplayName = getCallDisplayName (
74- call . state . members ,
75- call . state . participants ,
76- call . currentUserId ,
77- ) ;
78-
79109 if (
80- ! CallingxModule . isCallTracked ( call . cid ) &&
81- ( isOutcomingCall || ( ! call . ringing && CallingxModule . isOngoingCallsEnabled ) )
110+ isOutcomingCall ||
111+ ( ! call . ringing && CallingxModule . isOngoingCallsEnabled )
82112 ) {
113+ logger . debug ( `joinCallingxCall: Joining call ${ call . cid } ` ) ;
83114 try {
84115 await CallingxModule . startCall (
85116 call . cid , // unique id for call
86117 call . id , // phone number for display in dialer (we use call id as phone number)
87- callDisplayName , // display name for display in call screen
118+ getCallDisplayNameFromCall ( call ) , // display name for display in call screen
88119 call . state . settings ?. video ?. enabled ?? false , // is video call?
89120 ) ;
90121
91122 // Wait for audio session activation on iOS only
92123 if ( Platform . OS === 'ios' ) {
93124 await waitForAudioSessionActivation ( ) ;
94125 }
95-
96- // TODO: this must be done after join call is complete
97- CallingxModule . setCurrentCallActive ( call . cid ) ;
98126 } catch ( error ) {
99127 logger . error (
100128 `startCallingxCall: Error starting call in callingx: ${ call . cid } ` ,
101129 error ,
102130 ) ;
103131 }
104132 } else if ( isIncomingCall ) {
133+ logger . debug ( `joinCallingxCall: Joining incoming call ${ call . cid } ` ) ;
105134 try {
106135 // Leave any existing active ringing calls before joining a new ringing call
107136 const activeCallsToLeave = activeCalls . filter (
@@ -125,7 +154,7 @@ export async function startCallingxCall(call: Call, activeCalls: Call[]) {
125154 await CallingxModule . displayIncomingCall (
126155 call . cid , // unique id for call
127156 call . id , // phone number for display in dialer (we use call id as phone number)
128- callDisplayName , // display name for display in call screen
157+ getCallDisplayNameFromCall ( call ) , // display name for display in call screen
129158 call . state . settings ?. video ?. enabled ?? false , // is video call?
130159 ) ;
131160
@@ -152,14 +181,14 @@ export async function endCallingxCall(call: Call, reason?: EndCallReason) {
152181 return ;
153182 }
154183
184+ const logger = videoLoggerSystem . getLogger ( 'callingx' ) ;
155185 try {
186+ logger . debug ( `endCallingxCall: Ending call ${ call . cid } ` ) ;
156187 await CallingxModule . endCallWithReason ( call . cid , reason ?? 'local' ) ;
157188 } catch ( error ) {
158- videoLoggerSystem
159- . getLogger ( 'callingx' )
160- . error (
161- `endCallingxCall: Error ending call in callingx: ${ call . cid } ` ,
162- error ,
163- ) ;
189+ logger . error (
190+ `endCallingxCall: Error ending call in callingx: ${ call . cid } ` ,
191+ error ,
192+ ) ;
164193 }
165194}
0 commit comments