@stream-io/video-react-native-sdk 1.31.1 → 1.32.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/android/src/main/AndroidManifest.xml +8 -1
  3. package/android/src/main/AndroidManifestNew.xml +11 -0
  4. package/android/src/main/java/com/streamvideo/reactnative/StreamVideoReactNativeModule.kt +42 -5
  5. package/android/src/main/java/com/streamvideo/reactnative/audio/utils/WebRtcAudioUtils.kt +70 -6
  6. package/android/src/main/java/com/streamvideo/reactnative/callmanager/StreamInCallManagerModule.kt +6 -4
  7. package/android/src/main/java/com/streamvideo/reactnative/keepalive/KeepAliveNotification.kt +83 -0
  8. package/android/src/main/java/com/streamvideo/reactnative/keepalive/StreamCallKeepAliveHeadlessService.kt +149 -0
  9. package/dist/commonjs/hooks/push/index.js +0 -2
  10. package/dist/commonjs/hooks/push/index.js.map +1 -1
  11. package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js +146 -0
  12. package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js.map +1 -0
  13. package/dist/commonjs/hooks/push/useIosVoipPushEventsSetupEffect.js +18 -31
  14. package/dist/commonjs/hooks/push/useIosVoipPushEventsSetupEffect.js.map +1 -1
  15. package/dist/commonjs/hooks/useAndroidKeepCallAliveEffect.js +41 -106
  16. package/dist/commonjs/hooks/useAndroidKeepCallAliveEffect.js.map +1 -1
  17. package/dist/commonjs/index.js +1 -0
  18. package/dist/commonjs/index.js.map +1 -1
  19. package/dist/commonjs/modules/call-manager/CallManager.js +26 -0
  20. package/dist/commonjs/modules/call-manager/CallManager.js.map +1 -1
  21. package/dist/commonjs/providers/StreamCall/index.js +6 -6
  22. package/dist/commonjs/providers/StreamCall/index.js.map +1 -1
  23. package/dist/commonjs/utils/StreamVideoRN/index.js +35 -21
  24. package/dist/commonjs/utils/StreamVideoRN/index.js.map +1 -1
  25. package/dist/commonjs/utils/internal/callingx/audioSessionPromise.js +68 -0
  26. package/dist/commonjs/utils/internal/callingx/audioSessionPromise.js.map +1 -0
  27. package/dist/commonjs/utils/internal/callingx/callingx.js +150 -0
  28. package/dist/commonjs/utils/internal/callingx/callingx.js.map +1 -0
  29. package/dist/commonjs/utils/internal/registerSDKGlobals.js +53 -3
  30. package/dist/commonjs/utils/internal/registerSDKGlobals.js.map +1 -1
  31. package/dist/commonjs/utils/keepCallAliveHeadlessTask.js +48 -0
  32. package/dist/commonjs/utils/keepCallAliveHeadlessTask.js.map +1 -0
  33. package/dist/commonjs/utils/push/android.js +135 -202
  34. package/dist/commonjs/utils/push/android.js.map +1 -1
  35. package/dist/commonjs/utils/push/internal/ios.js +17 -34
  36. package/dist/commonjs/utils/push/internal/ios.js.map +1 -1
  37. package/dist/commonjs/utils/push/internal/rxSubjects.js +1 -45
  38. package/dist/commonjs/utils/push/internal/rxSubjects.js.map +1 -1
  39. package/dist/commonjs/utils/push/internal/utils.js +71 -53
  40. package/dist/commonjs/utils/push/internal/utils.js.map +1 -1
  41. package/dist/commonjs/utils/push/ios.js.map +1 -1
  42. package/dist/commonjs/utils/push/libs/callingx.js +75 -0
  43. package/dist/commonjs/utils/push/libs/callingx.js.map +1 -0
  44. package/dist/commonjs/utils/push/libs/index.js +8 -19
  45. package/dist/commonjs/utils/push/libs/index.js.map +1 -1
  46. package/dist/commonjs/utils/push/libs/notifee/index.js +0 -23
  47. package/dist/commonjs/utils/push/libs/notifee/index.js.map +1 -1
  48. package/dist/commonjs/utils/push/setupCallingExpEvents.js +105 -0
  49. package/dist/commonjs/utils/push/setupCallingExpEvents.js.map +1 -0
  50. package/dist/commonjs/utils/push/setupIosVoipPushEvents.js +7 -6
  51. package/dist/commonjs/utils/push/setupIosVoipPushEvents.js.map +1 -1
  52. package/dist/commonjs/version.js +1 -1
  53. package/dist/module/hooks/push/index.js +0 -2
  54. package/dist/module/hooks/push/index.js.map +1 -1
  55. package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js +139 -0
  56. package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js.map +1 -0
  57. package/dist/module/hooks/push/useIosVoipPushEventsSetupEffect.js +18 -31
  58. package/dist/module/hooks/push/useIosVoipPushEventsSetupEffect.js.map +1 -1
  59. package/dist/module/hooks/useAndroidKeepCallAliveEffect.js +42 -107
  60. package/dist/module/hooks/useAndroidKeepCallAliveEffect.js.map +1 -1
  61. package/dist/module/index.js +1 -0
  62. package/dist/module/index.js.map +1 -1
  63. package/dist/module/modules/call-manager/CallManager.js +26 -0
  64. package/dist/module/modules/call-manager/CallManager.js.map +1 -1
  65. package/dist/module/providers/StreamCall/index.js +6 -6
  66. package/dist/module/providers/StreamCall/index.js.map +1 -1
  67. package/dist/module/utils/StreamVideoRN/index.js +35 -21
  68. package/dist/module/utils/StreamVideoRN/index.js.map +1 -1
  69. package/dist/module/utils/internal/callingx/audioSessionPromise.js +61 -0
  70. package/dist/module/utils/internal/callingx/audioSessionPromise.js.map +1 -0
  71. package/dist/module/utils/internal/callingx/callingx.js +140 -0
  72. package/dist/module/utils/internal/callingx/callingx.js.map +1 -0
  73. package/dist/module/utils/internal/registerSDKGlobals.js +53 -3
  74. package/dist/module/utils/internal/registerSDKGlobals.js.map +1 -1
  75. package/dist/module/utils/keepCallAliveHeadlessTask.js +42 -0
  76. package/dist/module/utils/keepCallAliveHeadlessTask.js.map +1 -0
  77. package/dist/module/utils/push/android.js +137 -204
  78. package/dist/module/utils/push/android.js.map +1 -1
  79. package/dist/module/utils/push/internal/ios.js +17 -34
  80. package/dist/module/utils/push/internal/ios.js.map +1 -1
  81. package/dist/module/utils/push/internal/rxSubjects.js +0 -44
  82. package/dist/module/utils/push/internal/rxSubjects.js.map +1 -1
  83. package/dist/module/utils/push/internal/utils.js +67 -50
  84. package/dist/module/utils/push/internal/utils.js.map +1 -1
  85. package/dist/module/utils/push/ios.js.map +1 -1
  86. package/dist/module/utils/push/libs/callingx.js +67 -0
  87. package/dist/module/utils/push/libs/callingx.js.map +1 -0
  88. package/dist/module/utils/push/libs/index.js +1 -2
  89. package/dist/module/utils/push/libs/index.js.map +1 -1
  90. package/dist/module/utils/push/libs/notifee/index.js +0 -21
  91. package/dist/module/utils/push/libs/notifee/index.js.map +1 -1
  92. package/dist/module/utils/push/setupCallingExpEvents.js +99 -0
  93. package/dist/module/utils/push/setupCallingExpEvents.js.map +1 -0
  94. package/dist/module/utils/push/setupIosVoipPushEvents.js +7 -6
  95. package/dist/module/utils/push/setupIosVoipPushEvents.js.map +1 -1
  96. package/dist/module/version.js +1 -1
  97. package/dist/typescript/hooks/push/index.d.ts.map +1 -1
  98. package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts +5 -0
  99. package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts.map +1 -0
  100. package/dist/typescript/hooks/push/useIosVoipPushEventsSetupEffect.d.ts.map +1 -1
  101. package/dist/typescript/hooks/useAndroidKeepCallAliveEffect.d.ts.map +1 -1
  102. package/dist/typescript/index.d.ts +1 -0
  103. package/dist/typescript/index.d.ts.map +1 -1
  104. package/dist/typescript/modules/call-manager/CallManager.d.ts +5 -0
  105. package/dist/typescript/modules/call-manager/CallManager.d.ts.map +1 -1
  106. package/dist/typescript/utils/StreamVideoRN/index.d.ts +22 -2
  107. package/dist/typescript/utils/StreamVideoRN/index.d.ts.map +1 -1
  108. package/dist/typescript/utils/StreamVideoRN/types.d.ts +59 -25
  109. package/dist/typescript/utils/StreamVideoRN/types.d.ts.map +1 -1
  110. package/dist/typescript/utils/internal/callingx/audioSessionPromise.d.ts +16 -0
  111. package/dist/typescript/utils/internal/callingx/audioSessionPromise.d.ts.map +1 -0
  112. package/dist/typescript/utils/internal/callingx/callingx.d.ts +18 -0
  113. package/dist/typescript/utils/internal/callingx/callingx.d.ts.map +1 -0
  114. package/dist/typescript/utils/internal/registerSDKGlobals.d.ts.map +1 -1
  115. package/dist/typescript/utils/keepCallAliveHeadlessTask.d.ts +10 -0
  116. package/dist/typescript/utils/keepCallAliveHeadlessTask.d.ts.map +1 -0
  117. package/dist/typescript/utils/push/android.d.ts +1 -2
  118. package/dist/typescript/utils/push/android.d.ts.map +1 -1
  119. package/dist/typescript/utils/push/internal/ios.d.ts.map +1 -1
  120. package/dist/typescript/utils/push/internal/rxSubjects.d.ts +0 -33
  121. package/dist/typescript/utils/push/internal/rxSubjects.d.ts.map +1 -1
  122. package/dist/typescript/utils/push/internal/utils.d.ts +14 -8
  123. package/dist/typescript/utils/push/internal/utils.d.ts.map +1 -1
  124. package/dist/typescript/utils/push/ios.d.ts +1 -2
  125. package/dist/typescript/utils/push/ios.d.ts.map +1 -1
  126. package/dist/typescript/utils/push/libs/callingx.d.ts +9 -0
  127. package/dist/typescript/utils/push/libs/callingx.d.ts.map +1 -0
  128. package/dist/typescript/utils/push/libs/index.d.ts +1 -2
  129. package/dist/typescript/utils/push/libs/index.d.ts.map +1 -1
  130. package/dist/typescript/utils/push/libs/notifee/index.d.ts +0 -2
  131. package/dist/typescript/utils/push/libs/notifee/index.d.ts.map +1 -1
  132. package/dist/typescript/utils/push/setupCallingExpEvents.d.ts +8 -0
  133. package/dist/typescript/utils/push/setupCallingExpEvents.d.ts.map +1 -0
  134. package/dist/typescript/utils/push/setupIosVoipPushEvents.d.ts.map +1 -1
  135. package/dist/typescript/version.d.ts +1 -1
  136. package/expo-config-plugin/dist/withAndroidManifest.js +1 -33
  137. package/expo-config-plugin/dist/withAndroidPermissions.js +2 -7
  138. package/expo-config-plugin/dist/withAppDelegate.js +19 -197
  139. package/expo-config-plugin/dist/withMainActivity.js +1 -1
  140. package/expo-config-plugin/dist/withiOSInfoPlist.js +2 -3
  141. package/ios/StreamInCallManager.m +2 -0
  142. package/ios/StreamInCallManager.swift +19 -7
  143. package/ios/StreamVideoReactNative-Bridging-Header.h +3 -1
  144. package/ios/StreamVideoReactNative.h +7 -4
  145. package/ios/StreamVideoReactNative.m +199 -84
  146. package/package.json +11 -16
  147. package/src/hooks/push/index.ts +0 -2
  148. package/src/hooks/push/useCallingExpWithCallingStateEffect.ts +193 -0
  149. package/src/hooks/push/useIosVoipPushEventsSetupEffect.ts +21 -34
  150. package/src/hooks/useAndroidKeepCallAliveEffect.ts +63 -129
  151. package/src/index.ts +1 -0
  152. package/src/modules/call-manager/CallManager.ts +36 -0
  153. package/src/modules/call-manager/native-module.d.ts +7 -0
  154. package/src/providers/StreamCall/index.tsx +6 -6
  155. package/src/utils/StreamVideoRN/index.ts +42 -30
  156. package/src/utils/StreamVideoRN/types.ts +61 -25
  157. package/src/utils/internal/callingx/audioSessionPromise.ts +65 -0
  158. package/src/utils/internal/callingx/callingx.ts +197 -0
  159. package/src/utils/internal/registerSDKGlobals.ts +52 -4
  160. package/src/utils/keepCallAliveHeadlessTask.ts +54 -0
  161. package/src/utils/push/android.ts +198 -311
  162. package/src/utils/push/internal/ios.ts +28 -44
  163. package/src/utils/push/internal/rxSubjects.ts +0 -61
  164. package/src/utils/push/internal/utils.ts +108 -64
  165. package/src/utils/push/ios.ts +1 -6
  166. package/src/utils/push/libs/callingx.ts +89 -0
  167. package/src/utils/push/libs/index.ts +1 -2
  168. package/src/utils/push/libs/notifee/index.ts +0 -31
  169. package/src/utils/push/setupCallingExpEvents.ts +135 -0
  170. package/src/utils/push/setupIosVoipPushEvents.ts +11 -7
  171. package/src/version.ts +1 -1
  172. package/android/src/main/java/com/streamvideo/reactnative/util/CallAliveServiceChecker.kt +0 -95
  173. package/dist/commonjs/hooks/push/useIosCallkeepWithCallingStateEffect.js +0 -160
  174. package/dist/commonjs/hooks/push/useIosCallkeepWithCallingStateEffect.js.map +0 -1
  175. package/dist/commonjs/hooks/push/useProcessPushCallEffect.js +0 -67
  176. package/dist/commonjs/hooks/push/useProcessPushCallEffect.js.map +0 -1
  177. package/dist/commonjs/utils/push/libs/callkeep.js +0 -17
  178. package/dist/commonjs/utils/push/libs/callkeep.js.map +0 -1
  179. package/dist/commonjs/utils/push/libs/voipPushNotification.js +0 -17
  180. package/dist/commonjs/utils/push/libs/voipPushNotification.js.map +0 -1
  181. package/dist/commonjs/utils/push/setupIosCallKeepEvents.js +0 -205
  182. package/dist/commonjs/utils/push/setupIosCallKeepEvents.js.map +0 -1
  183. package/dist/module/hooks/push/useIosCallkeepWithCallingStateEffect.js +0 -153
  184. package/dist/module/hooks/push/useIosCallkeepWithCallingStateEffect.js.map +0 -1
  185. package/dist/module/hooks/push/useProcessPushCallEffect.js +0 -60
  186. package/dist/module/hooks/push/useProcessPushCallEffect.js.map +0 -1
  187. package/dist/module/utils/push/libs/callkeep.js +0 -11
  188. package/dist/module/utils/push/libs/callkeep.js.map +0 -1
  189. package/dist/module/utils/push/libs/voipPushNotification.js +0 -11
  190. package/dist/module/utils/push/libs/voipPushNotification.js.map +0 -1
  191. package/dist/module/utils/push/setupIosCallKeepEvents.js +0 -199
  192. package/dist/module/utils/push/setupIosCallKeepEvents.js.map +0 -1
  193. package/dist/typescript/hooks/push/useIosCallkeepWithCallingStateEffect.d.ts +0 -5
  194. package/dist/typescript/hooks/push/useIosCallkeepWithCallingStateEffect.d.ts.map +0 -1
  195. package/dist/typescript/hooks/push/useProcessPushCallEffect.d.ts +0 -8
  196. package/dist/typescript/hooks/push/useProcessPushCallEffect.d.ts.map +0 -1
  197. package/dist/typescript/utils/push/libs/callkeep.d.ts +0 -3
  198. package/dist/typescript/utils/push/libs/callkeep.d.ts.map +0 -1
  199. package/dist/typescript/utils/push/libs/voipPushNotification.d.ts +0 -3
  200. package/dist/typescript/utils/push/libs/voipPushNotification.d.ts.map +0 -1
  201. package/dist/typescript/utils/push/setupIosCallKeepEvents.d.ts +0 -6
  202. package/dist/typescript/utils/push/setupIosCallKeepEvents.d.ts.map +0 -1
  203. package/src/hooks/push/useIosCallkeepWithCallingStateEffect.ts +0 -235
  204. package/src/hooks/push/useProcessPushCallEffect.ts +0 -108
  205. package/src/utils/push/libs/callkeep.ts +0 -16
  206. package/src/utils/push/libs/voipPushNotification.ts +0 -17
  207. package/src/utils/push/setupIosCallKeepEvents.ts +0 -252
