@stream-io/video-react-native-sdk 1.29.3 → 1.29.4-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 (209) hide show
  1. package/android/src/main/AndroidManifest.xml +8 -1
  2. package/android/src/main/AndroidManifestNew.xml +11 -0
  3. package/android/src/main/java/com/streamvideo/reactnative/StreamVideoReactNativeModule.kt +42 -5
  4. package/android/src/main/java/com/streamvideo/reactnative/audio/utils/WebRtcAudioUtils.kt +70 -6
  5. package/android/src/main/java/com/streamvideo/reactnative/callmanager/StreamInCallManagerModule.kt +6 -4
  6. package/android/src/main/java/com/streamvideo/reactnative/keepalive/KeepAliveNotification.kt +83 -0
  7. package/android/src/main/java/com/streamvideo/reactnative/keepalive/StreamCallKeepAliveHeadlessService.kt +149 -0
  8. package/dist/commonjs/hooks/push/index.js +0 -2
  9. package/dist/commonjs/hooks/push/index.js.map +1 -1
  10. package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js +121 -0
  11. package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js.map +1 -0
  12. package/dist/commonjs/hooks/push/useIosVoipPushEventsSetupEffect.js +18 -31
  13. package/dist/commonjs/hooks/push/useIosVoipPushEventsSetupEffect.js.map +1 -1
  14. package/dist/commonjs/hooks/useAndroidKeepCallAliveEffect.js +64 -97
  15. package/dist/commonjs/hooks/useAndroidKeepCallAliveEffect.js.map +1 -1
  16. package/dist/commonjs/index.js +1 -0
  17. package/dist/commonjs/index.js.map +1 -1
  18. package/dist/commonjs/modules/call-manager/CallManager.js +26 -0
  19. package/dist/commonjs/modules/call-manager/CallManager.js.map +1 -1
  20. package/dist/commonjs/providers/StreamCall/index.js +6 -6
  21. package/dist/commonjs/providers/StreamCall/index.js.map +1 -1
  22. package/dist/commonjs/utils/StreamVideoRN/index.js +33 -21
  23. package/dist/commonjs/utils/StreamVideoRN/index.js.map +1 -1
  24. package/dist/commonjs/utils/internal/callingx/audioSessionPromise.js +58 -0
  25. package/dist/commonjs/utils/internal/callingx/audioSessionPromise.js.map +1 -0
  26. package/dist/commonjs/utils/internal/callingx/callingx.js +109 -0
  27. package/dist/commonjs/utils/internal/callingx/callingx.js.map +1 -0
  28. package/dist/commonjs/utils/internal/registerSDKGlobals.js +52 -3
  29. package/dist/commonjs/utils/internal/registerSDKGlobals.js.map +1 -1
  30. package/dist/commonjs/utils/keepCallAliveHeadlessTask.js +48 -0
  31. package/dist/commonjs/utils/keepCallAliveHeadlessTask.js.map +1 -0
  32. package/dist/commonjs/utils/push/android.js +151 -202
  33. package/dist/commonjs/utils/push/android.js.map +1 -1
  34. package/dist/commonjs/utils/push/internal/ios.js +17 -34
  35. package/dist/commonjs/utils/push/internal/ios.js.map +1 -1
  36. package/dist/commonjs/utils/push/internal/rxSubjects.js +1 -45
  37. package/dist/commonjs/utils/push/internal/rxSubjects.js.map +1 -1
  38. package/dist/commonjs/utils/push/internal/utils.js +32 -20
  39. package/dist/commonjs/utils/push/internal/utils.js.map +1 -1
  40. package/dist/commonjs/utils/push/ios.js.map +1 -1
  41. package/dist/commonjs/utils/push/libs/callingx.js +75 -0
  42. package/dist/commonjs/utils/push/libs/callingx.js.map +1 -0
  43. package/dist/commonjs/utils/push/libs/index.js +8 -19
  44. package/dist/commonjs/utils/push/libs/index.js.map +1 -1
  45. package/dist/commonjs/utils/push/libs/notifee/index.js +0 -19
  46. package/dist/commonjs/utils/push/libs/notifee/index.js.map +1 -1
  47. package/dist/commonjs/utils/push/setupCallingExpEvents.js +108 -0
  48. package/dist/commonjs/utils/push/setupCallingExpEvents.js.map +1 -0
  49. package/dist/commonjs/utils/push/setupIosVoipPushEvents.js +7 -6
  50. package/dist/commonjs/utils/push/setupIosVoipPushEvents.js.map +1 -1
  51. package/dist/commonjs/version.js +1 -1
  52. package/dist/commonjs/version.js.map +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 +114 -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 +66 -99
  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 +33 -21
  68. package/dist/module/utils/StreamVideoRN/index.js.map +1 -1
  69. package/dist/module/utils/internal/callingx/audioSessionPromise.js +51 -0
  70. package/dist/module/utils/internal/callingx/audioSessionPromise.js.map +1 -0
  71. package/dist/module/utils/internal/callingx/callingx.js +100 -0
  72. package/dist/module/utils/internal/callingx/callingx.js.map +1 -0
  73. package/dist/module/utils/internal/registerSDKGlobals.js +52 -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 +153 -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 +29 -19
  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 -18
  91. package/dist/module/utils/push/libs/notifee/index.js.map +1 -1
  92. package/dist/module/utils/push/setupCallingExpEvents.js +102 -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/module/version.js.map +1 -1
  98. package/dist/typescript/hooks/push/index.d.ts.map +1 -1
  99. package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts +5 -0
  100. package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts.map +1 -0
  101. package/dist/typescript/hooks/push/useIosVoipPushEventsSetupEffect.d.ts.map +1 -1
  102. package/dist/typescript/hooks/useAndroidKeepCallAliveEffect.d.ts.map +1 -1
  103. package/dist/typescript/index.d.ts +1 -0
  104. package/dist/typescript/index.d.ts.map +1 -1
  105. package/dist/typescript/modules/call-manager/CallManager.d.ts +5 -0
  106. package/dist/typescript/modules/call-manager/CallManager.d.ts.map +1 -1
  107. package/dist/typescript/utils/StreamVideoRN/index.d.ts +20 -2
  108. package/dist/typescript/utils/StreamVideoRN/index.d.ts.map +1 -1
  109. package/dist/typescript/utils/StreamVideoRN/types.d.ts +54 -29
  110. package/dist/typescript/utils/StreamVideoRN/types.d.ts.map +1 -1
  111. package/dist/typescript/utils/internal/callingx/audioSessionPromise.d.ts +16 -0
  112. package/dist/typescript/utils/internal/callingx/audioSessionPromise.d.ts.map +1 -0
  113. package/dist/typescript/utils/internal/callingx/callingx.d.ts +14 -0
  114. package/dist/typescript/utils/internal/callingx/callingx.d.ts.map +1 -0
  115. package/dist/typescript/utils/internal/registerSDKGlobals.d.ts.map +1 -1
  116. package/dist/typescript/utils/keepCallAliveHeadlessTask.d.ts +10 -0
  117. package/dist/typescript/utils/keepCallAliveHeadlessTask.d.ts.map +1 -0
  118. package/dist/typescript/utils/push/android.d.ts +1 -2
  119. package/dist/typescript/utils/push/android.d.ts.map +1 -1
  120. package/dist/typescript/utils/push/internal/ios.d.ts.map +1 -1
  121. package/dist/typescript/utils/push/internal/rxSubjects.d.ts +0 -33
  122. package/dist/typescript/utils/push/internal/rxSubjects.d.ts.map +1 -1
  123. package/dist/typescript/utils/push/internal/utils.d.ts +8 -1
  124. package/dist/typescript/utils/push/internal/utils.d.ts.map +1 -1
  125. package/dist/typescript/utils/push/ios.d.ts +1 -2
  126. package/dist/typescript/utils/push/ios.d.ts.map +1 -1
  127. package/dist/typescript/utils/push/libs/callingx.d.ts +9 -0
  128. package/dist/typescript/utils/push/libs/callingx.d.ts.map +1 -0
  129. package/dist/typescript/utils/push/libs/index.d.ts +1 -2
  130. package/dist/typescript/utils/push/libs/index.d.ts.map +1 -1
  131. package/dist/typescript/utils/push/libs/notifee/index.d.ts +0 -1
  132. package/dist/typescript/utils/push/libs/notifee/index.d.ts.map +1 -1
  133. package/dist/typescript/utils/push/setupCallingExpEvents.d.ts +8 -0
  134. package/dist/typescript/utils/push/setupCallingExpEvents.d.ts.map +1 -0
  135. package/dist/typescript/utils/push/setupIosVoipPushEvents.d.ts.map +1 -1
  136. package/dist/typescript/version.d.ts +1 -1
  137. package/dist/typescript/version.d.ts.map +1 -1
  138. package/expo-config-plugin/dist/withAndroidManifest.js +1 -33
  139. package/expo-config-plugin/dist/withAndroidPermissions.js +2 -7
  140. package/expo-config-plugin/dist/withAppDelegate.js +19 -197
  141. package/expo-config-plugin/dist/withMainActivity.js +1 -1
  142. package/expo-config-plugin/dist/withiOSInfoPlist.js +2 -3
  143. package/ios/StreamInCallManager.m +2 -0
  144. package/ios/StreamInCallManager.swift +19 -7
  145. package/ios/StreamVideoReactNative.h +7 -4
  146. package/ios/StreamVideoReactNative.m +189 -82
  147. package/package.json +13 -18
  148. package/src/hooks/push/index.ts +0 -2
  149. package/src/hooks/push/useCallingExpWithCallingStateEffect.ts +147 -0
  150. package/src/hooks/push/useIosVoipPushEventsSetupEffect.ts +21 -34
  151. package/src/hooks/useAndroidKeepCallAliveEffect.ts +94 -120
  152. package/src/index.ts +1 -0
  153. package/src/modules/call-manager/CallManager.ts +36 -0
  154. package/src/modules/call-manager/native-module.d.ts +7 -0
  155. package/src/providers/StreamCall/index.tsx +6 -6
  156. package/src/utils/StreamVideoRN/index.ts +40 -30
  157. package/src/utils/StreamVideoRN/types.ts +56 -29
  158. package/src/utils/internal/callingx/audioSessionPromise.ts +53 -0
  159. package/src/utils/internal/callingx/callingx.ts +146 -0
  160. package/src/utils/internal/registerSDKGlobals.ts +47 -4
  161. package/src/utils/keepCallAliveHeadlessTask.ts +54 -0
  162. package/src/utils/push/android.ts +227 -309
  163. package/src/utils/push/internal/ios.ts +28 -44
  164. package/src/utils/push/internal/rxSubjects.ts +0 -61
  165. package/src/utils/push/internal/utils.ts +45 -26
  166. package/src/utils/push/ios.ts +1 -6
  167. package/src/utils/push/libs/callingx.ts +90 -0
  168. package/src/utils/push/libs/index.ts +1 -2
  169. package/src/utils/push/libs/notifee/index.ts +0 -27
  170. package/src/utils/push/setupCallingExpEvents.ts +130 -0
  171. package/src/utils/push/setupIosVoipPushEvents.ts +11 -7
  172. package/src/version.ts +1 -1
  173. package/CHANGELOG.md +0 -3144
  174. package/android/src/main/java/com/streamvideo/reactnative/util/CallAliveServiceChecker.kt +0 -95
  175. package/dist/commonjs/hooks/push/useIosCallkeepWithCallingStateEffect.js +0 -160
  176. package/dist/commonjs/hooks/push/useIosCallkeepWithCallingStateEffect.js.map +0 -1
  177. package/dist/commonjs/hooks/push/useProcessPushCallEffect.js +0 -67
  178. package/dist/commonjs/hooks/push/useProcessPushCallEffect.js.map +0 -1
  179. package/dist/commonjs/utils/push/libs/callkeep.js +0 -17
  180. package/dist/commonjs/utils/push/libs/callkeep.js.map +0 -1
  181. package/dist/commonjs/utils/push/libs/voipPushNotification.js +0 -17
  182. package/dist/commonjs/utils/push/libs/voipPushNotification.js.map +0 -1
  183. package/dist/commonjs/utils/push/setupIosCallKeepEvents.js +0 -205
  184. package/dist/commonjs/utils/push/setupIosCallKeepEvents.js.map +0 -1
  185. package/dist/module/hooks/push/useIosCallkeepWithCallingStateEffect.js +0 -153
  186. package/dist/module/hooks/push/useIosCallkeepWithCallingStateEffect.js.map +0 -1
  187. package/dist/module/hooks/push/useProcessPushCallEffect.js +0 -60
  188. package/dist/module/hooks/push/useProcessPushCallEffect.js.map +0 -1
  189. package/dist/module/utils/push/libs/callkeep.js +0 -11
  190. package/dist/module/utils/push/libs/callkeep.js.map +0 -1
  191. package/dist/module/utils/push/libs/voipPushNotification.js +0 -11
  192. package/dist/module/utils/push/libs/voipPushNotification.js.map +0 -1
  193. package/dist/module/utils/push/setupIosCallKeepEvents.js +0 -199
  194. package/dist/module/utils/push/setupIosCallKeepEvents.js.map +0 -1
  195. package/dist/typescript/hooks/push/useIosCallkeepWithCallingStateEffect.d.ts +0 -5
  196. package/dist/typescript/hooks/push/useIosCallkeepWithCallingStateEffect.d.ts.map +0 -1
  197. package/dist/typescript/hooks/push/useProcessPushCallEffect.d.ts +0 -8
  198. package/dist/typescript/hooks/push/useProcessPushCallEffect.d.ts.map +0 -1
  199. package/dist/typescript/utils/push/libs/callkeep.d.ts +0 -3
  200. package/dist/typescript/utils/push/libs/callkeep.d.ts.map +0 -1
  201. package/dist/typescript/utils/push/libs/voipPushNotification.d.ts +0 -3
  202. package/dist/typescript/utils/push/libs/voipPushNotification.d.ts.map +0 -1
  203. package/dist/typescript/utils/push/setupIosCallKeepEvents.d.ts +0 -6
  204. package/dist/typescript/utils/push/setupIosCallKeepEvents.d.ts.map +0 -1
  205. package/src/hooks/push/useIosCallkeepWithCallingStateEffect.ts +0 -235
  206. package/src/hooks/push/useProcessPushCallEffect.ts +0 -108
  207. package/src/utils/push/libs/callkeep.ts +0 -16
  208. package/src/utils/push/libs/voipPushNotification.ts +0 -17
  209. package/src/utils/push/setupIosCallKeepEvents.ts +0 -252
