@stream-io/video-react-native-sdk 1.31.1 → 1.32.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 (207) hide show
  1. package/CHANGELOG.md +14 -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,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,45 @@ 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';
15
-
16
- const notifeeLib = getNotifeeLibNoThrowForKeepCallAlive();
17
- const callToPassToForegroundService: { current: Call | undefined } = {
18
- current: undefined,
19
- };
11
+ import { CallingState, videoLoggerSystem } from '@stream-io/video-client';
12
+ import { keepCallAliveCallRef } from '../utils/keepCallAliveHeadlessTask';
13
+ import { getCallingxLibIfAvailable } from '../utils/push/libs';
20
14
 
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
- );
15
+ async function stopForegroundServiceNoThrow() {
16
+ const logger = videoLoggerSystem.getLogger('stopForegroundServiceNoThrow');
17
+ try {
18
+ await NativeModules.StreamVideoReactNative.stopKeepCallAliveService();
19
+ } catch (e) {
20
+ logger.warn('Failed to stop keep-call-alive foreground service', e);
21
+ }
59
22
  }
60
23
 
61
24
  async function startForegroundService(call_cid: string) {
62
- const isCallAliveConfigured =
63
- await NativeModules.StreamVideoReactNative.isCallAliveConfigured();
25
+ const logger = videoLoggerSystem.getLogger('startForegroundService');
26
+ const isCallAliveConfigured = await (async () => {
27
+ try {
28
+ return await NativeModules.StreamVideoReactNative.isCallAliveConfigured();
29
+ } catch (e) {
30
+ logger.warn('Failed to check whether KeepCallAlive is configured', e);
31
+ return false;
32
+ }
33
+ })();
64
34
  if (!isCallAliveConfigured) {
65
- const logger = videoLoggerSystem.getLogger('startForegroundService');
66
35
  logger.info(
67
36
  'KeepCallAlive is not configured. Skipping foreground service setup.',
68
37
  );
69
38
  return;
70
39
  }
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');
40
+ // Check for notification permission (Android 13+) before starting the service.
41
+ const hasPostNotificationsPermission =
42
+ Number(Platform.Version) < 33 ||
43
+ (await PermissionsAndroid.check(
44
+ PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
45
+ ));
46
+ if (!hasPostNotificationsPermission) {
78
47
  logger.info(
79
48
  'Notification permission not granted, can not start foreground service to keep the call alive',
80
49
  );
@@ -83,38 +52,28 @@ async function startForegroundService(call_cid: string) {
83
52
  const videoConfig = StreamVideoRN.getConfig();
84
53
  const foregroundServiceConfig = videoConfig.foregroundService;
85
54
  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();
55
+ const channel = foregroundServiceConfig.android.channel;
56
+ const smallIconName = videoConfig.push?.android.smallIcon;
57
+
91
58
  // NOTE: we use requestAnimationFrame to ensure that the foreground service is started after all the current UI operations are done
92
59
  // this is a workaround for the crash - android.app.RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground()
93
60
  // 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
- });
61
+ requestAnimationFrame(async () => {
62
+ try {
63
+ await NativeModules.StreamVideoReactNative.startKeepCallAliveService(
64
+ call_cid,
65
+ channel.id,
66
+ channel.name,
67
+ notificationTexts.title,
68
+ notificationTexts.body,
69
+ smallIconName ?? null,
70
+ );
71
+ } catch (e) {
72
+ logger.warn('Failed to start keep-call-alive foreground service', e);
73
+ }
112
74
  });
113
75
  }
114
76
 
