Skip to content

Commit 39c4ba7

Browse files
authored
fix: early completion call on iOS remote notifications (#1687)
### Overview rarely didDisplayIncomingCall comes after onNotificationReceived completes, this is problematic as per the voipNotification library. We must complete only at the last after all are processed it seems. But I dont know what the problem is though. ### Test Just ensure that JS calls the completion function in all three scenarios 1. Foregrounded app 2. Backgrounded app 3. Killed off app
1 parent de1ebf4 commit 39c4ba7

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

packages/react-native-sdk/src/hooks/push/useIosCallKeepEventsSetupEffect.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import {
44
voipPushNotificationCallCId$,
55
} from '../../utils/push/internal/rxSubjects';
66
import { getLogger, RxUtils } from '@stream-io/video-client';
7-
import { getCallKeepLib } from '../../utils/push/libs';
7+
import {
8+
getCallKeepLib,
9+
getVoipPushNotificationLib,
10+
} from '../../utils/push/libs';
811
import { StreamVideoRN } from '../../utils/StreamVideoRN';
912
import type { StreamVideoConfig } from '../../utils/StreamVideoRN/types';
1013
import {
@@ -52,21 +55,22 @@ export const useIosCallKeepEventsSetupEffect = () => {
5255
const { remove: removeDisplayIncomingCall } = callkeep.addEventListener(
5356
'didDisplayIncomingCall',
5457
({ callUUID, payload }) => {
58+
const voipPushNotification = getVoipPushNotificationLib();
5559
// you might want to do following things when receiving this event:
5660
// - Start playing ringback if it is an outgoing call
5761
// @ts-expect-error
5862
const call_cid = payload?.call_cid as string | undefined;
59-
if (!call_cid) {
60-
return;
61-
}
6263
logger(
6364
'debug',
64-
`didDisplayIncomingCall event with call_cid: ${call_cid}`
65+
`didDisplayIncomingCall event with callUUID: ${callUUID} call_cid: ${call_cid}`
6566
);
66-
voipCallkeepCallOnForegroundMap$.next({
67-
uuid: callUUID,
68-
cid: call_cid,
69-
});
67+
if (call_cid) {
68+
voipCallkeepCallOnForegroundMap$.next({
69+
uuid: callUUID,
70+
cid: call_cid,
71+
});
72+
}
73+
voipPushNotification.onVoipNotificationCompleted(callUUID);
7074
}
7175
);
7276

packages/react-native-sdk/src/hooks/push/useIosVoipPushEventsSetupEffect.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const logger = getLogger(['useIosVoipPushEventsSetupEffect']);
2828
hence to support login and logout scenario of multiple users we keep of the last count of the listener that was added
2929
This helps in not removing the listeners when a new user logs in and overrides the last listener
3030
*/
31-
let lastListenerCount = 0;
31+
let lastListener = { count: 0 };
3232

3333
function setLogoutCallback(
3434
client: StreamVideoClient,
@@ -166,12 +166,12 @@ export const useIosVoipPushEventsSetupEffect = () => {
166166
}
167167
}
168168
});
169-
lastListenerCount += 1;
170-
const currentListenerCount = lastListenerCount;
169+
lastListener.count += 1;
170+
const currentListenerCount = lastListener.count;
171171

172172
return () => {
173173
const userId = client.streamClient._user?.id;
174-
if (currentListenerCount !== lastListenerCount) {
174+
if (currentListenerCount !== lastListener.count) {
175175
logger(
176176
'debug',
177177
'Skipped removing voip event listeners for user: ' + userId
@@ -266,6 +266,8 @@ const onNotificationReceived = async (notification: any) => {
266266
`callkeep.reportEndCallWithUUID for uuid: ${uuid}, call_cid: ${call_cid}, reason: ${callkeepReason}`
267267
);
268268
callkeep.reportEndCallWithUUID(uuid, callkeepReason);
269+
const voipPushNotification = getVoipPushNotificationLib();
270+
voipPushNotification.onVoipNotificationCompleted(uuid);
269271
return true;
270272
}
271273
return false;
@@ -305,6 +307,4 @@ const onNotificationReceived = async (notification: any) => {
305307
// send the info to this subject, it is listened by callkeep events
306308
// callkeep events will then accept/reject the call
307309
voipPushNotificationCallCId$.next(call_cid);
308-
const voipPushNotification = getVoipPushNotificationLib();
309-
voipPushNotification.onVoipNotificationCompleted(uuid);
310310
};

0 commit comments

Comments
 (0)