@@ -5,6 +5,18 @@ import {
5
5
  } from '@stream-io/video-client';
6
6
  import type { AndroidChannel } from '@notifee/react-native';
7
7
 
8
+ export type AndroidChannelConfig = {
9
+ id: string;
10
+ name: string;
11
+ sound?: string;
12
+ vibration?: boolean;
13
+ };
14
+
15
+ export type KeepAliveAndroidNotificationTexts = {
16
+ title: string;
17
+ body: string;
18
+ };
19
+
8
20
  export type NonRingingPushEvent =
9
21
  | 'call.live_started'
10
22
  | 'call.notification'
@@ -32,6 +44,27 @@ export type StreamVideoConfig = {
32
44
  * @example "production-apn-video" or "staging-apn-video" based on the environment
33
45
  */
34
46
  pushProviderName?: string;
47
+ supportsVideo?: boolean;
48
+ /**
49
+ * Sound to play when an incoming call is received. Must be a valid sound resource name in the project.
50
+ * @default '' (no sound)
51
+ */
52
+ sound?: string;
53
+ /**
54
+ * Image to display when an incoming call is received. Must be a valid image resource name in the project.
55
+ * @default '' (no image)
56
+ */
57
+ imageName?: string;
58
+ /**
59
+ * Enable calls history. When enabled, the call will be added to the calls history.
60
+ * @default false
61
+ */
62
+ callsHistory?: boolean;
63
+ /**
64
+ * Timeout to display an incoming call. When the call is displayed for more than the timeout, the call will be rejected.
65
+ * @default 60000 (1 minute)
66
+ */
67
+ displayCallTimeout?: number;
35
68
  };
