55} from '@stream-io/video-client' ;
66import { useCall , useCallStateHooks } from '@stream-io/video-react-bindings' ;
77import { useEffect , useRef } from 'react' ;
8- import { voipPushNotificationCallCId$ } from '../../utils/push/internal/rxSubjects' ;
98import { getCallingxLibIfAvailable } from '../../utils/push/libs/callingx' ;
109
1110//calling state methods are not exhaustive, so we need to add more methods to cover all the cases
@@ -40,53 +39,40 @@ export const useCallingExpWithCallingStateEffect = () => {
4039 useEffect ( ( ) => {
4140 return ( ) => {
4241 const callingx = getCallingxLibIfAvailable ( ) ;
43- if ( ! callingx ) {
42+ if ( ! callingx || ! activeCallCid ) {
4443 return ;
4544 }
46- //as an alternative think about method which will return CallKit/Telecom state for given cid
47- const incomingCallCid = RxUtils . getCurrentValue (
48- voipPushNotificationCallCId$ ,
49- ) ;
50- if (
51- ! activeCallCid ||
52- ! incomingCallCid ||
53- incomingCallCid !== activeCallCid
54- ) {
45+
46+ const isCallRegistered = callingx . isCallRegistered ( activeCallCid ) ;
47+ if ( ! isCallRegistered ) {
5548 logger . debug (
56- `No active call cid to end in calling exp: ${ activeCallCid } incomingCallCid : ${ incomingCallCid } ` ,
49+ `No active call cid to end in calling exp: ${ activeCallCid } isCallRegistered : ${ isCallRegistered } ` ,
5750 ) ;
5851 return ;
5952 }
6053 //if incoming stream call was unmounted, we need to end the call in CallKit/Telecom
6154 //TODO: think about sending appropriate reason for end call
55+ logger . debug ( `Ending call in calling exp: ${ activeCallCid } ` ) ;
6256 callingx . endCallWithReason ( activeCallCid , 'local' ) ;
63- voipPushNotificationCallCId$ . next ( undefined ) ;
6457 } ;
6558 } , [ activeCallCid ] ) ;
6659
6760 useEffect ( ( ) => {
6861 const callingx = getCallingxLibIfAvailable ( ) ;
69- if ( ! callingx ) {
62+ if ( ! callingx || ! activeCallCid ) {
7063 return ;
7164 }
7265
73- //as an alternative think about method which will return CallKit/Telecom state for given cid
74- const incomingCallCid = RxUtils . getCurrentValue (
75- voipPushNotificationCallCId$ ,
76- ) ;
77- if (
78- ! incomingCallCid ||
79- ! activeCallCid ||
80- incomingCallCid !== activeCallCid
81- ) {
66+ const isCallRegistered = callingx . isCallRegistered ( activeCallCid ) ;
67+ if ( ! isCallRegistered ) {
8268 logger . debug (
83- `No active call cid to end in calling exp: ${ activeCallCid } incomingCallCid : ${ incomingCallCid } ` ,
69+ `No active call cid to end in calling exp: ${ activeCallCid } isCallRegistered : ${ isCallRegistered } ` ,
8470 ) ;
8571 return ;
8672 }
8773
8874 logger . debug (
89- `useEffect: ${ activeCallCid } incomingCallCid : ${ incomingCallCid } ` ,
75+ `useEffect: ${ activeCallCid } isCallRegistered : ${ isCallRegistered } ` ,
9076 ) ;
9177 logger . debug (
9278 `prevState.current: ${ prevState . current } , current callingState: ${ callingState } ` ,
@@ -99,7 +85,7 @@ export const useCallingExpWithCallingStateEffect = () => {
9985 ) {
10086 //in case call was registered as incoming and state changed to joined, we need to answer the call
10187 logger . debug (
102- `Should accept call in callkeep: ${ activeCallCid } callCid : ${ incomingCallCid } ` ,
88+ `Should accept call in callkeep: ${ activeCallCid } isCallRegistered : ${ isCallRegistered } ` ,
10389 ) ;
10490 callingx . answerIncomingCall ( activeCallCid ) ;
10591 } else if (
@@ -110,7 +96,6 @@ export const useCallingExpWithCallingStateEffect = () => {
11096 logger . debug ( `Should end call in callkeep: ${ activeCallCid } ` ) ;
11197 //TODO: think about sending appropriate reason for end call
11298 callingx . endCallWithReason ( activeCallCid , 'local' ) ;
113- voipPushNotificationCallCId$ . next ( undefined ) ;
11499 }
115100 }
116101
@@ -119,21 +104,14 @@ export const useCallingExpWithCallingStateEffect = () => {
119104
120105 useEffect ( ( ) => {
121106 const callingx = getCallingxLibIfAvailable ( ) ;
122- if ( ! callingx ) {
107+ if ( ! callingx || ! activeCallCid ) {
123108 return ;
124109 }
125110
126- //for now supports only incoming calls
127- const incomingCallCid = RxUtils . getCurrentValue (
128- voipPushNotificationCallCId$ ,
129- ) ;
130- if (
131- ! incomingCallCid ||
132- ! activeCallCid ||
133- incomingCallCid !== activeCallCid
134- ) {
111+ const isCallRegistered = callingx . isCallRegistered ( activeCallCid ) ;
112+ if ( ! isCallRegistered ) {
135113 logger . debug (
136- `No active call cid to set muted in calling exp: ${ activeCallCid } incomingCallCid : ${ incomingCallCid } ` ,
114+ `No active call cid to set muted in calling exp: ${ activeCallCid } isCallRegistered : ${ isCallRegistered } ` ,
137115 ) ;
138116 return ;
139117 }
0 commit comments