@@ -1,10 +1,9 @@
1
- import { AppState, NativeModules, Platform } from 'react-native';
2
- import { getCallKeepLib, getVoipPushNotificationLib } from '../libs';
3
- import { voipPushNotificationCallCId$ } from './rxSubjects';
1
+ import { Platform } from 'react-native';
4
2
  import { pushUnsubscriptionCallbacks } from './constants';
5
- import { canAddPushWSSubscriptionsRef, shouldCallBeEnded } from './utils';
3
+ import { canListenToWS, shouldCallBeClosed } from './utils';
6
4
  import { StreamVideoConfig } from '../../StreamVideoRN/types';
7
5
  import { videoLoggerSystem } from '@stream-io/video-client';
6
+ import { getCallingxLib } from '../libs/callingx';
8
7
 
9
8
  export const onVoipNotificationReceived = async (
10
9
  notification: any,
@@ -32,71 +31,57 @@ export const onVoipNotificationReceived = async (
32
31
  "version": "v2"
33
32
  }
34
33
  } */
34
+ const logger = videoLoggerSystem.getLogger(
35
+ 'callingx - onVoipNotificationReceived',
36
+ );
37
+
35
38
  const sender = notification?.stream?.sender;
36
39
  const type = notification?.stream?.type;
37
40
  // do not process any other notifications other than stream.video or ringing