115
- // flag to check if setForegroundService has already been run once
116
- let isSetForegroundServiceRan = false;
117
-
118
77
  /**
119
78
  * This hook is used to keep the call alive in the background for Android.
120
79
  * It starts a foreground service to keep the call alive as soon as the call is joined
@@ -125,7 +84,7 @@ export const useAndroidKeepCallAliveEffect = () => {
125
84
  const foregroundServiceStartedRef = useRef(false);
126
85
 
127
86
  const call = useCall();
128
- callToPassToForegroundService.current = call;
87
+ keepCallAliveCallRef.current = call;
129
88
  const activeCallCid = call?.cid;
130
89
  const { useCallCallingState } = useCallStateHooks();
131
90
  const callingState = useCallCallingState();
@@ -133,6 +92,7 @@ export const useAndroidKeepCallAliveEffect = () => {
133
92
  const isOutgoingCall =
134
93
  callingState === CallingState.RINGING && call?.isCreatedByMe;
135
94
  const isCallJoined = callingState === CallingState.JOINED;
95
+ const isRingingCall = call?.ringing;
136
96
 
137
97
  const shouldStartForegroundService =
138
98
  !foregroundServiceStartedRef.current && (isOutgoingCall || isCallJoined);
@@ -141,7 +101,14 @@ export const useAndroidKeepCallAliveEffect = () => {
141
101
  if (Platform.OS === 'ios' || !activeCallCid) {
142
102
  return undefined;
143
103
  }
144
- if (!notifeeLib) return undefined;
104
+
105
+ const callingx = getCallingxLibIfAvailable();
106
+ if (
107
+ callingx?.isSetup &&
108
+ (isRingingCall || (!isRingingCall && callingx?.isOngoingCallsEnabled))
109
+ ) {
110
+ return undefined;
111
+ }
145
112
 
146
113
  // start foreground service as soon as the call is joined
147
114
  if (shouldStartForegroundService) {
@@ -149,23 +116,6 @@ export const useAndroidKeepCallAliveEffect = () => {
149
116
  if (foregroundServiceStartedRef.current) {
150
117
  return;
151
118
  }
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);
167
- }
168
- // check for notification permission and then start the foreground service
169
119
 
170
120
  await startForegroundService(activeCallCid);
171
121
  foregroundServiceStartedRef.current = true;
@@ -174,7 +124,6 @@ export const useAndroidKeepCallAliveEffect = () => {
174
124
  // ensure that app is active before running the function
175
125
  if (AppState.currentState === 'active') {
176
126
  run();
177
- return undefined;
178
127
  }
179
128
  const sub = AppState.addEventListener(
180
129
  'change',
@@ -188,46 +137,31 @@ export const useAndroidKeepCallAliveEffect = () => {
188
137
  return () => {
189
138
  sub.remove();
190
139
  };
191
- } else if (callingState === CallingState.RINGING) {
192
- return () => {
193
- // cancel any notifee displayed notification when the call has transitioned out of ringing
194
- // NOTE: cancels only the non fg service notifications
195
- notifeeLib.default.cancelDisplayedNotification(activeCallCid);
196
- };
197
140
  } else if (
198
141
  callingState === CallingState.IDLE ||
199
142
  callingState === CallingState.LEFT
200
143
  ) {
201
144
  if (foregroundServiceStartedRef.current) {
202
- callToPassToForegroundService.current = undefined;
145
+ keepCallAliveCallRef.current = undefined;
203
146
  // stop foreground service when the call is not active
204
- notifeeLib.default.stopForegroundService();
147
+ stopForegroundServiceNoThrow();
205
148
  foregroundServiceStartedRef.current = false;
206
- } 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
- });
219
149
  }
220
150
  }
221
151
  return undefined;
222
- }, [activeCallCid, callingState, shouldStartForegroundService]);
152
+ }, [
153
+ activeCallCid,
154
+ callingState,
155
+ shouldStartForegroundService,
156
+ isRingingCall,
157
+ ]);
223
158
 
224
159
  useEffect(() => {
225
160
  return () => {
226
161
  // stop foreground service when this effect is unmounted
227
162
  if (foregroundServiceStartedRef.current) {
228
- if (!notifeeLib) return;
229
- callToPassToForegroundService.current = undefined;
230
- notifeeLib.default.stopForegroundService();
163
+ keepCallAliveCallRef.current = undefined;
164
+ stopForegroundServiceNoThrow();
231
165
  foregroundServiceStartedRef.current = false;
232
166
  }
233
167
  };
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@ import { registerGlobals } from '@stream-io/react-native-webrtc';
9
9
  import Logger from '@stream-io/react-native-webrtc/src/Logger';
10
10
  import { Platform } from 'react-native';
11
11
  import { registerSDKGlobals } from './utils/internal/registerSDKGlobals';
12
+ import './utils/keepCallAliveHeadlessTask';
12
13
 
13
14
  // We're registering globals, because our video JS client is serving SDKs that use browser based webRTC functions.
14
15
  // This will result in creation of 2 global objects: `window` and `navigator`
@@ -1,7 +1,10 @@
1
1
  import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
2
2
  import { AudioDeviceStatus, StreamInCallManagerConfig } from './types';
3
+ import { getCallingxLibIfAvailable } from '../../utils/push/libs/callingx';
4
+ import { videoLoggerSystem } from '@stream-io/video-client';
3
5
 
4
6
  const NativeManager = NativeModules.StreamInCallManager;
7
+ const CallingxModule = getCallingxLibIfAvailable();
5
8
 
6
9
  const invariant = (condition: boolean, message: string) => {
7
10
  if (!condition) throw new Error(message);
@@ -72,6 +75,19 @@ class SpeakerManager {
72
75
  };
73
76
  }
74
77
 
78
+ const shouldBypassForCallKit = (): boolean => {
79
+ if (Platform.OS !== 'ios') {
80
+ return false;
81
+ }
82
+ if (!CallingxModule) {
83
+ return false;
84
+ }
85
+ return (
86
+ CallingxModule.isSetup &&
87
+ (CallingxModule.hasRegisteredCall() || CallingxModule.isOngoingCallsEnabled)
88
+ );
89
+ };
90
+
75
91
  export class CallManager {
76
92
  android = new AndroidCallManager();
77
93
  ios = new IOSCallManager();
@@ -95,6 +111,14 @@ export class CallManager {
95
111
  * @param config.enableStereoAudioOutput Whether to enable stereo audio output. Only supported for listener audio role.
96
112
  */
97
113
  start = (config?: StreamInCallManagerConfig): void => {
114
+ if (shouldBypassForCallKit()) {
115
+ videoLoggerSystem
116
+ .getLogger('CallManager')
117
+ .debug(
118
+ 'start: skipping start as callkit is handling the audio session',
119
+ );
120
+ return;
121
+ }
98
122
  NativeManager.setAudioRole(config?.audioRole ?? 'communicator');
99
123
  if (config?.audioRole === 'communicator') {
100
124
  const type = config.deviceEndpointType ?? 'speaker';
@@ -110,6 +134,12 @@ export class CallManager {
110
134
  * Stops the in call manager.
111
135
  */
112
136
  stop = (): void => {
137
+ if (shouldBypassForCallKit()) {
138
+ videoLoggerSystem
139
+ .getLogger('CallManager')
140
+ .debug('stop: skipping stop as callkit is handling the audio session');
141
+ return;
142
+ }
113
143
  NativeManager.stop();
114
144
  };
115
145
 
@@ -118,4 +148,10 @@ export class CallManager {
118
148
  * in the native layer.
119
149
  */
120
150
  logAudioState = (): void => NativeManager.logAudioState();
151
+
152
+ /**
153
+ * For debugging purposes, returns the current audio state as a string.
154
+ * @returns A string containing the current audio state information.
155
+ */
156
+ getAudioStateLog = (): string => NativeManager.getAudioStateLog();
121
157
  }
@@ -82,6 +82,13 @@ export interface CallManager extends NativeModule {
82
82
  * Meant for debugging purposes.
83
83
  */
84
84
  logAudioState: () => void;
85
+
86
+ /**
87
+ * Get the current audio state as a string.
88
+ * Meant for debugging purposes.
89
+ * @returns A string containing the current audio state information.
90
+ */
91
+ getAudioStateLog: () => string;
85
92
  }
86
93
 
87
94
  declare module 'react-native' {
@@ -1,13 +1,13 @@
1
1
  import { StreamCallProvider } from '@stream-io/video-react-bindings';
2
2
  import React, { type PropsWithChildren, useEffect } from 'react';
3
3
  import { Call } from '@stream-io/video-client';
4
- import { useIosCallkeepWithCallingStateEffect } from '../../hooks/push/useIosCallkeepWithCallingStateEffect';
5
4
  import { canAddPushWSSubscriptionsRef } from '../../utils/push/internal/utils';
6
5
  import { useAndroidKeepCallAliveEffect } from '../../hooks/useAndroidKeepCallAliveEffect';
7
6
  import { useScreenShareAudioMixing } from '../../hooks/useScreenShareAudioMixing';
8
7
  import { AppStateListener } from './AppStateListener';
9
8
  import { DeviceStats } from './DeviceStats';
10
9
  import { pushUnsubscriptionCallbacks } from '../../utils/push/internal/constants';
10
+ import { useCallingExpWithCallingStateEffect } from '../../hooks/push/useCallingExpWithCallingStateEffect';
11
11
 
12
12
  // const PIP_CHANGE_EVENT = 'StreamVideoReactNative_PIP_CHANGE_EVENT';
13
13
 
@@ -35,7 +35,7 @@ export const StreamCall = ({
35
35
  <StreamCallProvider call={call}>
36
36
  <AppStateListener />
37
37
  <AndroidKeepCallAlive />
38
- <IosInformCallkeepCallEnd />
38
+ <CallingExpWithCallingState />
39
39
  <ClearPushWSSubscriptions />
40
40
  <ScreenShareAudioMixer />
41
41
  <DeviceStats />
@@ -54,11 +54,11 @@ const AndroidKeepCallAlive = () => {
54
54
  };
55
55
 
56
56
  /**
57
- * This is a renderless component to end the call in callkeep for ios.
58
- * useAndroidKeepCallAliveEffect needs to called inside a child of StreamCallProvider.
57
+ * This is a renderless component to sync state between stream call and CallKit/Telecom.
58
+ * useCallingExpWithCallingStateEffect needs to called inside a child of StreamCallProvider.
59
59
  */
60
- const IosInformCallkeepCallEnd = () => {
61
- useIosCallkeepWithCallingStateEffect();
60
+ const CallingExpWithCallingState = () => {
61
+ useCallingExpWithCallingStateEffect();
62
62
  return null;
63
63
  };
64
64
 
@@ -3,9 +3,14 @@ import pushLogoutCallbacks from '../internal/pushLogoutCallback';
3
3
  import newNotificationCallbacks, {
4
4
  type NewCallNotificationCallback,
5
5
  } from '../internal/newNotificationCallbacks';
6
- import { setupIosCallKeepEvents } from '../push/setupIosCallKeepEvents';
7
6
  import { setupIosVoipPushEvents } from '../push/setupIosVoipPushEvents';
7
+ import { setupCallingExpEvents } from '../push/setupCallingExpEvents';
8
+ import {
9
+ extractCallingExpOptions,
10
+ getCallingxLib,
11
+ } from '../push/libs/callingx';
8
12
  import { NativeModules, Platform } from 'react-native';
13
+ import { videoLoggerSystem } from '@stream-io/video-client';
9
14
 
10
15
  // Utility type for deep partial
11
16
  type DeepPartial<T> = {
@@ -47,10 +52,7 @@ const DEFAULT_STREAM_VIDEO_CONFIG: StreamVideoConfig = {
47
52
  android: {
48
53
  channel: {
49
54
  id: 'stream_call_foreground_service',
50
- name: 'To keep calls alive',
51
- lights: false,
52
- vibration: false,
53
- importance: 3,
55
+ name: 'Ongoing calls',
54
56
  },
55
57
  notificationTexts: {
56
58
  title: 'Call in progress',
@@ -76,20 +78,6 @@ export class StreamVideoRN {
76
78
  this.config = deepMerge(this.config, updateConfig);
77
79
  }
78
80
 
79
- static updateAndroidIncomingCallChannel(
80
- updateChannel: Partial<
81
- NonNullable<StreamVideoConfig['push']>['android']['incomingCallChannel']
82
- >,
83
- ) {
84
- const prevChannel = this.config.push?.android?.incomingCallChannel;
85
- if (prevChannel) {
86
- this.config.push!.android.incomingCallChannel = {
87
- ...prevChannel,
88
- ...updateChannel,
89
- };
90
- }
91
- }
92
-
93
81
  /**
94
82
  * Set the push config for StreamVideoRN.
95
83
  * This method must be called **outside** of your application lifecycle, e.g. alongside your
@@ -102,7 +90,28 @@ export class StreamVideoRN {
102
90
  * import App from './App';
103
91
  * // Set push config
104
92
  * const pushConfig = {}; // construct your config
105
- * StreamVideoRN.setPushConfig(pushConfig);
93
+ * // Set CallKit/Android Telecom API integration options. All params are optional. If not provided, the default values will be used.
94
+ * const callingExpOptions = {
95
+ * ios: {
96
+ * callsHistory: true,
97
+ * displayCallTimeout: 60000,
98
+ * sound: 'ringtone',
99
+ * imageName: 'callkit_icon',
100
+ * },
101
+ * android: {
102
+ * incomingChannel: {
103
+ * id: 'stream_incoming_call_notifications',
104
+ * name: 'Call notifications',
105
+ * vibration: true,
106
+ * sound: 'default',
107
+ * },
108
+ * titleTransformer: (memberName: string, incoming: boolean) =>
109
+ * incoming
110
+ * ? `${memberName} is calling you`
111
+ * : `You are calling ${memberName}`,
112
+ * },
113
+ * };
114
+ * StreamVideoRN.setPushConfig(pushConfig, callingExpOptions);
106
115
  * AppRegistry.registerComponent('app', () => App);
107
116
  */
108
117
  static setPushConfig(pushConfig: NonNullable<StreamVideoConfig['push']>) {
@@ -110,20 +119,23 @@ export class StreamVideoRN {
110
119
  // Ignoring this config as push config was already set
111
120
  return;
112
121
  }
113
- if (
114
- __DEV__ &&
115
- (pushConfig.navigateAcceptCall || pushConfig.navigateToIncomingCall)
116
- ) {
122
+
123
+ this.config.push = pushConfig;
124
+
125
+ try {
126
+ const callingx = getCallingxLib();
127
+ videoLoggerSystem
128
+ .getLogger('StreamVideoRN.setPushConfig')
129
+ .info(JSON.stringify(this.config));
130
+ const options = extractCallingExpOptions(this.config);
131
+ callingx.setup(options);
132
+ } catch {
117
133
  throw new Error(
118
- `Support for navigateAcceptCall or navigateToIncomingCall in pushConfig has been removed.
119
- Please watch for incoming and outgoing calls in the root component of your app.
120
- Please see https://getstream.io/video/docs/react-native/advanced/ringing-calls/#watch-for-incoming-and-outgoing-calls for more information.`,
134
+ 'react-native-callingx library is not installed. Please check our migration instructions: https://getstream.io/video/docs/react-native/migration-guides/1.32.0/.',
121
135
  );
122
136
  }
123
137
 
124
- this.config.push = pushConfig;
125
-
126
- setupIosCallKeepEvents(pushConfig);
138
+ setupCallingExpEvents(pushConfig);
127
139
  setupIosVoipPushEvents(pushConfig);
128
140
  }
129
141