@stream-io/video-react-native-sdk 1.30.5 → 1.31.1-beta.0

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 (248) hide show
  1. package/CHANGELOG.md +11 -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 +127 -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/android/src/main/java/com/streamvideo/reactnative/screenshare/ScreenAudioCapture.kt +111 -0
  10. package/dist/commonjs/components/Call/CallControls/ScreenShareToggleButton.js +3 -2
  11. package/dist/commonjs/components/Call/CallControls/ScreenShareToggleButton.js.map +1 -1
  12. package/dist/commonjs/hooks/index.js +11 -0
  13. package/dist/commonjs/hooks/index.js.map +1 -1
  14. package/dist/commonjs/hooks/push/index.js +0 -2
  15. package/dist/commonjs/hooks/push/index.js.map +1 -1
  16. package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js +144 -0
  17. package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js.map +1 -0
  18. package/dist/commonjs/hooks/push/useIosVoipPushEventsSetupEffect.js +18 -31
  19. package/dist/commonjs/hooks/push/useIosVoipPushEventsSetupEffect.js.map +1 -1
  20. package/dist/commonjs/hooks/useAndroidKeepCallAliveEffect.js +64 -97
  21. package/dist/commonjs/hooks/useAndroidKeepCallAliveEffect.js.map +1 -1
  22. package/dist/commonjs/hooks/useScreenShareAudioMixing.js +126 -0
  23. package/dist/commonjs/hooks/useScreenShareAudioMixing.js.map +1 -0
  24. package/dist/commonjs/hooks/useScreenShareButton.js +57 -3
  25. package/dist/commonjs/hooks/useScreenShareButton.js.map +1 -1
  26. package/dist/commonjs/index.js +1 -0
  27. package/dist/commonjs/index.js.map +1 -1
  28. package/dist/commonjs/modules/ScreenShareAudioManager.js +54 -0
  29. package/dist/commonjs/modules/ScreenShareAudioManager.js.map +1 -0
  30. package/dist/commonjs/modules/call-manager/CallManager.js +26 -0
  31. package/dist/commonjs/modules/call-manager/CallManager.js.map +1 -1
  32. package/dist/commonjs/providers/StreamCall/index.js +16 -6
  33. package/dist/commonjs/providers/StreamCall/index.js.map +1 -1
  34. package/dist/commonjs/utils/StreamVideoRN/index.js +35 -21
  35. package/dist/commonjs/utils/StreamVideoRN/index.js.map +1 -1
  36. package/dist/commonjs/utils/internal/callingx/audioSessionPromise.js +68 -0
  37. package/dist/commonjs/utils/internal/callingx/audioSessionPromise.js.map +1 -0
  38. package/dist/commonjs/utils/internal/callingx/callingx.js +150 -0
  39. package/dist/commonjs/utils/internal/callingx/callingx.js.map +1 -0
  40. package/dist/commonjs/utils/internal/registerSDKGlobals.js +53 -3
  41. package/dist/commonjs/utils/internal/registerSDKGlobals.js.map +1 -1
  42. package/dist/commonjs/utils/keepCallAliveHeadlessTask.js +48 -0
  43. package/dist/commonjs/utils/keepCallAliveHeadlessTask.js.map +1 -0
  44. package/dist/commonjs/utils/push/android.js +135 -202
  45. package/dist/commonjs/utils/push/android.js.map +1 -1
  46. package/dist/commonjs/utils/push/internal/ios.js +17 -34
  47. package/dist/commonjs/utils/push/internal/ios.js.map +1 -1
  48. package/dist/commonjs/utils/push/internal/rxSubjects.js +1 -45
  49. package/dist/commonjs/utils/push/internal/rxSubjects.js.map +1 -1
  50. package/dist/commonjs/utils/push/internal/utils.js +71 -53
  51. package/dist/commonjs/utils/push/internal/utils.js.map +1 -1
  52. package/dist/commonjs/utils/push/ios.js.map +1 -1
  53. package/dist/commonjs/utils/push/libs/callingx.js +75 -0
  54. package/dist/commonjs/utils/push/libs/callingx.js.map +1 -0
  55. package/dist/commonjs/utils/push/libs/index.js +8 -19
  56. package/dist/commonjs/utils/push/libs/index.js.map +1 -1
  57. package/dist/commonjs/utils/push/libs/notifee/index.js +0 -19
  58. package/dist/commonjs/utils/push/libs/notifee/index.js.map +1 -1
  59. package/dist/commonjs/utils/push/setupCallingExpEvents.js +105 -0
  60. package/dist/commonjs/utils/push/setupCallingExpEvents.js.map +1 -0
  61. package/dist/commonjs/utils/push/setupIosVoipPushEvents.js +7 -6
  62. package/dist/commonjs/utils/push/setupIosVoipPushEvents.js.map +1 -1
  63. package/dist/commonjs/version.js +1 -1
  64. package/dist/commonjs/version.js.map +1 -1
  65. package/dist/module/components/Call/CallControls/ScreenShareToggleButton.js +3 -2
  66. package/dist/module/components/Call/CallControls/ScreenShareToggleButton.js.map +1 -1
  67. package/dist/module/hooks/index.js +1 -0
  68. package/dist/module/hooks/index.js.map +1 -1
  69. package/dist/module/hooks/push/index.js +0 -2
  70. package/dist/module/hooks/push/index.js.map +1 -1
  71. package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js +137 -0
  72. package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js.map +1 -0
  73. package/dist/module/hooks/push/useIosVoipPushEventsSetupEffect.js +18 -31
  74. package/dist/module/hooks/push/useIosVoipPushEventsSetupEffect.js.map +1 -1
  75. package/dist/module/hooks/useAndroidKeepCallAliveEffect.js +66 -99
  76. package/dist/module/hooks/useAndroidKeepCallAliveEffect.js.map +1 -1
  77. package/dist/module/hooks/useScreenShareAudioMixing.js +119 -0
  78. package/dist/module/hooks/useScreenShareAudioMixing.js.map +1 -0
  79. package/dist/module/hooks/useScreenShareButton.js +57 -3
  80. package/dist/module/hooks/useScreenShareButton.js.map +1 -1
  81. package/dist/module/index.js +1 -0
  82. package/dist/module/index.js.map +1 -1
  83. package/dist/module/modules/ScreenShareAudioManager.js +47 -0
  84. package/dist/module/modules/ScreenShareAudioManager.js.map +1 -0
  85. package/dist/module/modules/call-manager/CallManager.js +26 -0
  86. package/dist/module/modules/call-manager/CallManager.js.map +1 -1
  87. package/dist/module/providers/StreamCall/index.js +16 -6
  88. package/dist/module/providers/StreamCall/index.js.map +1 -1
  89. package/dist/module/utils/StreamVideoRN/index.js +35 -21
  90. package/dist/module/utils/StreamVideoRN/index.js.map +1 -1
  91. package/dist/module/utils/internal/callingx/audioSessionPromise.js +61 -0
  92. package/dist/module/utils/internal/callingx/audioSessionPromise.js.map +1 -0
  93. package/dist/module/utils/internal/callingx/callingx.js +140 -0
  94. package/dist/module/utils/internal/callingx/callingx.js.map +1 -0
  95. package/dist/module/utils/internal/registerSDKGlobals.js +53 -3
  96. package/dist/module/utils/internal/registerSDKGlobals.js.map +1 -1
  97. package/dist/module/utils/keepCallAliveHeadlessTask.js +42 -0
  98. package/dist/module/utils/keepCallAliveHeadlessTask.js.map +1 -0
  99. package/dist/module/utils/push/android.js +137 -204
  100. package/dist/module/utils/push/android.js.map +1 -1
  101. package/dist/module/utils/push/internal/ios.js +17 -34
  102. package/dist/module/utils/push/internal/ios.js.map +1 -1
  103. package/dist/module/utils/push/internal/rxSubjects.js +0 -44
  104. package/dist/module/utils/push/internal/rxSubjects.js.map +1 -1
  105. package/dist/module/utils/push/internal/utils.js +67 -50
  106. package/dist/module/utils/push/internal/utils.js.map +1 -1
  107. package/dist/module/utils/push/ios.js.map +1 -1
  108. package/dist/module/utils/push/libs/callingx.js +67 -0
  109. package/dist/module/utils/push/libs/callingx.js.map +1 -0
  110. package/dist/module/utils/push/libs/index.js +1 -2
  111. package/dist/module/utils/push/libs/index.js.map +1 -1
  112. package/dist/module/utils/push/libs/notifee/index.js +0 -18
  113. package/dist/module/utils/push/libs/notifee/index.js.map +1 -1
  114. package/dist/module/utils/push/setupCallingExpEvents.js +99 -0
  115. package/dist/module/utils/push/setupCallingExpEvents.js.map +1 -0
  116. package/dist/module/utils/push/setupIosVoipPushEvents.js +7 -6
  117. package/dist/module/utils/push/setupIosVoipPushEvents.js.map +1 -1
  118. package/dist/module/version.js +1 -1
  119. package/dist/module/version.js.map +1 -1
  120. package/dist/typescript/components/Call/CallControls/ScreenShareToggleButton.d.ts +6 -1
  121. package/dist/typescript/components/Call/CallControls/ScreenShareToggleButton.d.ts.map +1 -1
  122. package/dist/typescript/hooks/index.d.ts +1 -0
  123. package/dist/typescript/hooks/index.d.ts.map +1 -1
  124. package/dist/typescript/hooks/push/index.d.ts.map +1 -1
  125. package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts +5 -0
  126. package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts.map +1 -0
  127. package/dist/typescript/hooks/push/useIosVoipPushEventsSetupEffect.d.ts.map +1 -1
  128. package/dist/typescript/hooks/useAndroidKeepCallAliveEffect.d.ts.map +1 -1
  129. package/dist/typescript/hooks/useScreenShareAudioMixing.d.ts +14 -0
  130. package/dist/typescript/hooks/useScreenShareAudioMixing.d.ts.map +1 -0
  131. package/dist/typescript/hooks/useScreenShareButton.d.ts +39 -2
  132. package/dist/typescript/hooks/useScreenShareButton.d.ts.map +1 -1
  133. package/dist/typescript/index.d.ts +1 -0
  134. package/dist/typescript/index.d.ts.map +1 -1
  135. package/dist/typescript/modules/ScreenShareAudioManager.d.ts +28 -0
  136. package/dist/typescript/modules/ScreenShareAudioManager.d.ts.map +1 -0
  137. package/dist/typescript/modules/call-manager/CallManager.d.ts +5 -0
  138. package/dist/typescript/modules/call-manager/CallManager.d.ts.map +1 -1
  139. package/dist/typescript/providers/StreamCall/index.d.ts.map +1 -1
  140. package/dist/typescript/utils/StreamVideoRN/index.d.ts +22 -2
  141. package/dist/typescript/utils/StreamVideoRN/index.d.ts.map +1 -1
  142. package/dist/typescript/utils/StreamVideoRN/types.d.ts +59 -25
  143. package/dist/typescript/utils/StreamVideoRN/types.d.ts.map +1 -1
  144. package/dist/typescript/utils/internal/callingx/audioSessionPromise.d.ts +16 -0
  145. package/dist/typescript/utils/internal/callingx/audioSessionPromise.d.ts.map +1 -0
  146. package/dist/typescript/utils/internal/callingx/callingx.d.ts +18 -0
  147. package/dist/typescript/utils/internal/callingx/callingx.d.ts.map +1 -0
  148. package/dist/typescript/utils/internal/registerSDKGlobals.d.ts.map +1 -1
  149. package/dist/typescript/utils/keepCallAliveHeadlessTask.d.ts +10 -0
  150. package/dist/typescript/utils/keepCallAliveHeadlessTask.d.ts.map +1 -0
  151. package/dist/typescript/utils/push/android.d.ts +1 -2
  152. package/dist/typescript/utils/push/android.d.ts.map +1 -1
  153. package/dist/typescript/utils/push/internal/ios.d.ts.map +1 -1
  154. package/dist/typescript/utils/push/internal/rxSubjects.d.ts +0 -33
  155. package/dist/typescript/utils/push/internal/rxSubjects.d.ts.map +1 -1
  156. package/dist/typescript/utils/push/internal/utils.d.ts +14 -8
  157. package/dist/typescript/utils/push/internal/utils.d.ts.map +1 -1
  158. package/dist/typescript/utils/push/ios.d.ts +1 -2
  159. package/dist/typescript/utils/push/ios.d.ts.map +1 -1
  160. package/dist/typescript/utils/push/libs/callingx.d.ts +9 -0
  161. package/dist/typescript/utils/push/libs/callingx.d.ts.map +1 -0
  162. package/dist/typescript/utils/push/libs/firebaseMessaging/index.d.ts +16 -2
  163. package/dist/typescript/utils/push/libs/firebaseMessaging/index.d.ts.map +1 -1
  164. package/dist/typescript/utils/push/libs/index.d.ts +1 -2
  165. package/dist/typescript/utils/push/libs/index.d.ts.map +1 -1
  166. package/dist/typescript/utils/push/libs/notifee/index.d.ts +0 -1
  167. package/dist/typescript/utils/push/libs/notifee/index.d.ts.map +1 -1
  168. package/dist/typescript/utils/push/setupCallingExpEvents.d.ts +8 -0
  169. package/dist/typescript/utils/push/setupCallingExpEvents.d.ts.map +1 -0
  170. package/dist/typescript/utils/push/setupIosVoipPushEvents.d.ts.map +1 -1
  171. package/dist/typescript/version.d.ts +1 -1
  172. package/dist/typescript/version.d.ts.map +1 -1
  173. package/expo-config-plugin/dist/withAndroidManifest.js +1 -33
  174. package/expo-config-plugin/dist/withAndroidPermissions.js +2 -7
  175. package/expo-config-plugin/dist/withAppDelegate.js +19 -197
  176. package/expo-config-plugin/dist/withMainActivity.js +1 -1
  177. package/expo-config-plugin/dist/withiOSInfoPlist.js +2 -3
  178. package/ios/StreamInCallManager.m +2 -0
  179. package/ios/StreamInCallManager.swift +19 -7
  180. package/ios/StreamVideoReactNative.h +7 -4
  181. package/ios/StreamVideoReactNative.m +282 -86
  182. package/package.json +13 -18
  183. package/src/components/Call/CallControls/ScreenShareToggleButton.tsx +11 -1
  184. package/src/hooks/index.ts +1 -0
  185. package/src/hooks/push/index.ts +0 -2
  186. package/src/hooks/push/useCallingExpWithCallingStateEffect.ts +189 -0
  187. package/src/hooks/push/useIosVoipPushEventsSetupEffect.ts +21 -34
  188. package/src/hooks/useAndroidKeepCallAliveEffect.ts +94 -120
  189. package/src/hooks/useScreenShareAudioMixing.ts +130 -0
  190. package/src/hooks/useScreenShareButton.ts +87 -2
  191. package/src/index.ts +1 -0
  192. package/src/modules/ScreenShareAudioManager.ts +49 -0
  193. package/src/modules/call-manager/CallManager.ts +36 -0
  194. package/src/modules/call-manager/native-module.d.ts +7 -0
  195. package/src/providers/StreamCall/index.tsx +17 -6
  196. package/src/utils/StreamVideoRN/index.ts +42 -30
  197. package/src/utils/StreamVideoRN/types.ts +61 -25
  198. package/src/utils/internal/callingx/audioSessionPromise.ts +65 -0
  199. package/src/utils/internal/callingx/callingx.ts +194 -0
  200. package/src/utils/internal/registerSDKGlobals.ts +52 -4
  201. package/src/utils/keepCallAliveHeadlessTask.ts +54 -0
  202. package/src/utils/push/android.ts +198 -311
  203. package/src/utils/push/internal/ios.ts +28 -44
  204. package/src/utils/push/internal/rxSubjects.ts +0 -61
  205. package/src/utils/push/internal/utils.ts +108 -64
  206. package/src/utils/push/ios.ts +1 -6
  207. package/src/utils/push/libs/callingx.ts +89 -0
  208. package/src/utils/push/libs/index.ts +1 -2
  209. package/src/utils/push/libs/notifee/index.ts +0 -27
  210. package/src/utils/push/setupCallingExpEvents.ts +135 -0
  211. package/src/utils/push/setupIosVoipPushEvents.ts +11 -7
  212. package/src/version.ts +1 -1
  213. package/android/src/main/java/com/streamvideo/reactnative/util/CallAliveServiceChecker.kt +0 -95
  214. package/dist/commonjs/hooks/push/useIosCallkeepWithCallingStateEffect.js +0 -160
  215. package/dist/commonjs/hooks/push/useIosCallkeepWithCallingStateEffect.js.map +0 -1
  216. package/dist/commonjs/hooks/push/useProcessPushCallEffect.js +0 -67
  217. package/dist/commonjs/hooks/push/useProcessPushCallEffect.js.map +0 -1
  218. package/dist/commonjs/utils/push/libs/callkeep.js +0 -17
  219. package/dist/commonjs/utils/push/libs/callkeep.js.map +0 -1
  220. package/dist/commonjs/utils/push/libs/voipPushNotification.js +0 -17
  221. package/dist/commonjs/utils/push/libs/voipPushNotification.js.map +0 -1
  222. package/dist/commonjs/utils/push/setupIosCallKeepEvents.js +0 -205
  223. package/dist/commonjs/utils/push/setupIosCallKeepEvents.js.map +0 -1
  224. package/dist/module/hooks/push/useIosCallkeepWithCallingStateEffect.js +0 -153
  225. package/dist/module/hooks/push/useIosCallkeepWithCallingStateEffect.js.map +0 -1
  226. package/dist/module/hooks/push/useProcessPushCallEffect.js +0 -60
  227. package/dist/module/hooks/push/useProcessPushCallEffect.js.map +0 -1
  228. package/dist/module/utils/push/libs/callkeep.js +0 -11
  229. package/dist/module/utils/push/libs/callkeep.js.map +0 -1
  230. package/dist/module/utils/push/libs/voipPushNotification.js +0 -11
  231. package/dist/module/utils/push/libs/voipPushNotification.js.map +0 -1
  232. package/dist/module/utils/push/setupIosCallKeepEvents.js +0 -199
  233. package/dist/module/utils/push/setupIosCallKeepEvents.js.map +0 -1
  234. package/dist/typescript/hooks/push/useIosCallkeepWithCallingStateEffect.d.ts +0 -5
  235. package/dist/typescript/hooks/push/useIosCallkeepWithCallingStateEffect.d.ts.map +0 -1
  236. package/dist/typescript/hooks/push/useProcessPushCallEffect.d.ts +0 -8
  237. package/dist/typescript/hooks/push/useProcessPushCallEffect.d.ts.map +0 -1
  238. package/dist/typescript/utils/push/libs/callkeep.d.ts +0 -3
  239. package/dist/typescript/utils/push/libs/callkeep.d.ts.map +0 -1
  240. package/dist/typescript/utils/push/libs/voipPushNotification.d.ts +0 -3
  241. package/dist/typescript/utils/push/libs/voipPushNotification.d.ts.map +0 -1
  242. package/dist/typescript/utils/push/setupIosCallKeepEvents.d.ts +0 -6
  243. package/dist/typescript/utils/push/setupIosCallKeepEvents.d.ts.map +0 -1
  244. package/src/hooks/push/useIosCallkeepWithCallingStateEffect.ts +0 -235
  245. package/src/hooks/push/useProcessPushCallEffect.ts +0 -108
  246. package/src/utils/push/libs/callkeep.ts +0 -16
  247. package/src/utils/push/libs/voipPushNotification.ts +0 -17
  248. package/src/utils/push/setupIosCallKeepEvents.ts +0 -252
@@ -0,0 +1,189 @@
1
+ import { Call, CallingState, videoLoggerSystem } from '@stream-io/video-client';
2
+ import { useCall, useCallStateHooks } from '@stream-io/video-react-bindings';
3
+ import { useEffect, useMemo } from 'react';
4
+ import { filter, take } from 'rxjs/operators';
5
+ import { getCallDisplayName } from '../../utils/internal/callingx/callingx';
6
+ import { getCallingxLibIfAvailable } from '../../utils/push/libs/callingx';
7
+
8
+ const logger = videoLoggerSystem.getLogger('callingx');
9
+
10
+ /**
11
+ * This hook is used to inform sync call state with CallKit/Telecom (i.e. start call, end call, mute/unmute call).
12
+ */
13
+ export const useCallingExpWithCallingStateEffect = () => {
14
+ const { useMicrophoneState, useParticipants, useCallMembers } =
15
+ useCallStateHooks();
16
+
17
+ const activeCall = useCall();
18
+ const { isMute, microphone } = useMicrophoneState();
19
+ const callMembers = useCallMembers();
20
+ const participants = useParticipants();
21
+
22
+ const activeCallCid = activeCall?.cid;
23
+ const currentUserId = activeCall?.currentUserId;
24
+ const isIncoming =
25
+ (activeCall?.ringing && !activeCall?.isCreatedByMe) || false;
26
+
27
+ const callDisplayName = useMemo(
28
+ () => getCallDisplayName(callMembers, participants, currentUserId),
29
+ [callMembers, participants, currentUserId],
30
+ );
31
+
32
+ useEffect(() => {
33
+ const callingx = getCallingxLibIfAvailable();
34
+ if (!callingx?.isSetup || !activeCall) {
35
+ return;
36
+ }
37
+ // need to capture RINGING -> Joining -> Joined state change for the first time
38
+ // and inform callingx that the call is active
39
+ const shouldMakeCallActive = (call: Call): boolean => {
40
+ // only for outgoing calls or non-ringing ongoing calls in callingx
41
+ // Note: incoming calls are handled by callingx pending states instead
42
+ return (
43
+ (call.ringing && call.isCreatedByMe) ||
44
+ (!call.ringing && callingx.isOngoingCallsEnabled)
45
+ );
46
+ };
47
+ const subscription = activeCall.state.callingState$
48
+ .pipe(
49
+ filter(
50
+ (callingState) =>
51
+ shouldMakeCallActive(activeCall) &&
52
+ callingState === CallingState.JOINED &&
53
+ callingx.isCallTracked(activeCall.cid),
54
+ ),
55
+ take(1), // only need to capture the first joined state for outgoing calls
56
+ // then subscription completes and is automatically unsubscribed
57
+ )
58
+ .subscribe(() => {
59
+ callingx.setCurrentCallActive(activeCall.cid);
60
+ });
61
+ return () => {
62
+ subscription.unsubscribe();
63
+ };
64
+ }, [activeCall]);
65
+
66
+ useEffect(() => {
67
+ return () => {
68
+ const callingx = getCallingxLibIfAvailable();
69
+ if (!callingx?.isSetup || !activeCallCid) {
70
+ return;
71
+ }
72
+
73
+ const isCallTracked = callingx.isCallTracked(activeCallCid);
74
+ if (!isCallTracked) {
75
+ logger.debug(
76
+ `useCallingExpWithCallingStateEffect:No active call cid to end in calling exp: ${activeCallCid} isCallTracked: ${isCallTracked}`,
77
+ );
78
+ return;
79
+ }
80
+ //if incoming stream call was unmounted, we need to end the call in CallKit/Telecom
81
+ logger.debug(
82
+ `useCallingExpWithCallingStateEffect: Ending call in callingx: ${activeCallCid}`,
83
+ );
84
+ callingx
85
+ .endCallWithReason(activeCallCid, 'local')
86
+ .catch((error: unknown) => {
87
+ logger.error(
88
+ `useCallingExpWithCallingStateEffect: Error ending call in callingx: ${activeCallCid}`,
89
+ error,
90
+ );
91
+ });
92
+ };
93
+ }, [activeCallCid]);
94
+
95
+ useEffect(() => {
96
+ const callingx = getCallingxLibIfAvailable();
97
+ if (!callingx?.isSetup || !activeCallCid) {
98
+ return;
99
+ }
100
+
101
+ const isCallTracked = callingx.isCallTracked(activeCallCid);
102
+ if (!isCallTracked) {
103
+ logger.debug(
104
+ `useCallingExpWithCallingStateEffect:No active call cid to update callingx: ${activeCallCid} isCallTracked: ${isCallTracked}`,
105
+ );
106
+ return;
107
+ }
108
+
109
+ callingx.updateDisplay(
110
+ activeCallCid,
111
+ activeCallCid,
112
+ callDisplayName,
113
+ isIncoming,
114
+ );
115
+ }, [activeCallCid, callDisplayName, isIncoming]);
116
+
117
+ // Sync microphone mute state from app → CallKit
118
+ useEffect(() => {
119
+ const callingx = getCallingxLibIfAvailable();
120
+ if (!callingx?.isSetup || !activeCallCid) {
121
+ return;
122
+ }
123
+
124
+ const isCallTracked = callingx.isCallTracked(activeCallCid);
125
+ if (!isCallTracked) {
126
+ logger.debug(
127
+ `useCallingExpWithCallingStateEffect: No active call cid to set muted in calling exp: ${activeCallCid} isCallTracked: ${isCallTracked}`,
128
+ );
129
+ return;
130
+ }
131
+
132
+ callingx.setMutedCall(activeCallCid, isMute);
133
+ }, [activeCallCid, isMute]);
134
+
135
+ // Sync mute state from CallKit → app (only for system-initiated mute actions)
136
+ useEffect(() => {
137
+ const callingx = getCallingxLibIfAvailable();
138
+ if (!callingx?.isSetup || !activeCallCid) {
139
+ logger.debug(
140
+ `useCallingExpWithCallingStateEffect: No active call cid to set muted in calling exp: ${activeCallCid} callingx isSetup: ${callingx?.isSetup}`,
141
+ );
142
+ return;
143
+ }
144
+
145
+ // Listen to mic toggle events from CallKit/Telecom and update stream call microphone state.
146
+ // Only system-initiated mute actions (e.g. user tapped mute on the native CallKit UI)
147
+ // are sent here — app-initiated actions are filtered out on the native side to prevent
148
+ // the feedback loop: app mutes mic → setMutedCall → CallKit delegate → event to JS → loop.
149
+ const subscription = callingx.addEventListener(
150
+ 'didPerformSetMutedCallAction',
151
+ async (event: { callId: string; muted: boolean }) => {
152
+ const { callId, muted } = event;
153
+
154
+ const isCallTracked = callingx.isCallTracked(activeCallCid);
155
+ if (!isCallTracked || callId !== activeCallCid) {
156
+ logger.debug(
157
+ `useCallingExpWithCallingStateEffect: No active call cid to set muted in calling exp: ${activeCallCid} isCallTracked: ${isCallTracked} callId: ${callId}`,
158
+ );
159
+ return;
160
+ }
161
+
162
+ const isCurrentlyMuted = microphone.state.status === 'disabled';
163
+ if (isCurrentlyMuted === muted) {
164
+ logger.debug(
165
+ `useCallingExpWithCallingStateEffect: Mic toggle is already in the desired state: ${muted} for call: ${activeCallCid}`,
166
+ );
167
+ return;
168
+ }
169
+
170
+ try {
171
+ if (muted) {
172
+ await microphone.disable();
173
+ } else {
174
+ await microphone.enable();
175
+ }
176
+ } catch (error: unknown) {
177
+ logger.error(
178
+ `useCallingExpWithCallingStateEffect: Error toggling mic in calling exp: ${activeCallCid}`,
179
+ error,
180
+ );
181
+ }
182
+ },
183
+ );
184
+
185
+ return () => {
186
+ subscription.remove();
187
+ };
188
+ }, [activeCallCid, microphone]);
189
+ };
@@ -1,6 +1,4 @@
1
1
  import { type MutableRefObject, useEffect, useRef, useState } from 'react';
2
- import { getVoipPushNotificationLib } from '../../utils/push/libs';
3
-
4
2
  import { Platform } from 'react-native';
5
3
  import { StreamVideoRN } from '../../utils';
6
4
  import { onVoipNotificationReceived } from '../../utils/push/internal/ios';
@@ -10,6 +8,7 @@ import {
10
8
  } from '@stream-io/video-react-bindings';
11
9
  import { setPushLogoutCallback } from '../../utils/internal/pushLogoutCallback';
12
10
  import { StreamVideoClient, videoLoggerSystem } from '@stream-io/video-client';
11
+ import { getCallingxLibIfAvailable } from '../../utils/push/libs';
13
12
 
14
13
  const logger = videoLoggerSystem.getLogger('useIosVoipPushEventsSetupEffect');
15
14
 
@@ -28,6 +27,7 @@ function setLogoutCallback(
28
27
  lastVoipTokenRef.current = { token: '', userId: '' };
29
28
  try {
30
29
  await client.removeDevice(token);
30
+ logger.debug('PushLogoutCallback - Removed voip token', token);
31
31
  } catch (err) {
32
32
  logger.warn('PushLogoutCallback - Failed to remove voip token', err);
33
33
  }
@@ -89,24 +89,12 @@ export const useIosVoipPushEventsSetupEffect = () => {
89
89
  useEffect(() => {
90
90
  const pushConfig = StreamVideoRN.getConfig().push;
91
91
  const pushProviderName = pushConfig?.ios.pushProviderName;
92
- if (Platform.OS !== 'ios' || !client || !pushProviderName) {
93
- return;
94
- }
95
- if (!pushConfig.android.incomingCallChannel) {
96
- // TODO: remove this check and find a better way once we have telecom integration for android
97
- logger.debug(
98
- 'android incomingCallChannel is not defined, so skipping the useIosVoipPushEventsSetupEffect',
99
- );
92
+ const callingx = getCallingxLibIfAvailable();
93
+
94
+ if (Platform.OS !== 'ios' || !client || !pushProviderName || !callingx) {
100
95
  return;
101
96
  }
102
97
 
103
- const voipPushNotification = getVoipPushNotificationLib();
104
-
105
- // even though we do this natively, we have to still register here again
106
- // natively this will make sure "register" event for JS is sent with the last push token
107
- // Necessary if client changed before we got the event here or user logged out and logged in again
108
- voipPushNotification.registerVoipToken();
109
-
110
98
  const onTokenReceived = (token: string) => {
111
99
  const userId = client.streamClient._user?.id ?? '';
112
100
  if (client.streamClient.anonymous || !token || !userId) {
@@ -145,24 +133,24 @@ export const useIosVoipPushEventsSetupEffect = () => {
145
133
  });
146
134
  };
147
135
  // fired when PushKit give us the latest token
148
- voipPushNotification.addEventListener('register', (token) => {
149
- onTokenReceived(token);
150
- });
136
+ const voipRegisterListener = callingx.addEventListener(
137
+ 'voipNotificationsRegistered',
138
+ ({ token }) => {
139
+ onTokenReceived(token);
140
+ },
141
+ );
151
142
 
152
- // this will fire when there are events occured before js bridge initialized
153
- voipPushNotification.addEventListener('didLoadWithEvents', (events) => {
154
- if (!events || !Array.isArray(events) || events.length < 1) {
155
- return;
156
- }
157
- for (const voipPushEvent of events) {
158
- const { name, data } = voipPushEvent;
159
- if (name === 'RNVoipPushRemoteNotificationsRegisteredEvent') {
160
- onTokenReceived(data);
161
- } else if (name === 'RNVoipPushRemoteNotificationReceivedEvent') {
162
- onVoipNotificationReceived(data, pushConfig);
163
- }
143
+ // this will return events that were fired before js bridge initialized
144
+ callingx.getInitialVoipEvents().forEach(({ eventName, params }) => {
145
+ if (eventName === 'voipNotificationsRegistered' && 'token' in params) {
146
+ onTokenReceived(params.token);
147
+ } else if (eventName === 'voipNotificationReceived') {
148
+ onVoipNotificationReceived(params, pushConfig);
164
149
  }
165
150
  });
151
+
152
+ callingx.registerVoipToken();
153
+
166
154
  lastListener.count += 1;
167
155
  const currentListenerCount = lastListener.count;
168
156
 
@@ -175,8 +163,7 @@ export const useIosVoipPushEventsSetupEffect = () => {
175
163
  return;
176
164
  }
177
165
  logger.debug(`Voip event listeners are removed for user: ${userId}`);
178
- voipPushNotification.removeEventListener('didLoadWithEvents');
179
- voipPushNotification.removeEventListener('register');
166
+ voipRegisterListener.remove();
180
167
  };
181
168
  }, [client]);
182
169
  };
@@ -5,76 +5,48 @@ import {
5
5
  AppState,
6
6
  type AppStateStatus,
7
7
  NativeModules,
8
+ PermissionsAndroid,
8
9
  Platform,
9
10
  } from 'react-native';
10
- import { Call, CallingState, videoLoggerSystem } from '@stream-io/video-client';
11
- import {
12
- getKeepCallAliveForegroundServiceTypes,
13
- getNotifeeLibNoThrowForKeepCallAlive,
14
- } from '../utils/push/libs/notifee';
11
+ import { CallingState, videoLoggerSystem } from '@stream-io/video-client';
12
+ import { keepCallAliveCallRef } from '../utils/keepCallAliveHeadlessTask';
13
+ import { getNotifeeLibNoThrowForKeepCallAlive } from '../utils/push/libs/notifee';
14
+ import { getCallingxLibIfAvailable } from '../utils/push/libs';
15
15
 
16
16
  const notifeeLib = getNotifeeLibNoThrowForKeepCallAlive();
17
- const callToPassToForegroundService: { current: Call | undefined } = {
18
- current: undefined,
19
- };
20
17
 
21
- function setForegroundService() {
22
- if (Platform.OS === 'ios' || !notifeeLib) return;
23
- NativeModules.StreamVideoReactNative.isCallAliveConfigured().then(
24
- (isConfigured: boolean) => {
25
- if (!isConfigured) {
26
- const logger = videoLoggerSystem.getLogger(
27
- 'setForegroundService method',
28
- );
29
- logger.info(
30
- 'KeepCallAlive is not configured. Skipping foreground service setup.',
31
- );
32
- return;
33
- }
34
- notifeeLib.default.registerForegroundService(() => {
35
- const task = new Promise((resolve) => {
36
- const logger = videoLoggerSystem.getLogger(
37
- 'setForegroundService method',
38
- );
39
- logger.info('Foreground service running for call in progress');
40
- // any task to run from SDK in the foreground service must be added
41
- resolve(true);
42
- });
43
- const videoConfig = StreamVideoRN.getConfig();
44
- const foregroundServiceConfig = videoConfig.foregroundService;
45
- const { taskToRun } = foregroundServiceConfig.android;
46
- const call = callToPassToForegroundService.current;
47
- if (!call) {
48
- const logger = videoLoggerSystem.getLogger(
49
- 'setForegroundService method',
50
- );
51
- logger.warn('No call to pass to foreground service');
52
- return task.then(() => new Promise(() => {}));
53
- }
54
- callToPassToForegroundService.current = undefined;
55
- return task.then(() => taskToRun(call));
56
- });
57
- },
58
- );
18
+ async function stopForegroundServiceNoThrow() {
19
+ const logger = videoLoggerSystem.getLogger('stopForegroundServiceNoThrow');
20
+ try {
21
+ await NativeModules.StreamVideoReactNative.stopKeepCallAliveService();
22
+ } catch (e) {
23
+ logger.warn('Failed to stop keep-call-alive foreground service', e);
24
+ }
59
25
  }
60
26
 
61
27
  async function startForegroundService(call_cid: string) {
62
- const isCallAliveConfigured =
63
- await NativeModules.StreamVideoReactNative.isCallAliveConfigured();
28
+ const logger = videoLoggerSystem.getLogger('startForegroundService');
29
+ const isCallAliveConfigured = await (async () => {
30
+ try {
31
+ return await NativeModules.StreamVideoReactNative.isCallAliveConfigured();
32
+ } catch (e) {
33
+ logger.warn('Failed to check whether KeepCallAlive is configured', e);
34
+ return false;
35
+ }
36
+ })();
64
37
  if (!isCallAliveConfigured) {
65
- const logger = videoLoggerSystem.getLogger('startForegroundService');
66
38
  logger.info(
67
39
  'KeepCallAlive is not configured. Skipping foreground service setup.',
68
40
  );
69
41
  return;
70
42
  }
71
- // check for notification permission and then start the foreground service
72
- if (!notifeeLib) return;
73
- const settings = await notifeeLib.default.getNotificationSettings();
74
- if (
75
- settings.authorizationStatus !== notifeeLib.AuthorizationStatus.AUTHORIZED
76
- ) {
77
- const logger = videoLoggerSystem.getLogger('startForegroundService');
43
+ // Check for notification permission (Android 13+) before starting the service.
44
+ const hasPostNotificationsPermission =
45
+ Number(Platform.Version) < 33 ||
46
+ (await PermissionsAndroid.check(
47
+ PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
48
+ ));
49
+ if (!hasPostNotificationsPermission) {
78
50
  logger.info(
79
51
  'Notification permission not granted, can not start foreground service to keep the call alive',
80
52
  );
@@ -83,38 +55,28 @@ async function startForegroundService(call_cid: string) {
83
55
  const videoConfig = StreamVideoRN.getConfig();
84
56
  const foregroundServiceConfig = videoConfig.foregroundService;
85
57
  const notificationTexts = foregroundServiceConfig.android.notificationTexts;
86
- const channelId = foregroundServiceConfig.android.channel.id;
87
- await notifeeLib.default.createChannel(
88
- foregroundServiceConfig.android.channel,
89
- );
90
- const foregroundServiceTypes = await getKeepCallAliveForegroundServiceTypes();
58
+ const channel = foregroundServiceConfig.android.channel;
59
+ const smallIconName = videoConfig.push?.android.smallIcon;
60
+
91
61
  // NOTE: we use requestAnimationFrame to ensure that the foreground service is started after all the current UI operations are done
92
62
  // this is a workaround for the crash - android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground()
93
63
  // this crash was reproducible only in some android devices
94
- requestAnimationFrame(() => {
95
- notifeeLib.default.displayNotification({
96
- id: call_cid,
97
- title: notificationTexts.title,
98
- body: notificationTexts.body,
99
- android: {
100
- channelId,
101
- smallIcon: videoConfig.push?.android.smallIcon,
102
- foregroundServiceTypes,
103
- asForegroundService: true,
104
- ongoing: true, // user cannot dismiss the notification
105
- colorized: true,
106
- pressAction: {
107
- id: 'default',
108
- launchActivity: 'default', // open the app when the notification is pressed
109
- },
110
- },
111
- });
64
+ requestAnimationFrame(async () => {
65
+ try {
66
+ await NativeModules.StreamVideoReactNative.startKeepCallAliveService(
67
+ call_cid,
68
+ channel.id,
69
+ channel.name,
70
+ notificationTexts.title,
71
+ notificationTexts.body,
72
+ smallIconName ?? null,
73
+ );
74
+ } catch (e) {
75
+ logger.warn('Failed to start keep-call-alive foreground service', e);
76
+ }
112
77
  });
113
78
  }
114
79
 
115
- // flag to check if setForegroundService has already been run once
116
- let isSetForegroundServiceRan = false;
117
-
118
80
  /**
119
81
  * This hook is used to keep the call alive in the background for Android.
120
82
  * It starts a foreground service to keep the call alive as soon as the call is joined
@@ -125,7 +87,7 @@ export const useAndroidKeepCallAliveEffect = () => {
125
87
  const foregroundServiceStartedRef = useRef(false);
126
88
 
127
89
  const call = useCall();
128
- callToPassToForegroundService.current = call;
90
+ keepCallAliveCallRef.current = call;
129
91
  const activeCallCid = call?.cid;
130
92
  const { useCallCallingState } = useCallStateHooks();
131
93
  const callingState = useCallCallingState();
@@ -133,6 +95,7 @@ export const useAndroidKeepCallAliveEffect = () => {
133
95
  const isOutgoingCall =
134
96
  callingState === CallingState.RINGING && call?.isCreatedByMe;
135
97
  const isCallJoined = callingState === CallingState.JOINED;
98
+ const isRingingCall = call?.ringing;
136
99
 
137
100
  const shouldStartForegroundService =
138
101
  !foregroundServiceStartedRef.current && (isOutgoingCall || isCallJoined);
@@ -141,7 +104,14 @@ export const useAndroidKeepCallAliveEffect = () => {
141
104
  if (Platform.OS === 'ios' || !activeCallCid) {
142
105
  return undefined;
143
106
  }
144
- if (!notifeeLib) return undefined;
107
+
108
+ const callingx = getCallingxLibIfAvailable();
109
+ if (
110
+ callingx?.isSetup &&
111
+ (isRingingCall || (!isRingingCall && callingx?.isOngoingCallsEnabled))
112
+ ) {
113
+ return undefined;
114
+ }
145
115
 
146
116
  // start foreground service as soon as the call is joined
147
117
  if (shouldStartForegroundService) {
@@ -149,23 +119,21 @@ export const useAndroidKeepCallAliveEffect = () => {
149
119
  if (foregroundServiceStartedRef.current) {
150
120
  return;
151
121
  }
152
- if (!isSetForegroundServiceRan) {
153
- isSetForegroundServiceRan = true;
154
- setForegroundService();
155
- }
156
- const notifee = notifeeLib.default;
157
- const displayedNotifications =
158
- await notifee.getDisplayedNotifications();
159
- const activeCallNotification = displayedNotifications.find(
160
- (notification) => notification.id === activeCallCid,
161
- );
162
- if (activeCallNotification) {
163
- callToPassToForegroundService.current = undefined;
164
- // this means that we have a incoming call notification shown as foreground service and we must stop it
165
- notifee.stopForegroundService();
166
- notifee.cancelDisplayedNotification(activeCallCid);
122
+ // Optional compatibility cleanup: if the app uses Notifee for ringing push,
123
+ // we might have an incoming call notification running as a foreground service.
124
+ if (notifeeLib) {
125
+ const notifee = notifeeLib.default;
126
+ const displayedNotifications =
127
+ await notifee.getDisplayedNotifications();
128
+ const activeCallNotification = displayedNotifications.find(
129
+ (notification) => notification.id === activeCallCid,
130
+ );
131
+ if (activeCallNotification) {
132
+ // this means that we have a incoming call notification shown as foreground service and we must stop it
133
+ notifee.stopForegroundService();
134
+ notifee.cancelDisplayedNotification(activeCallCid);
135
+ }
167
136
  }
168
- // check for notification permission and then start the foreground service
169
137
 
170
138
  await startForegroundService(activeCallCid);
171
139
  foregroundServiceStartedRef.current = true;
@@ -174,7 +142,6 @@ export const useAndroidKeepCallAliveEffect = () => {
174
142
  // ensure that app is active before running the function
175
143
  if (AppState.currentState === 'active') {
176
144
  run();
177
- return undefined;
178
145
  }
179
146
  const sub = AppState.addEventListener(
180
147
  'change',
@@ -192,42 +159,49 @@ export const useAndroidKeepCallAliveEffect = () => {
192
159
  return () => {
193
160
  // cancel any notifee displayed notification when the call has transitioned out of ringing
194
161
  // NOTE: cancels only the non fg service notifications
195
- notifeeLib.default.cancelDisplayedNotification(activeCallCid);
162
+ if (notifeeLib) {
163
+ notifeeLib.default.cancelDisplayedNotification(activeCallCid);
164
+ }
196
165
  };
197
166
  } else if (
198
167
  callingState === CallingState.IDLE ||
199
168
  callingState === CallingState.LEFT
200
169
  ) {
201
170
  if (foregroundServiceStartedRef.current) {
202
- callToPassToForegroundService.current = undefined;
171
+ keepCallAliveCallRef.current = undefined;
203
172
  // stop foreground service when the call is not active
204
- notifeeLib.default.stopForegroundService();
173
+ stopForegroundServiceNoThrow();
205
174
  foregroundServiceStartedRef.current = false;
206
175
  } else {
207
- notifeeLib.default
208
- .getDisplayedNotifications()
209
- .then((displayedNotifications) => {
210
- const activeCallNotification = displayedNotifications.find(
211
- (notification) => notification.id === activeCallCid,
212
- );
213
- if (activeCallNotification) {
214
- callToPassToForegroundService.current = undefined;
215
- // this means that we have a incoming call notification shown as foreground service and we must stop it
216
- notifeeLib.default.stopForegroundService();
217
- }
218
- });
176
+ if (notifeeLib) {
177
+ notifeeLib.default
178
+ .getDisplayedNotifications()
179
+ .then((displayedNotifications) => {
180
+ const activeCallNotification = displayedNotifications.find(
181
+ (notification) => notification.id === activeCallCid,
182
+ );
183
+ if (activeCallNotification) {
184
+ // this means that we have a incoming call notification shown as foreground service and we must stop it
185
+ notifeeLib.default.stopForegroundService();
186
+ }
187
+ });
188
+ }
219
189
  }
220
190
  }
221
191
  return undefined;
222
- }, [activeCallCid, callingState, shouldStartForegroundService]);
192
+ }, [
193
+ activeCallCid,
194
+ callingState,
195
+ shouldStartForegroundService,
196
+ isRingingCall,
197
+ ]);
223
198
 
224
199
  useEffect(() => {
225
200
  return () => {
226
201
  // stop foreground service when this effect is unmounted
227
202
  if (foregroundServiceStartedRef.current) {
228
- if (!notifeeLib) return;
229
- callToPassToForegroundService.current = undefined;
230
- notifeeLib.default.stopForegroundService();
203
+ keepCallAliveCallRef.current = undefined;
204
+ stopForegroundServiceNoThrow();
231
205
  foregroundServiceStartedRef.current = false;
232
206
  }
233
207
  };