36
69
  android: {
37
70
  /**
@@ -61,28 +94,21 @@ export type StreamVideoConfig = {
61
94
  * The notification channel to be used for incoming calls for Android.
62
95
  * @example
63
96
  * {
64
- * id: 'stream_incoming_call',
65
- * name: 'Incoming call notifications',
66
- * importance: AndroidImportance.HIGH,
97
+ * id: 'incoming_calls_channel',
98
+ * name: 'Incoming calls',
99
+ * sound?: string;
100
+ * vibration?: boolean;
67
101
  * }
68
102
  */
69
- incomingCallChannel?: AndroidChannel;
103
+ incomingChannel?: AndroidChannelConfig;
70
104
  /**
71
- * Functions to create the texts shown in the notification for incoming calls in Android.
72
- * @example
73
- * {
74
- * getTitle: (createdUserName: string) => `Incoming call from ${createdUserName}`,
75
- * getBody: (createdUserName: string) => `Tap to answer the call`
76
- * getAcceptButtonTitle?: () => `Accept`,
77
- * getDeclineButtonTitle?: () => `Decline`,
78
- * }
105
+ * The transformer to be used to transform the call title in the notification for ringing and ongoing calls for Android.
79
106
  */
80
- incomingCallNotificationTextGetters?: {
81
- getTitle: (createdUserName: string) => string;
82
- getBody: (createdUserName: string) => string;
83
- getAcceptButtonTitle?: () => string;
84
- getDeclineButtonTitle?: () => string;
85
- };
107
+ titleTransformer?: (memberName: string, incoming: boolean) => string;
108
+ /**
109
+ * The transformer to be used to transform the call subtitle for ringing and ongoing calls for Android.
110
+ */
111
+ subtitleTransformer?: (call_cid: string, incoming: boolean) => string;
86
112
  /**
87
113
  * Functions to create the texts shown in the notification for non ringing calls in Android.
88
114
  * @example
@@ -111,6 +137,16 @@ export type StreamVideoConfig = {
111
137
  getBody: (type: NonRingingPushEvent, createdUserName: string) => string;
112
138
  };
113
139
  };
140
+ /**
141
+ * Whether to enable ongoing calls.
142
+ * @default false
143
+ */
144
+ enableOngoingCalls?: boolean;
145
+ /**
146
+ * Whether to reject calls when the user is busy.
147
+ * @default false
148
+ */
149
+ shouldRejectCallWhenBusy?: boolean;
114
150
  /**
115
151
  * This function is used to create a custom video client.
116
152
  * This is used create a video client for incoming calls in the background and inform call events to the server.
@@ -130,12 +166,6 @@ export type StreamVideoConfig = {
130
166
  * }
131
167
  */
132
168
  createStreamVideoClient: () => Promise<StreamVideoClient | undefined>;
133
- /** @deprecated This method will be removed in the future. Please watch for incoming and outgoing calls in the root component of your app.
134
- Please see https://getstream.io/video/docs/react-native/advanced/ringing-calls/#watch-for-incoming-and-outgoing-calls for more information */
135
- navigateAcceptCall?: () => void;
136
- /** @deprecated This method will be removed in the future. Please watch for incoming and outgoing calls in the root component of your app.
137
- Please see https://getstream.io/video/docs/react-native/advanced/ringing-calls/#watch-for-incoming-and-outgoing-calls for more information */
138
- navigateToIncomingCall?: () => void;
139
169
  /** Callback that is called when a non ringing push notification was tapped */
140
170
  onTapNonRingingCallNotification?: (
141
171
  call_cid: string,
@@ -147,14 +177,11 @@ export type StreamVideoConfig = {
147
177
  /**
148
178
  * The notification channel to keep call alive in the background for Android using a foreground service.
149
179
  */
150
- channel: AndroidChannel;
180
+ channel: Omit<AndroidChannelConfig, 'sound' | 'vibration'>;
151
181
  /**
152
182
  * The texts shown in the notification to keep call alive in the background
153
183
  */
154
- notificationTexts: {
155
- title: string;
156
- body: string;
157
- };
184
+ notificationTexts: KeepAliveAndroidNotificationTexts;
158
185
  /**
159
186
  * The task to run in the foreground service
160
187
  * The task must resolve a promise once complete
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Module to manage pending promise for audio session activation.
3
+ * Used to wait for iOS CallKit's didActivateAudioSession event after starting a call.
4
+ */
5
+
6
+ let pendingResolve: (() => void) | null = null;
7
+ let pendingTimeout: ReturnType<typeof setTimeout> | null = null;
8
+ /**
9
+ * Flag to check if the audio session is already activated.
10
+ * This solves race condition for a cold start case, when the audio session is activated before the promise is created.
11
+ */
12
+ let isAudioSessionAlreadyActivated = false;
13
+
14
+ const AUDIO_SESSION_TIMEOUT_MS = 5000;
15
+
16
+ /**
17
+ * Creates a promise that resolves when the audio session is activated,
18
+ * or after a timeout to prevent hanging indefinitely.
19
+ * @returns Promise that resolves when audio session is activated or timeout occurs
20
+ */
21
+ export function waitForAudioSessionActivation(): Promise<void> {
22
+ if (isAudioSessionAlreadyActivated) {
23
+ isAudioSessionAlreadyActivated = false;
24
+ return Promise.resolve();
25
+ }
26
+
27
+ return new Promise((resolve) => {
28
+ pendingResolve = resolve;
29
+ pendingTimeout = setTimeout(() => {
30
+ // Resolve on timeout to prevent hanging
31
+ resolvePendingAudioSession();
32
+ }, AUDIO_SESSION_TIMEOUT_MS);
33
+ });
34
+ }
35
+
36
+ /**
37
+ * Resolves the pending audio session activation promise.
38
+ * Called when the didActivateAudioSession event fires or on timeout.
39
+ */
40
+ export function resolvePendingAudioSession(): void {
41
+ if (pendingTimeout) {
42
+ clearTimeout(pendingTimeout);
43
+ pendingTimeout = null;
44
+ }
45
+
46
+ if (pendingResolve) {
47
+ pendingResolve();
48
+ pendingResolve = null;
49
+ isAudioSessionAlreadyActivated = false;
50
+ } else {
51
+ isAudioSessionAlreadyActivated = true;
52
+ }
53
+ }
@@ -0,0 +1,146 @@
1
+ /***
2
+ * Internal utils for callingx library usage from video-client.
3
+ * See @./registerSDKGlobals.ts for more usage details.
4
+ */
5
+ import { Platform } from 'react-native';
6
+ import type { EndCallReason } from '@stream-io/react-native-callingx';
7
+ import { getCallingxLibIfAvailable } from '../../push/libs/callingx';
8
+ import { waitForAudioSessionActivation } from './audioSessionPromise';
9
+ import type {
10
+ Call,
11
+ MemberResponse,
12
+ StreamVideoParticipant,
13
+ } from '@stream-io/video-client';
14
+ import { videoLoggerSystem } from '@stream-io/video-client';
15
+ const CallingxModule = getCallingxLibIfAvailable();
16
+
17
+ /**
18
+ * Gets the call display name. To be used for display in native call screen.
19
+ */
20
+ export function getCallDisplayName(
21
+ callMembers: MemberResponse[] | undefined,
22
+ participants: StreamVideoParticipant[] | undefined,
23
+ currentUserId: string | undefined,
24
+ ) {
25
+ if (!callMembers || !participants || !currentUserId) {
26
+ return 'Call';
27
+ }
28
+
29
+ let names: string[] = [];
30
+
31
+ if (callMembers.length > 0) {
32
+ // for ringing calls, members array contains all call members from the very early state and participants array is empty in the beginning
33
+ names = callMembers
34
+ .filter((member) => member.user.id !== currentUserId)
35
+ .map((member) => member.user.name)
36
+ .filter((name): name is string => name !== undefined);
37
+ } else if (participants.length > 0) {
38
+ // for non-ringing calls, members array is empty and we rely on participants array there
39
+ names = participants
40
+ .filter((participant) => participant.userId !== currentUserId)
41
+ .map((participant) => participant.name)
42
+ .filter(Boolean);
43
+ }
44
+
45
+ // if no names are found, we use the name of the current user
46
+ if (names.length === 0) {
47
+ names = [
48
+ participants.find((participant) => participant.userId === currentUserId)
49
+ ?.name ?? 'Call',
50
+ ];
51
+ }
52
+
53
+ return names.sort().join(', ');
54
+ }
55
+
56
+ /**
57
+ * Starts the call in the callingx library.
58
+ * Must be called for all outgoing calls
59
+ * and optionally for non-ringing calls when ongoing calls are enabled.
60
+ */
61
+ export async function startCallingxCall(call: Call) {
62
+ if (!CallingxModule || !CallingxModule.isSetup) {
63
+ return;
64
+ }
65
+
66
+ const logger = videoLoggerSystem.getLogger('callingx');
67
+ const isOutcomingCall = call.ringing && call.isCreatedByMe;
68
+ const isIncomingCall = call.ringing && !call.isCreatedByMe;
69
+
70
+ const callDisplayName = getCallDisplayName(
71
+ call.state.members,
72
+ call.state.participants,
73
+ call.currentUserId,
74
+ );
75
+
76
+ if (
77
+ !CallingxModule.isCallTracked(call.cid) &&
78
+ (isOutcomingCall || (!call.ringing && CallingxModule.isOngoingCallsEnabled))
79
+ ) {
80
+ try {
81
+ await CallingxModule.startCall(
82
+ call.cid, // unique id for call
83
+ call.id, // phone number for display in dialer (we use call id as phone number)
84
+ callDisplayName, // display name for display in call screen
85
+ call.state.settings?.video?.enabled ?? false, // is video call?
86
+ );
87
+
88
+ // Wait for audio session activation on iOS only
89
+ if (Platform.OS === 'ios') {
90
+ await waitForAudioSessionActivation();
91
+ }
92
+
93
+ // TODO: this must be done after join call is complete
94
+ CallingxModule.setCurrentCallActive(call.cid);
95
+ } catch (error) {
96
+ logger.error(
97
+ `startCallingxCall: Error starting call in callingx: ${call.cid}`,
98
+ error,
99
+ );
100
+ }
101
+ } else if (isIncomingCall) {
102
+ try {
103
+ // Awaits native CallKit/Telecom registration before answering.
104
+ // Safe to call even if the call is already registered (e.g. from VoIP push) --
105
+ // iOS early-returns with no error, Android sends the registered broadcast.
106
+ await CallingxModule.displayIncomingCall(
107
+ call.cid, // unique id for call
108
+ call.id, // phone number for display in dialer (we use call id as phone number)
109
+ callDisplayName, // display name for display in call screen
110
+ call.state.settings?.video?.enabled ?? false, // is video call?
111
+ );
112
+
113
+ await CallingxModule.answerIncomingCall(call.cid);
114
+
115
+ if (Platform.OS === 'ios') {
116
+ await waitForAudioSessionActivation();
117
+ }
118
+ } catch (error) {
119
+ logger.error(
120
+ `Error displaying incoming call in callingx: ${call.cid}`,
121
+ error,
122
+ );
123
+ }
124
+ }
125
+ }
126
+
127
+ export async function endCallingxCall(call: Call, reason?: EndCallReason) {
128
+ if (
129
+ !CallingxModule ||
130
+ !CallingxModule.isSetup ||
131
+ !CallingxModule.isCallTracked(call.cid)
132
+ ) {
133
+ return;
134
+ }
135
+
136
+ try {
137
+ await CallingxModule.endCallWithReason(call.cid, reason ?? 'local');
138
+ } catch (error) {
139
+ videoLoggerSystem
140
+ .getLogger('callingx')
141
+ .error(
142
+ `endCallingxCall: Error ending call in callingx: ${call.cid}`,
143
+ error,
144
+ );
145
+ }
146
+ }
@@ -1,23 +1,66 @@
1
- import type { StreamRNVideoSDKGlobals } from '@stream-io/video-client';
1
+ import { StreamRNVideoSDKGlobals } from '@stream-io/video-client';
2
2
  import { NativeModules, PermissionsAndroid, Platform } from 'react-native';
3
+ import { getCallingxLibIfAvailable } from '../push/libs/callingx';
4
+ import { endCallingxCall, startCallingxCall } from './callingx/callingx';
3
5
 
4
6
  const StreamInCallManagerNativeModule = NativeModules.StreamInCallManager;
5
7
  const StreamVideoReactNativeModule = NativeModules.StreamVideoReactNative as {
6
8
  checkPermission: StreamRNVideoSDKGlobals['permissions']['check'] | undefined;
7
9
  };
8
10
 
11
+ const CallingxModule = getCallingxLibIfAvailable();
12
+
13
+ /**
14
+ * Checks if StreamInCallManager should be bypassed because CallKit is handling
15
+ * the audio session via CallingX.
16
+ *
17
+ * On iOS, when CallingX is set up and has a registered call, the audio session
18
+ * is managed by CallKit through CallingxImpl.swift.
19
+ * In this case, StreamInCallManager should not run to avoid conflicting audio
20
+ * session configurations.
21
+ */
22
+ const shouldBypassForCallKit = ({
23
+ isRingingTypeCall,
24
+ }: {
25
+ isRingingTypeCall: boolean;
26
+ }): boolean => {
27
+ if (Platform.OS !== 'ios') {
28
+ return false;
29
+ }
30
+ if (!CallingxModule) {
31
+ return false;
32
+ }
33
+ const bypass =
34
+ CallingxModule.isSetup &&
35
+ (isRingingTypeCall || CallingxModule.isOngoingCallsEnabled);
36
+ return bypass;
37
+ };
38
+
9
39
  const streamRNVideoSDKGlobals: StreamRNVideoSDKGlobals = {
40
+ callingX: {
41
+ startCall: startCallingxCall,
42
+ endCall: endCallingxCall,
43
+ },
10
44
  callManager: {
11
- setup: ({ defaultDevice }) => {
45
+ setup: ({ defaultDevice, isRingingTypeCall }) => {
46
+ if (shouldBypassForCallKit({ isRingingTypeCall })) {
47
+ return;
48
+ }
12
49
  StreamInCallManagerNativeModule.setDefaultAudioDeviceEndpointType(
13
50
  defaultDevice,
14
51
  );
15
52
  StreamInCallManagerNativeModule.setup();
16
53
  },
17
- start: () => {
54
+ start: ({ isRingingTypeCall }) => {
55
+ if (shouldBypassForCallKit({ isRingingTypeCall })) {
56
+ return;
57
+ }
18
58
  StreamInCallManagerNativeModule.start();
19
59
  },
20
- stop: () => {
60
+ stop: ({ isRingingTypeCall }) => {
61
+ if (shouldBypassForCallKit({ isRingingTypeCall })) {
62
+ return;
63
+ }
21
64
  StreamInCallManagerNativeModule.stop();
22
65
  },
23
66
  },
@@ -0,0 +1,54 @@
1
+ import { AppRegistry, Platform } from 'react-native';
2
+ import type { Call } from '@stream-io/video-client';
3
+ import { videoLoggerSystem } from '@stream-io/video-client';
4
+ import { StreamVideoRN } from './StreamVideoRN';
5
+
6
+ export const KEEP_CALL_ALIVE_HEADLESS_TASK_NAME = 'StreamVideoKeepCallAlive';
7
+
8
+ /**
9
+ * The keep-alive headless task needs access to the active `Call` instance.
10
+ * The keep-alive hook will set this reference before starting the native service.
11
+ */
12
+ export const keepCallAliveCallRef: { current: Call | undefined } = {
13
+ current: undefined,
14
+ };
15
+
16
+ function registerKeepCallAliveHeadlessTaskOnce() {
17
+ if (Platform.OS !== 'android') return;
18
+
19
+ AppRegistry.registerHeadlessTask(
20
+ KEEP_CALL_ALIVE_HEADLESS_TASK_NAME,
21
+ () => async (data: { callCid?: string } | undefined) => {
22
+ const logger = videoLoggerSystem.getLogger(
23
+ 'KEEP_CALL_ALIVE_HEADLESS_TASK',
24
+ );
25
+ const callCid = data?.callCid;
26
+
27
+ const call = keepCallAliveCallRef.current;
28
+ if (!call) {
29
+ logger.warn(
30
+ 'No active call instance available for keep-alive task; skipping.',
31
+ { callCid },
32
+ );
33
+ return;
34
+ }
35
+ if (callCid && call.cid && call.cid !== callCid) {
36
+ logger.warn(
37
+ 'Keep-alive task callCid does not match active call; skipping.',
38
+ { callCid, activeCallCid: call.cid },
39
+ );
40
+ return;
41
+ }
42
+
43
+ const config = StreamVideoRN.getConfig();
44
+ const taskToRun = config.foregroundService.android.taskToRun;
45
+ try {
46
+ await taskToRun(call);
47
+ } catch (e) {
48
+ logger.error('Keep-alive headless task failed', e);
49
+ }
50
+ },
51
+ );
52
+ }
53
+
54
+ registerKeepCallAliveHeadlessTaskOnce();