38
41
  if (sender !== 'stream.video' && type !== 'call.ring') {
39
42
  return;
40
43
  }
44
+
41
45
  const call_cid = notification?.stream?.call_cid;
42
46
  if (!call_cid || Platform.OS !== 'ios' || !pushConfig.ios.pushProviderName) {
43
47
  return;
44
48
  }
45
- const logger = videoLoggerSystem.getLogger('setupIosVoipPushEvents');
46
- const client = await pushConfig.createStreamVideoClient();
47
49
 
48
- if (!client) {
50
+ const callingx = getCallingxLib();
51
+ if (callingx.isCallTracked(call_cid)) {
52
+ //same call_cid is already tracked, so we skip the notification
49
53
  logger.debug(
50
- 'client not found, not processing call.ring voip push notification',
54
+ `the same call_cid ${call_cid} is already tracked, skipping the call.ring notification`,
51
55
  );
52
56
  return;
53
57
  }
54
- const shouldRejectCallWhenBusy = client['rejectCallWhenBusy'] ?? false;
55
- if (shouldRejectCallWhenBusy) {
56
- // inform the iOS native module that we should reject call when busy
57
- NativeModules.StreamVideoReactNative.setShouldRejectCallWhenBusy(
58
- shouldRejectCallWhenBusy,
59
- );
60
- }
61
- const callFromPush = await client.onRingingCall(call_cid);
62
- let uuid = '';
63
- try {
64
- uuid =
65
- await NativeModules?.StreamVideoReactNative?.getIncomingCallUUid(
66
- call_cid,
67
- );
68
- } catch (error) {
69
- logger.error('Error in getting call uuid from native module', error);
70
- }
71
- if (!uuid) {
72
- logger.error(
73
- `Not processing call.ring push notification, as no uuid found for call_cid: ${call_cid}`,
58
+
59
+ const client = await pushConfig.createStreamVideoClient();
60
+ if (!client) {
61
+ logger.debug(
62
+ 'client not found, not processing call.ring voip push notification',
74
63
  );
75
64
  return;
76
65
  }
77
- const created_by_id = notification?.stream?.created_by_id;
78
- const receiver_id = notification?.stream?.receiver_id;
66
+
67
+ const callFromPush = await client.onRingingCall(call_cid);
68
+
79
69
  function closeCallIfNecessary() {
80
- const { mustEndCall, callkeepReason } = shouldCallBeEnded(
70
+ const { mustEndCall, endCallReason } = shouldCallBeClosed(
81
71
  callFromPush,
82
- created_by_id,
83
- receiver_id,
72
+ notification?.stream,
84
73
  );
85
74
  if (mustEndCall) {
86
- const callkeep = getCallKeepLib();
87
75
  logger.debug(
88
- `callkeep.reportEndCallWithUUID for uuid: ${uuid}, call_cid: ${call_cid}, reason: ${callkeepReason}`,
76
+ `callingx.endCallWithReason for call_cid: ${call_cid} endCallReason: ${endCallReason}`,
89
77
  );
90
- callkeep.reportEndCallWithUUID(uuid, callkeepReason);
91
- const voipPushNotification = getVoipPushNotificationLib();
92
- voipPushNotification.onVoipNotificationCompleted(uuid);
78
+ callingx.endCallWithReason(call_cid, endCallReason);
93
79
  return true;
94
80
  }
95
81
  return false;
96
82
  }
83
+
97
84
  const closed = closeCallIfNecessary();
98
- const canListenToWS = () =>
99
- canAddPushWSSubscriptionsRef.current && AppState.currentState !== 'active';
100
85
  if (!closed && canListenToWS()) {
101
86
  const unsubscribe = callFromPush.on('all', (event) => {
102
87
  const _canListenToWS = canListenToWS();
@@ -121,10 +106,9 @@ export const onVoipNotificationReceived = async (
121
106
  pushUnsubscriptionCallbacks.get(call_cid)?.forEach((cb) => cb());
122
107
  pushUnsubscriptionCallbacks.set(call_cid, [unsubscribe]);
123
108
  }
124
- // send the info to this subject, it is listened by callkeep events
125
- // callkeep events will then accept/reject the call
109
+
110
+ // callingx event listeners (setupCallingExpEvents) will handle accept/reject
126
111
  logger.debug(
127
- `call_cid:${call_cid} uuid:${uuid} received and processed from call.ring push notification`,
112
+ `call_cid:${call_cid} received and processed from call.ring push notification`,
128
113
  );
129
- voipPushNotificationCallCId$.next(call_cid);
130
114
  };
@@ -8,64 +8,3 @@ import type { NonRingingPushEvent } from '../../StreamVideoRN/types';
8
8
  export const pushNonRingingCallData$ = new BehaviorSubject<
9
9
  { cid: string; type: NonRingingPushEvent } | undefined
10
10
  >(undefined);
11
-
12
- /**
13
- * This rxjs subject is used to store the call cid of the accepted incoming call from push notification
14
- * Note: it is should be subscribed only when a user has connected to the websocket of Stream
15
- */
16
- export const pushAcceptedIncomingCallCId$ = new BehaviorSubject<
17
- string | undefined
18
- >(undefined);
19
-
20
- /**
21
- * This rxjs subject is used to store the call cid of the tapped incoming call from push notification it is neither accepted nor rejected yet
22
- * Note: it should be subscribed only when a user has connected to the websocket of Stream
23
- */
24
- export const pushTappedIncomingCallCId$ = new BehaviorSubject<
25
- string | undefined
26
- >(undefined);
27
-
28
- /**
29
- * This rxjs subject is used to store the call cid of the delivered incoming call from push notification it is neither accepted nor rejected yet
30
- * Used so that the call is navigated to when app is open from being killed
31
- * Note: it should be subscribed only when a user has connected to the websocket of Stream
32
- */
33
- export const pushAndroidBackgroundDeliveredIncomingCallCId$ =
34
- new BehaviorSubject<string | undefined>(undefined);
35
-
36
- /**
37
- * This rxjs subject is used to store the call cid of the accepted incoming call from push notification
38
- * Note: it should be subscribed only when a user has connected to the websocket of Stream
39
- */
40
- export const pushRejectedIncomingCallCId$ = new BehaviorSubject<
41
- string | undefined
42
- >(undefined);
43
-
44
- /**
45
- * This rxjs subject is used to store the call cid of the incoming call from ios voip pushkit notification
46
- */
47
- export const voipPushNotificationCallCId$ = new BehaviorSubject<
48
- string | undefined
49
- >(undefined);
50
-
51
- /** The pair of cid of a call and its corresponding uuid created in the native side */
52
- type CallkeepMap = {
53
- uuid: string;
54
- cid: string;
55
- };
56
-
57
- /*
58
- * This rxjs subject should only used to store the CallkeepMap
59
- * for the incoming call when on foreground
60
- * or in other words, when we get didDisplayIncomingCall from callkeep lib
61
- */
62
- export const voipCallkeepCallOnForegroundMap$ = new BehaviorSubject<
63
- CallkeepMap | undefined
64
- >(undefined);
65
-
66
- /*
67
- * This rxjs subject should only used to store the CallkeepMap when it was accepted in the native dialer
68
- */
69
- export const voipCallkeepAcceptedCallOnNativeDialerMap$ = new BehaviorSubject<
70
- CallkeepMap | undefined
71
- >(undefined);
@@ -10,9 +10,12 @@ import type {
10
10
  } from '../../StreamVideoRN/types';
11
11
  import { onNewCallNotification } from '../../internal/newNotificationCallbacks';
12
12
  import { pushUnsubscriptionCallbacks } from './constants';
13
+ import { AppState } from 'react-native';
14
+ import type { EndCallReason } from '@stream-io/react-native-callingx';
13
15
 
14
16
  type PushConfig = NonNullable<StreamVideoConfig['push']>;
15
17
 
18
+ const logger = videoLoggerSystem.getLogger('callingx');
16
19
  type CanAddPushWSSubscriptionsRef = { current: boolean };
17
20
 
18
21
  /**
@@ -24,44 +27,40 @@ export const shouldCallBeEnded = (
24
27
  created_by_id: string | undefined,
25
28
  receiver_id: string | undefined,
26
29
  ) => {
27
- /* callkeep reasons for ending a call
28
- FAILED: 1,
29
- REMOTE_ENDED: 2,
30
- UNANSWERED: 3,
31
- ANSWERED_ELSEWHERE: 4,
32
- DECLINED_ELSEWHERE: 5,
33
- MISSED: 6
34
- */
35
30
  const callSession = callFromPush.state.session;
36
31
  const rejected_by = callSession?.rejected_by;
37
32
  const accepted_by = callSession?.accepted_by;
38
33
  let mustEndCall = false;
39
- let callkeepReason = 0;
40
- if (created_by_id && rejected_by) {
34
+ let endCallReason: EndCallReason = 'unknown';
35
+
36
+ if (callFromPush.state.endedAt) {
37
+ mustEndCall = true;
38
+ endCallReason = 'remote';
39
+ } else if (created_by_id && rejected_by) {
41
40
  if (rejected_by[created_by_id]) {
42
- // call was cancelled by the caller
41
+ // call was cancelled by the caller before the receiver could answer
43
42
  mustEndCall = true;
44
- callkeepReason = 2;
43
+ endCallReason = 'canceled';
45
44
  }
46
45
  } else if (receiver_id && rejected_by) {
47
46
  if (rejected_by[receiver_id]) {
48
47
  // call was rejected by the receiver in some other device
49
48
  mustEndCall = true;
50
- callkeepReason = 5;
49
+ endCallReason = 'rejected';
51
50
  }
52
51
  } else if (receiver_id && accepted_by) {
53
52
  if (accepted_by[receiver_id]) {
54
53
  // call was accepted by the receiver in some other device
55
54
  mustEndCall = true;
56
- callkeepReason = 4;
55
+ endCallReason = 'answeredElsewhere';
57
56
  }
58
57
  }
59
58
  videoLoggerSystem
60
59
  .getLogger('shouldCallBeEnded')
61
60
  .debug(
62
- `callCid: ${callFromPush.cid} mustEndCall: ${mustEndCall} callkeepReason: ${callkeepReason}`,
61
+ `callCid: ${callFromPush.cid} mustEndCall: ${mustEndCall} endCallReason: ${endCallReason}`,
63
62
  );
64
- return { mustEndCall, callkeepReason };
63
+ return { mustEndCall, endCallReason };
65
64
  };
66
65
 
67
66
  /* An action for the notification or callkeep and app does not have JS context setup yet, so we need to do two steps:
@@ -71,71 +70,95 @@ export const shouldCallBeEnded = (
71
70
  export const processCallFromPushInBackground = async (
72
71
  pushConfig: PushConfig,
73
72
  call_cid: string,
74
- action: Parameters<typeof processCallFromPush>[2],
73
+ action: 'accept' | 'decline' | 'pressed' | 'backgroundDelivered',
74
+ /**
75
+ * Callback to inform iOS CallKit that the action can be fulfilled
76
+ * Needed for iOS CallKit fullfillment of action
77
+ * as per ios docs "Instead, wait until you establish a connection and then fulfill the object."
78
+ * This means we wait until call.get() is done and call.join() or call.leave() is invoked (not completed) to fulfill the action
79
+ */
80
+ onIOSActionCanBeFulfilled: (didFail: boolean) => void,
75
81
  ) => {
76
82
  let videoClient: StreamVideoClient | undefined;
77
83
 
78
84
  try {
79
85
  videoClient = await pushConfig.createStreamVideoClient();
80
86
  if (!videoClient) {
81
- return;
87
+ throw new Error('createStreamVideoClient returned null');
82
88
  }
83
89
  } catch (e) {
84
- const logger = videoLoggerSystem.getLogger(
85
- 'processCallFromPushInBackground',
90
+ logger.error(
91
+ 'processCallFromPushInBackground: failed to create video client',
92
+ e,
86
93
  );
87
- logger.error('failed to create video client', e);
94
+ onIOSActionCanBeFulfilled(true);
88
95
  return;
89
96
  }
90
- await processCallFromPush(videoClient, call_cid, action, pushConfig);
91
- };
92
97
 
93
- /**
94
- * This function is used process the call from push notifications due to incoming call
95
- * It does the following steps:
96
- * 1. Get the call from the client if present or create a new call
97
- * 2. Fetch the latest state of the call from the server if its not already in ringing state
98
- * 3. Join or leave the call based on the user's action.
99
- */
100
- export const processCallFromPush = async (
101
- client: StreamVideoClient,
102
- call_cid: string,
103
- action: 'accept' | 'decline' | 'pressed' | 'backgroundDelivered',
104
- pushConfig: PushConfig,
105
- ) => {
106
98
  let callFromPush: Call;
107
99
  try {
108
- callFromPush = await client.onRingingCall(call_cid);
100
+ callFromPush = await videoClient.onRingingCall(call_cid);
109
101
  } catch (e) {
110
- const logger = videoLoggerSystem.getLogger('processCallFromPush');
111
- logger.error('failed to fetch call from push notification', e);
102
+ logger.error(
103
+ 'processCallFromPushInBackground: failed to fetch call from push notification',
104
+ e,
105
+ );
106
+ onIOSActionCanBeFulfilled(true);
112
107
  return;
113
108
  }
114
- // note: when action was pressed or delivered, we dont need to do anything as the only thing is to do is to get the call which adds it to the client
115
- try {
116
- if (action === 'accept') {
117
- if (pushConfig.publishOptions) {
118
- callFromPush.updatePublishOptions(pushConfig.publishOptions);
119
- }
120
- videoLoggerSystem
121
- .getLogger('processCallFromPush')
122
- .debug(
123
- `joining call from push notification with callCid: ${callFromPush.cid}`,
124
- );
109
+ if (action === 'accept') {
110
+ if (pushConfig.publishOptions) {
111
+ callFromPush.updatePublishOptions(pushConfig.publishOptions);
112
+ }
113
+ logger.debug(
114
+ `joining call from push notification with callCid: ${callFromPush.cid}`,
115
+ );
116
+ const callingState = callFromPush.state.callingState;
117
+ if (
118
+ callingState !== CallingState.RINGING &&
119
+ callingState !== CallingState.IDLE
120
+ ) {
121
+ logger.debug(
122
+ `skipping join call as it is not in ringing or idle state from push notification. callCid: ${callFromPush.cid}`,
123
+ );
124
+ onIOSActionCanBeFulfilled(true);
125
+ return;
126
+ }
127
+ try {
128
+ onIOSActionCanBeFulfilled(false);
125
129
  await callFromPush.join();
126
- } else if (action === 'decline') {
127
- const canReject =
128
- callFromPush.state.callingState === CallingState.RINGING;
129
- videoLoggerSystem
130
- .getLogger('processCallFromPush')
131
- .debug(
132
- `declining call from push notification with callCid: ${callFromPush.cid} reject: ${canReject}`,
133
- );
134
- await callFromPush.leave({ reject: canReject, reason: 'decline' });
130
+ } catch (e) {
131
+ logger.warn(
132
+ 'processCallFromPushInBackground: failed to join call from push notification',
133
+ e,
134
+ );
135
+ }
136
+ } else if (action === 'decline') {
137
+ const alreadyLeft = callFromPush.state.callingState === CallingState.LEFT;
138
+ if (alreadyLeft) {
139
+ onIOSActionCanBeFulfilled(false);
140
+ return;
141
+ }
142
+ const canReject =
143
+ callFromPush.state.callingState === CallingState.RINGING ||
144
+ callFromPush.state.callingState === CallingState.IDLE;
145
+ const isCurrentUserMember = callFromPush.state.members.some(
146
+ (member) => member.user_id === callFromPush.currentUserId,
147
+ );
148
+ const reject = canReject && isCurrentUserMember;
149
+ logger.debug(
150
+ `declining call from push notification with callCid: ${callFromPush.cid} reject: ${reject}`,
151
+ );
152
+ try {
153
+ await callFromPush.leave({ reject, reason: 'decline' });
154
+ onIOSActionCanBeFulfilled(false);
155
+ } catch (e) {
156
+ logger.warn(
157
+ 'processCallFromPushInBackground: failed to decline call from push notification',
158
+ e,
159
+ );
160
+ onIOSActionCanBeFulfilled(true);
135
161
  }
136
- } catch (e) {
137
- const logger = videoLoggerSystem.getLogger('processCallFromPush');
138
- logger.warn(`failed to process ${action} call from push notification`, e);
139
162
  }
140
163
  };
141
164
 
@@ -163,10 +186,13 @@ export const processNonIncomingCallFromPush = async (
163
186
  await callFromPush.get();
164
187
  }
165
188
  } catch (e) {
166
- const logger = videoLoggerSystem.getLogger(
189
+ const nonRingingCallLogger = videoLoggerSystem.getLogger(
167
190
  'processNonIncomingCallFromPush',
168
191
  );
169
- logger.error('failed to fetch call from push notification', e);
192
+ nonRingingCallLogger.error(
193
+ 'failed to fetch call from push notification',
194
+ e,
195
+ );
170
196
  return;
171
197
  }
172
198
  onNewCallNotification(callFromPush, nonRingingNotificationType);
@@ -191,3 +217,21 @@ export const clearPushWSEventSubscriptions = (call_cid: string) => {
191
217
  export const canAddPushWSSubscriptionsRef: CanAddPushWSSubscriptionsRef = {
192
218
  current: true,
193
219
  };
220
+
221
+ export const canListenToWS = () =>
222
+ canAddPushWSSubscriptionsRef.current && AppState.currentState !== 'active';
223
+
224
+ export const shouldCallBeClosed = (
225
+ call: Call,
226
+ pushData: { [key: string]: string | object },
227
+ ) => {
228
+ const created_by_id = pushData?.created_by_id as string;
229
+ const receiver_id = pushData?.receiver_id as string;
230
+
231
+ const { mustEndCall, endCallReason } = shouldCallBeEnded(
232
+ call,
233
+ created_by_id,
234
+ receiver_id,
235
+ );
236
+ return { mustEndCall, endCallReason };
237
+ };
@@ -62,12 +62,7 @@ export const oniOSExpoNotificationEvent = (event: ExpoNotification) => {
62
62
  }
63
63
  };
64
64
 
65
- export const oniOSNotifeeEvent = ({
66
- event,
67
- }: {
68
- event: Event;
69
- isBackground: boolean;
70
- }) => {
65
+ export const oniOSNotifeeEvent = ({ event }: { event: Event }) => {
71
66
  if (Platform.OS !== 'ios') return;
72
67
  const pushConfig = StreamVideoRN.getConfig().push;
73
68
  const { type, detail } = event;
@@ -0,0 +1,89 @@
1
+ import { StreamVideoConfig } from '../../StreamVideoRN/types';
2
+
3
+ export type RNCallingxType =
4
+ import('@stream-io/react-native-callingx').ICallingxModule;
5
+ export type EventData = import('@stream-io/react-native-callingx').EventData;
6
+ export type EventParams =
7
+ import('@stream-io/react-native-callingx').EventParams;
8
+ export type CallingExpOptions =
9
+ import('@stream-io/react-native-callingx').CallingExpOptions;
10
+
11
+ let callingx: RNCallingxType | undefined;
12
+
13
+ try {
14
+ callingx = require('@stream-io/react-native-callingx').CallingxModule;
15
+ } catch {}
16
+
17
+ export function getCallingxLib() {
18
+ if (!callingx) {
19
+ throw Error('react-native-callingx library is not installed.');
20
+ }
21
+ return callingx;
22
+ }
23
+
24
+ export function getCallingxLibIfAvailable() {
25
+ return callingx ?? undefined;
26
+ }
27
+
28
+ export function extractCallingExpOptions(
29
+ config: StreamVideoConfig,
30
+ ): CallingExpOptions {
31
+ const { push: pushConfig, foregroundService: foregroundServiceConfig } =
32
+ config;
33
+ const callingExpOptions: CallingExpOptions = {};
34
+
35
+ if (pushConfig?.ios) {
36
+ const iosOptions: CallingExpOptions['ios'] = {};
37
+ if (pushConfig.ios.supportsVideo !== undefined) {
38
+ iosOptions.supportsVideo = pushConfig.ios.supportsVideo;
39
+ }
40
+ if (pushConfig.ios.sound !== undefined) {
41
+ iosOptions.sound = pushConfig.ios.sound;
42
+ }
43
+ if (pushConfig.ios.imageName !== undefined) {
44
+ iosOptions.imageName = pushConfig.ios.imageName;
45
+ }
46
+ if (pushConfig.ios.callsHistory !== undefined) {
47
+ iosOptions.callsHistory = pushConfig.ios.callsHistory;
48
+ }
49
+ if (pushConfig.ios.displayCallTimeout !== undefined) {
50
+ iosOptions.displayCallTimeout = pushConfig.ios.displayCallTimeout;
51
+ }
52
+
53
+ if (Object.keys(iosOptions).length > 0) {
54
+ callingExpOptions.ios = iosOptions;
55
+ }
56
+ }
57
+
58
+ const androidOptions: CallingExpOptions['android'] = {};
59
+ if (pushConfig?.android) {
60
+ if (pushConfig.android.incomingChannel) {
61
+ androidOptions.incomingChannel = pushConfig.android.incomingChannel;
62
+ }
63
+ if (pushConfig.android.titleTransformer) {
64
+ androidOptions.titleTransformer = pushConfig.android.titleTransformer;
65
+ }
66
+ if (pushConfig.android.notificationTexts) {
67
+ androidOptions.notificationTexts = pushConfig.android.notificationTexts;
68
+ }
69
+ }
70
+
71
+ if (foregroundServiceConfig.android.channel) {
72
+ androidOptions.ongoingChannel = foregroundServiceConfig.android.channel;
73
+ }
74
+
75
+ if (Object.keys(androidOptions).length > 0) {
76
+ callingExpOptions.android = androidOptions;
77
+ }
78
+
79
+ if (pushConfig?.shouldRejectCallWhenBusy !== undefined) {
80
+ callingExpOptions.shouldRejectCallWhenBusy =
81
+ pushConfig.shouldRejectCallWhenBusy;
82
+ }
83
+
84
+ if (pushConfig?.enableOngoingCalls !== undefined) {
85
+ callingExpOptions.enableOngoingCalls = pushConfig?.enableOngoingCalls;
86
+ }
87
+
88
+ return callingExpOptions;
89
+ }
@@ -1,9 +1,8 @@
1
1
  export * from './expoNotifications';
2
2
  export * from './firebaseMessaging';
3
3
  export * from './iosPushNotification';
4
- export * from './voipPushNotification';
5
- export * from './callkeep';
6
4
  export * from './notifee';
5
+ export * from './callingx';
7
6
 
8
7
  /*
9
8
  NOTE: must keep each libs in different files
@@ -1,6 +1,4 @@
1
- import { PermissionsAndroid } from 'react-native';
2
1
  import { lib, type Type } from './lib';
3
- import { videoLoggerSystem } from '@stream-io/video-client';
4
2
 
5
3
  export type NotifeeLib = Type;
6
4
 
@@ -35,35 +33,6 @@ export function getNotifeeLibThrowIfNotInstalledForPush() {
35
33
  return lib;
36
34
  }
37
35
 
38
- export function getNotifeeLibNoThrowForKeepCallAlive() {
39
- if (!lib) {
40
- const logger = videoLoggerSystem.getLogger('getNotifeeLibNoThrow');
41
- logger.info(
42
- `${'@notifee/react-native library not installed. It is required to keep call alive in the background for Android. '}${INSTALLATION_INSTRUCTION}`,
43
- );
44
- }
45
- return lib;
46
- }
47
-
48
- export async function getKeepCallAliveForegroundServiceTypes() {
49
- const types: AndroidForegroundServiceType[] = [
50
- AndroidForegroundServiceType.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK,
51
- ];
52
- const hasCameraPermission = await PermissionsAndroid.check(
53
- PermissionsAndroid.PERMISSIONS.CAMERA!,
54
- );
55
- if (hasCameraPermission) {
56
- types.push(AndroidForegroundServiceType.FOREGROUND_SERVICE_TYPE_CAMERA);
57
- }
58
- const hasMicrophonePermission = await PermissionsAndroid.check(
59
- PermissionsAndroid.PERMISSIONS.RECORD_AUDIO!,
60
- );
61
- if (hasMicrophonePermission) {
62
- types.push(AndroidForegroundServiceType.FOREGROUND_SERVICE_TYPE_MICROPHONE);
63
- }
64
- return types;
65
- }
66
-
67
36
  export function getIncomingCallForegroundServiceTypes() {
68
37
  const types: AndroidForegroundServiceType[] = [
69
38
  AndroidForegroundServiceType.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE,