@stream-io/video-react-native-sdk 1.29.0-beta.3 → 1.29.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (224) hide show
  1. package/CHANGELOG.md +3126 -0
  2. package/android/src/main/AndroidManifest.xml +1 -8
  3. package/android/src/main/AndroidManifestNew.xml +0 -11
  4. package/android/src/main/java/com/streamvideo/reactnative/StreamVideoReactNativeModule.kt +5 -42
  5. package/android/src/main/java/com/streamvideo/reactnative/audio/utils/WebRtcAudioUtils.kt +6 -70
  6. package/android/src/main/java/com/streamvideo/reactnative/callmanager/StreamInCallManagerModule.kt +4 -6
  7. package/android/src/main/java/com/streamvideo/reactnative/util/CallAliveServiceChecker.kt +95 -0
  8. package/dist/commonjs/components/Call/CallContent/CallContent.js +7 -2
  9. package/dist/commonjs/components/Call/CallContent/CallContent.js.map +1 -1
  10. package/dist/commonjs/components/Call/CallContent/RTCViewPipIOS.js +8 -1
  11. package/dist/commonjs/components/Call/CallContent/RTCViewPipIOS.js.map +1 -1
  12. package/dist/commonjs/components/Call/CallContent/RTCViewPipNative.js +3 -0
  13. package/dist/commonjs/components/Call/CallContent/RTCViewPipNative.js.map +1 -1
  14. package/dist/commonjs/hooks/push/useIosCallkeepWithCallingStateEffect.js +160 -0
  15. package/dist/commonjs/hooks/push/useIosCallkeepWithCallingStateEffect.js.map +1 -0
  16. package/dist/commonjs/hooks/push/useIosVoipPushEventsSetupEffect.js +31 -18
  17. package/dist/commonjs/hooks/push/useIosVoipPushEventsSetupEffect.js.map +1 -1
  18. package/dist/commonjs/hooks/useAndroidKeepCallAliveEffect.js +97 -64
  19. package/dist/commonjs/hooks/useAndroidKeepCallAliveEffect.js.map +1 -1
  20. package/dist/commonjs/index.js +0 -1
  21. package/dist/commonjs/index.js.map +1 -1
  22. package/dist/commonjs/modules/call-manager/CallManager.js +0 -26
  23. package/dist/commonjs/modules/call-manager/CallManager.js.map +1 -1
  24. package/dist/commonjs/providers/StreamCall/index.js +6 -6
  25. package/dist/commonjs/providers/StreamCall/index.js.map +1 -1
  26. package/dist/commonjs/utils/StreamVideoRN/index.js +21 -33
  27. package/dist/commonjs/utils/StreamVideoRN/index.js.map +1 -1
  28. package/dist/commonjs/utils/internal/registerSDKGlobals.js +15 -52
  29. package/dist/commonjs/utils/internal/registerSDKGlobals.js.map +1 -1
  30. package/dist/commonjs/utils/push/android.js +202 -155
  31. package/dist/commonjs/utils/push/android.js.map +1 -1
  32. package/dist/commonjs/utils/push/internal/ios.js +32 -16
  33. package/dist/commonjs/utils/push/internal/ios.js.map +1 -1
  34. package/dist/commonjs/utils/push/internal/rxSubjects.js +20 -1
  35. package/dist/commonjs/utils/push/internal/rxSubjects.js.map +1 -1
  36. package/dist/commonjs/utils/push/internal/utils.js +16 -28
  37. package/dist/commonjs/utils/push/internal/utils.js.map +1 -1
  38. package/dist/commonjs/utils/push/ios.js.map +1 -1
  39. package/dist/commonjs/utils/push/libs/callkeep.js +17 -0
  40. package/dist/commonjs/utils/push/libs/callkeep.js.map +1 -0
  41. package/dist/commonjs/utils/push/libs/index.js +19 -8
  42. package/dist/commonjs/utils/push/libs/index.js.map +1 -1
  43. package/dist/commonjs/utils/push/libs/notifee/index.js +19 -0
  44. package/dist/commonjs/utils/push/libs/notifee/index.js.map +1 -1
  45. package/dist/commonjs/utils/push/libs/voipPushNotification.js +17 -0
  46. package/dist/commonjs/utils/push/libs/voipPushNotification.js.map +1 -0
  47. package/dist/commonjs/utils/push/setupIosCallKeepEvents.js +205 -0
  48. package/dist/commonjs/utils/push/setupIosCallKeepEvents.js.map +1 -0
  49. package/dist/commonjs/utils/push/setupIosVoipPushEvents.js +6 -7
  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/components/Call/CallContent/CallContent.js +7 -2
  54. package/dist/module/components/Call/CallContent/CallContent.js.map +1 -1
  55. package/dist/module/components/Call/CallContent/RTCViewPipIOS.js +8 -1
  56. package/dist/module/components/Call/CallContent/RTCViewPipIOS.js.map +1 -1
  57. package/dist/module/components/Call/CallContent/RTCViewPipNative.js +3 -0
  58. package/dist/module/components/Call/CallContent/RTCViewPipNative.js.map +1 -1
  59. package/dist/module/hooks/push/useIosCallkeepWithCallingStateEffect.js +153 -0
  60. package/dist/module/hooks/push/useIosCallkeepWithCallingStateEffect.js.map +1 -0
  61. package/dist/module/hooks/push/useIosVoipPushEventsSetupEffect.js +31 -18
  62. package/dist/module/hooks/push/useIosVoipPushEventsSetupEffect.js.map +1 -1
  63. package/dist/module/hooks/useAndroidKeepCallAliveEffect.js +99 -66
  64. package/dist/module/hooks/useAndroidKeepCallAliveEffect.js.map +1 -1
  65. package/dist/module/index.js +0 -1
  66. package/dist/module/index.js.map +1 -1
  67. package/dist/module/modules/call-manager/CallManager.js +0 -26
  68. package/dist/module/modules/call-manager/CallManager.js.map +1 -1
  69. package/dist/module/providers/StreamCall/index.js +6 -6
  70. package/dist/module/providers/StreamCall/index.js.map +1 -1
  71. package/dist/module/utils/StreamVideoRN/index.js +21 -33
  72. package/dist/module/utils/StreamVideoRN/index.js.map +1 -1
  73. package/dist/module/utils/internal/registerSDKGlobals.js +16 -53
  74. package/dist/module/utils/internal/registerSDKGlobals.js.map +1 -1
  75. package/dist/module/utils/push/android.js +204 -157
  76. package/dist/module/utils/push/android.js.map +1 -1
  77. package/dist/module/utils/push/internal/ios.js +32 -16
  78. package/dist/module/utils/push/internal/ios.js.map +1 -1
  79. package/dist/module/utils/push/internal/rxSubjects.js +19 -0
  80. package/dist/module/utils/push/internal/rxSubjects.js.map +1 -1
  81. package/dist/module/utils/push/internal/utils.js +15 -25
  82. package/dist/module/utils/push/internal/utils.js.map +1 -1
  83. package/dist/module/utils/push/ios.js.map +1 -1
  84. package/dist/module/utils/push/libs/callkeep.js +11 -0
  85. package/dist/module/utils/push/libs/callkeep.js.map +1 -0
  86. package/dist/module/utils/push/libs/index.js +2 -1
  87. package/dist/module/utils/push/libs/index.js.map +1 -1
  88. package/dist/module/utils/push/libs/notifee/index.js +18 -0
  89. package/dist/module/utils/push/libs/notifee/index.js.map +1 -1
  90. package/dist/module/utils/push/libs/voipPushNotification.js +11 -0
  91. package/dist/module/utils/push/libs/voipPushNotification.js.map +1 -0
  92. package/dist/module/utils/push/setupIosCallKeepEvents.js +199 -0
  93. package/dist/module/utils/push/setupIosCallKeepEvents.js.map +1 -0
  94. package/dist/module/utils/push/setupIosVoipPushEvents.js +6 -7
  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/components/Call/CallContent/CallContent.d.ts +2 -2
  99. package/dist/typescript/components/Call/CallContent/CallContent.d.ts.map +1 -1
  100. package/dist/typescript/components/Call/CallContent/RTCViewPipIOS.d.ts +4 -0
  101. package/dist/typescript/components/Call/CallContent/RTCViewPipIOS.d.ts.map +1 -1
  102. package/dist/typescript/components/Call/CallContent/RTCViewPipNative.d.ts +9 -6
  103. package/dist/typescript/components/Call/CallContent/RTCViewPipNative.d.ts.map +1 -1
  104. package/dist/typescript/hooks/push/useIosCallkeepWithCallingStateEffect.d.ts +5 -0
  105. package/dist/typescript/hooks/push/useIosCallkeepWithCallingStateEffect.d.ts.map +1 -0
  106. package/dist/typescript/hooks/push/useIosVoipPushEventsSetupEffect.d.ts.map +1 -1
  107. package/dist/typescript/hooks/useAndroidKeepCallAliveEffect.d.ts.map +1 -1
  108. package/dist/typescript/index.d.ts +0 -1
  109. package/dist/typescript/index.d.ts.map +1 -1
  110. package/dist/typescript/modules/call-manager/CallManager.d.ts +0 -5
  111. package/dist/typescript/modules/call-manager/CallManager.d.ts.map +1 -1
  112. package/dist/typescript/utils/StreamVideoRN/index.d.ts +2 -20
  113. package/dist/typescript/utils/StreamVideoRN/index.d.ts.map +1 -1
  114. package/dist/typescript/utils/StreamVideoRN/types.d.ts +29 -54
  115. package/dist/typescript/utils/StreamVideoRN/types.d.ts.map +1 -1
  116. package/dist/typescript/utils/internal/registerSDKGlobals.d.ts.map +1 -1
  117. package/dist/typescript/utils/push/android.d.ts +2 -1
  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 +12 -0
  121. package/dist/typescript/utils/push/internal/rxSubjects.d.ts.map +1 -1
  122. package/dist/typescript/utils/push/internal/utils.d.ts +1 -8
  123. package/dist/typescript/utils/push/internal/utils.d.ts.map +1 -1
  124. package/dist/typescript/utils/push/ios.d.ts +2 -1
  125. package/dist/typescript/utils/push/ios.d.ts.map +1 -1
  126. package/dist/typescript/utils/push/libs/callkeep.d.ts +3 -0
  127. package/dist/typescript/utils/push/libs/callkeep.d.ts.map +1 -0
  128. package/dist/typescript/utils/push/libs/firebaseMessaging/index.d.ts +2 -16
  129. package/dist/typescript/utils/push/libs/firebaseMessaging/index.d.ts.map +1 -1
  130. package/dist/typescript/utils/push/libs/index.d.ts +2 -1
  131. package/dist/typescript/utils/push/libs/index.d.ts.map +1 -1
  132. package/dist/typescript/utils/push/libs/notifee/index.d.ts +1 -0
  133. package/dist/typescript/utils/push/libs/notifee/index.d.ts.map +1 -1
  134. package/dist/typescript/utils/push/libs/voipPushNotification.d.ts +3 -0
  135. package/dist/typescript/utils/push/libs/voipPushNotification.d.ts.map +1 -0
  136. package/dist/typescript/utils/push/setupIosCallKeepEvents.d.ts +6 -0
  137. package/dist/typescript/utils/push/setupIosCallKeepEvents.d.ts.map +1 -0
  138. package/dist/typescript/utils/push/setupIosVoipPushEvents.d.ts.map +1 -1
  139. package/dist/typescript/version.d.ts +1 -1
  140. package/dist/typescript/version.d.ts.map +1 -1
  141. package/expo-config-plugin/dist/withAndroidManifest.js +33 -1
  142. package/expo-config-plugin/dist/withAndroidPermissions.js +7 -2
  143. package/expo-config-plugin/dist/withAppDelegate.js +197 -19
  144. package/expo-config-plugin/dist/withMainActivity.js +1 -1
  145. package/expo-config-plugin/dist/withiOSInfoPlist.js +3 -2
  146. package/ios/PictureInPicture/StreamAVPictureInPictureVideoCallViewController.swift +8 -0
  147. package/ios/PictureInPicture/StreamPictureInPictureController.swift +8 -0
  148. package/ios/PictureInPicture/StreamPictureInPictureVideoRenderer.swift +10 -0
  149. package/ios/RTCViewPip.swift +6 -0
  150. package/ios/RTCViewPipManager.mm +1 -0
  151. package/ios/StreamInCallManager.m +0 -2
  152. package/ios/StreamInCallManager.swift +7 -19
  153. package/ios/StreamVideoReactNative.h +4 -7
  154. package/ios/StreamVideoReactNative.m +102 -191
  155. package/package.json +19 -14
  156. package/src/components/Call/CallContent/CallContent.tsx +6 -1
  157. package/src/components/Call/CallContent/RTCViewPipIOS.tsx +18 -2
  158. package/src/components/Call/CallContent/RTCViewPipNative.tsx +4 -7
  159. package/src/hooks/push/useIosCallkeepWithCallingStateEffect.ts +235 -0
  160. package/src/hooks/push/useIosVoipPushEventsSetupEffect.ts +34 -21
  161. package/src/hooks/useAndroidKeepCallAliveEffect.ts +120 -94
  162. package/src/index.ts +0 -1
  163. package/src/modules/call-manager/CallManager.ts +0 -36
  164. package/src/modules/call-manager/native-module.d.ts +0 -7
  165. package/src/providers/StreamCall/index.tsx +6 -6
  166. package/src/utils/StreamVideoRN/index.ts +30 -40
  167. package/src/utils/StreamVideoRN/types.ts +29 -56
  168. package/src/utils/internal/registerSDKGlobals.ts +23 -47
  169. package/src/utils/push/android.ts +309 -231
  170. package/src/utils/push/internal/ios.ts +42 -27
  171. package/src/utils/push/internal/rxSubjects.ts +29 -0
  172. package/src/utils/push/internal/utils.ts +15 -38
  173. package/src/utils/push/ios.ts +6 -1
  174. package/src/utils/push/libs/callkeep.ts +16 -0
  175. package/src/utils/push/libs/index.ts +2 -1
  176. package/src/utils/push/libs/notifee/index.ts +27 -0
  177. package/src/utils/push/libs/voipPushNotification.ts +17 -0
  178. package/src/utils/push/setupIosCallKeepEvents.ts +252 -0
  179. package/src/utils/push/setupIosVoipPushEvents.ts +7 -11
  180. package/src/version.ts +1 -1
  181. package/android/src/main/java/com/streamvideo/reactnative/keepalive/KeepAliveNotification.kt +0 -83
  182. package/android/src/main/java/com/streamvideo/reactnative/keepalive/StreamCallKeepAliveHeadlessService.kt +0 -134
  183. package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js +0 -121
  184. package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js.map +0 -1
  185. package/dist/commonjs/utils/internal/audioSessionPromise.js +0 -57
  186. package/dist/commonjs/utils/internal/audioSessionPromise.js.map +0 -1
  187. package/dist/commonjs/utils/internal/callingx.js +0 -136
  188. package/dist/commonjs/utils/internal/callingx.js.map +0 -1
  189. package/dist/commonjs/utils/keepCallAliveHeadlessTask.js +0 -48
  190. package/dist/commonjs/utils/keepCallAliveHeadlessTask.js.map +0 -1
  191. package/dist/commonjs/utils/push/libs/callingx.js +0 -75
  192. package/dist/commonjs/utils/push/libs/callingx.js.map +0 -1
  193. package/dist/commonjs/utils/push/setupCallingExpEvents.js +0 -97
  194. package/dist/commonjs/utils/push/setupCallingExpEvents.js.map +0 -1
  195. package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js +0 -114
  196. package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js.map +0 -1
  197. package/dist/module/utils/internal/audioSessionPromise.js +0 -50
  198. package/dist/module/utils/internal/audioSessionPromise.js.map +0 -1
  199. package/dist/module/utils/internal/callingx.js +0 -127
  200. package/dist/module/utils/internal/callingx.js.map +0 -1
  201. package/dist/module/utils/keepCallAliveHeadlessTask.js +0 -42
  202. package/dist/module/utils/keepCallAliveHeadlessTask.js.map +0 -1
  203. package/dist/module/utils/push/libs/callingx.js +0 -67
  204. package/dist/module/utils/push/libs/callingx.js.map +0 -1
  205. package/dist/module/utils/push/setupCallingExpEvents.js +0 -91
  206. package/dist/module/utils/push/setupCallingExpEvents.js.map +0 -1
  207. package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts +0 -5
  208. package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts.map +0 -1
  209. package/dist/typescript/utils/internal/audioSessionPromise.d.ts +0 -16
  210. package/dist/typescript/utils/internal/audioSessionPromise.d.ts.map +0 -1
  211. package/dist/typescript/utils/internal/callingx.d.ts +0 -13
  212. package/dist/typescript/utils/internal/callingx.d.ts.map +0 -1
  213. package/dist/typescript/utils/keepCallAliveHeadlessTask.d.ts +0 -10
  214. package/dist/typescript/utils/keepCallAliveHeadlessTask.d.ts.map +0 -1
  215. package/dist/typescript/utils/push/libs/callingx.d.ts +0 -9
  216. package/dist/typescript/utils/push/libs/callingx.d.ts.map +0 -1
  217. package/dist/typescript/utils/push/setupCallingExpEvents.d.ts +0 -8
  218. package/dist/typescript/utils/push/setupCallingExpEvents.d.ts.map +0 -1
  219. package/src/hooks/push/useCallingExpWithCallingStateEffect.ts +0 -147
  220. package/src/utils/internal/audioSessionPromise.ts +0 -52
  221. package/src/utils/internal/callingx.ts +0 -192
  222. package/src/utils/keepCallAliveHeadlessTask.ts +0 -54
  223. package/src/utils/push/libs/callingx.ts +0 -90
  224. package/src/utils/push/setupCallingExpEvents.ts +0 -117
@@ -1,9 +1,10 @@
1
- import { Platform } from 'react-native';
1
+ import { AppState, NativeModules, Platform } from 'react-native';
2
+ import { getCallKeepLib, getVoipPushNotificationLib } from '../libs';
3
+ import { voipPushNotificationCallCId$ } from './rxSubjects';
2
4
  import { pushUnsubscriptionCallbacks } from './constants';
3
- import { canListenToWS, shouldCallBeClosed } from './utils';
5
+ import { canAddPushWSSubscriptionsRef, shouldCallBeEnded } from './utils';
4
6
  import { StreamVideoConfig } from '../../StreamVideoRN/types';
5
7
  import { videoLoggerSystem } from '@stream-io/video-client';
6
- import { getCallingxLib } from '../libs/callingx';
7
8
 
8
9
  export const onVoipNotificationReceived = async (
9
10
  notification: any,
@@ -31,57 +32,71 @@ export const onVoipNotificationReceived = async (
31
32
  "version": "v2"
32
33
  }
33
34
  } */
34
- const logger = videoLoggerSystem.getLogger(
35
- 'callingx - onVoipNotificationReceived',
36
- );
37
-
38
35
  const sender = notification?.stream?.sender;
39
36
  const type = notification?.stream?.type;
40
37
  // do not process any other notifications other than stream.video or ringing
41
38
  if (sender !== 'stream.video' && type !== 'call.ring') {
42
39
  return;
43
40
  }
44
-
45
41
  const call_cid = notification?.stream?.call_cid;
46
42
  if (!call_cid || Platform.OS !== 'ios' || !pushConfig.ios.pushProviderName) {
47
43
  return;
48
44
  }
49
-
50
- const callingx = getCallingxLib();
51
- if (callingx.isCallRegistered(call_cid)) {
52
- //same call_cid is registered, so we skipping the notification
53
- logger.debug(
54
- `the same call_cid ${call_cid} is registered, skipping the call.ring notification`,
55
- );
56
- return;
57
- }
58
-
45
+ const logger = videoLoggerSystem.getLogger('setupIosVoipPushEvents');
59
46
  const client = await pushConfig.createStreamVideoClient();
47
+
60
48
  if (!client) {
61
49
  logger.debug(
62
50
  'client not found, not processing call.ring voip push notification',
63
51
  );
64
52
  return;
65
53
  }
66
-
54
+ const shouldRejectCallWhenBusy = client['rejectCallWhenBusy'] ?? false;
55
+ if (shouldRejectCallWhenBusy) {
56
+ // inform the iOS native module that we should reject call when busy
57
+ NativeModules.StreamVideoReactNative.setShouldRejectCallWhenBusy(
58
+ shouldRejectCallWhenBusy,
59
+ );
60
+ }
67
61
  const callFromPush = await client.onRingingCall(call_cid);
68
-
62
+ let uuid = '';
63
+ try {
64
+ uuid =
65
+ await NativeModules?.StreamVideoReactNative?.getIncomingCallUUid(
66
+ call_cid,
67
+ );
68
+ } catch (error) {
69
+ logger.error('Error in getting call uuid from native module', error);
70
+ }
71
+ if (!uuid) {
72
+ logger.error(
73
+ `Not processing call.ring push notification, as no uuid found for call_cid: ${call_cid}`,
74
+ );
75
+ return;
76
+ }
77
+ const created_by_id = notification?.stream?.created_by_id;
78
+ const receiver_id = notification?.stream?.receiver_id;
69
79
  function closeCallIfNecessary() {
70
- const { mustEndCall, endCallReason } = shouldCallBeClosed(
80
+ const { mustEndCall, callkeepReason } = shouldCallBeEnded(
71
81
  callFromPush,
72
- notification?.stream,
82
+ created_by_id,
83
+ receiver_id,
73
84
  );
74
85
  if (mustEndCall) {
86
+ const callkeep = getCallKeepLib();
75
87
  logger.debug(
76
- `callingx.endCallWithReason for call_cid: ${call_cid} endCallReason: ${endCallReason}`,
88
+ `callkeep.reportEndCallWithUUID for uuid: ${uuid}, call_cid: ${call_cid}, reason: ${callkeepReason}`,
77
89
  );
78
- callingx.endCallWithReason(call_cid, endCallReason);
90
+ callkeep.reportEndCallWithUUID(uuid, callkeepReason);
91
+ const voipPushNotification = getVoipPushNotificationLib();
92
+ voipPushNotification.onVoipNotificationCompleted(uuid);
79
93
  return true;
80
94
  }
81
95
  return false;
82
96
  }
83
-
84
97
  const closed = closeCallIfNecessary();
98
+ const canListenToWS = () =>
99
+ canAddPushWSSubscriptionsRef.current && AppState.currentState !== 'active';
85
100
  if (!closed && canListenToWS()) {
86
101
  const unsubscribe = callFromPush.on('all', (event) => {
87
102
  const _canListenToWS = canListenToWS();
@@ -106,10 +121,10 @@ export const onVoipNotificationReceived = async (
106
121
  pushUnsubscriptionCallbacks.get(call_cid)?.forEach((cb) => cb());
107
122
  pushUnsubscriptionCallbacks.set(call_cid, [unsubscribe]);
108
123
  }
109
-
110
124
  // send the info to this subject, it is listened by callkeep events
111
125
  // callkeep events will then accept/reject the call
112
126
  logger.debug(
113
- `call_cid:${call_cid} received and processed from call.ring push notification`,
127
+ `call_cid:${call_cid} uuid:${uuid} received and processed from call.ring push notification`,
114
128
  );
129
+ voipPushNotificationCallCId$.next(call_cid);
115
130
  };
@@ -40,3 +40,32 @@ export const pushAndroidBackgroundDeliveredIncomingCallCId$ =
40
40
  export const pushRejectedIncomingCallCId$ = new BehaviorSubject<
41
41
  string | undefined
42
42
  >(undefined);
43
+
44
+ /**
45
+ * This rxjs subject is used to store the call cid of the incoming call from ios voip pushkit notification
46
+ */
47
+ export const voipPushNotificationCallCId$ = new BehaviorSubject<
48
+ string | undefined
49
+ >(undefined);
50
+
51
+ /** The pair of cid of a call and its corresponding uuid created in the native side */
52
+ type CallkeepMap = {
53
+ uuid: string;
54
+ cid: string;
55
+ };
56
+
57
+ /*
58
+ * This rxjs subject should only used to store the CallkeepMap
59
+ * for the incoming call when on foreground
60
+ * or in other words, when we get didDisplayIncomingCall from callkeep lib
61
+ */
62
+ export const voipCallkeepCallOnForegroundMap$ = new BehaviorSubject<
63
+ CallkeepMap | undefined
64
+ >(undefined);
65
+
66
+ /*
67
+ * This rxjs subject should only used to store the CallkeepMap when it was accepted in the native dialer
68
+ */
69
+ export const voipCallkeepAcceptedCallOnNativeDialerMap$ = new BehaviorSubject<
70
+ CallkeepMap | undefined
71
+ >(undefined);
@@ -10,8 +10,6 @@ import type {
10
10
  } from '../../StreamVideoRN/types';
11
11
  import { onNewCallNotification } from '../../internal/newNotificationCallbacks';
12
12
  import { pushUnsubscriptionCallbacks } from './constants';
13
- import { AppState } from 'react-native';
14
- import type { EndCallReason } from '@stream-io/react-native-callingx';
15
13
 
16
14
  type PushConfig = NonNullable<StreamVideoConfig['push']>;
17
15
 
@@ -26,37 +24,44 @@ export const shouldCallBeEnded = (
26
24
  created_by_id: string | undefined,
27
25
  receiver_id: string | undefined,
28
26
  ) => {
27
+ /* callkeep reasons for ending a call
28
+ FAILED: 1,
29
+ REMOTE_ENDED: 2,
30
+ UNANSWERED: 3,
31
+ ANSWERED_ELSEWHERE: 4,
32
+ DECLINED_ELSEWHERE: 5,
33
+ MISSED: 6
34
+ */
29
35
  const callSession = callFromPush.state.session;
30
36
  const rejected_by = callSession?.rejected_by;
31
37
  const accepted_by = callSession?.accepted_by;
32
38
  let mustEndCall = false;
33
- let endCallReason: EndCallReason = 'unknown';
34
-
39
+ let callkeepReason = 0;
35
40
  if (created_by_id && rejected_by) {
36
41
  if (rejected_by[created_by_id]) {
37
- // call was cancelled by the caller before the receiver could answer
42
+ // call was cancelled by the caller
38
43
  mustEndCall = true;
39
- endCallReason = 'canceled';
44
+ callkeepReason = 2;
40
45
  }
41
46
  } else if (receiver_id && rejected_by) {
42
47
  if (rejected_by[receiver_id]) {
43
48
  // call was rejected by the receiver in some other device
44
49
  mustEndCall = true;
45
- endCallReason = 'rejected';
50
+ callkeepReason = 5;
46
51
  }
47
52
  } else if (receiver_id && accepted_by) {
48
53
  if (accepted_by[receiver_id]) {
49
54
  // call was accepted by the receiver in some other device
50
55
  mustEndCall = true;
51
- endCallReason = 'answeredElsewhere';
56
+ callkeepReason = 4;
52
57
  }
53
58
  }
54
59
  videoLoggerSystem
55
60
  .getLogger('shouldCallBeEnded')
56
61
  .debug(
57
- `callCid: ${callFromPush.cid} mustEndCall: ${mustEndCall} endCallReason: ${endCallReason}`,
62
+ `callCid: ${callFromPush.cid} mustEndCall: ${mustEndCall} callkeepReason: ${callkeepReason}`,
58
63
  );
59
- return { mustEndCall, endCallReason };
64
+ return { mustEndCall, callkeepReason };
60
65
  };
61
66
 
62
67
  /* An action for the notification or callkeep and app does not have JS context setup yet, so we need to do two steps:
@@ -117,16 +122,6 @@ export const processCallFromPush = async (
117
122
  .debug(
118
123
  `joining call from push notification with callCid: ${callFromPush.cid}`,
119
124
  );
120
-
121
- if (callFromPush.state.callingState === CallingState.JOINED) {
122
- videoLoggerSystem
123
- .getLogger('processCallFromPush')
124
- .debug(
125
- `call already joined from push notification with callCid: ${callFromPush.cid}`,
126
- );
127
- return;
128
- }
129
-
130
125
  await callFromPush.join();
131
126
  } else if (action === 'decline') {
132
127
  const canReject =
@@ -196,21 +191,3 @@ export const clearPushWSEventSubscriptions = (call_cid: string) => {
196
191
  export const canAddPushWSSubscriptionsRef: CanAddPushWSSubscriptionsRef = {
197
192
  current: true,
198
193
  };
199
-
200
- export const canListenToWS = () =>
201
- canAddPushWSSubscriptionsRef.current && AppState.currentState !== 'active';
202
-
203
- export const shouldCallBeClosed = (
204
- call: Call,
205
- pushData: { [key: string]: string | object },
206
- ) => {
207
- const created_by_id = pushData?.created_by_id as string;
208
- const receiver_id = pushData?.receiver_id as string;
209
-
210
- const { mustEndCall, endCallReason } = shouldCallBeEnded(
211
- call,
212
- created_by_id,
213
- receiver_id,
214
- );
215
- return { mustEndCall, endCallReason };
216
- };
@@ -62,7 +62,12 @@ export const oniOSExpoNotificationEvent = (event: ExpoNotification) => {
62
62
  }
63
63
  };
64
64
 
65
- export const oniOSNotifeeEvent = ({ event }: { event: Event }) => {
65
+ export const oniOSNotifeeEvent = ({
66
+ event,
67
+ }: {
68
+ event: Event;
69
+ isBackground: boolean;
70
+ }) => {
66
71
  if (Platform.OS !== 'ios') return;
67
72
  const pushConfig = StreamVideoRN.getConfig().push;
68
73
  const { type, detail } = event;
@@ -0,0 +1,16 @@
1
+ export type RNCallKeepType = typeof import('react-native-callkeep').default;
2
+
3
+ let callkeep: RNCallKeepType | undefined;
4
+
5
+ try {
6
+ callkeep = require('react-native-callkeep').default;
7
+ } catch {}
8
+
9
+ export function getCallKeepLib() {
10
+ if (!callkeep) {
11
+ throw Error(
12
+ 'react-native-callkeep library is not installed. Please see https://github.com/react-native-webrtc/react-native-callkeep#Installation for installation instructions',
13
+ );
14
+ }
15
+ return callkeep;
16
+ }
@@ -1,8 +1,9 @@
1
1
  export * from './expoNotifications';
2
2
  export * from './firebaseMessaging';
3
3
  export * from './iosPushNotification';
4
+ export * from './voipPushNotification';
5
+ export * from './callkeep';
4
6
  export * from './notifee';
5
- export * from './callingx';
6
7
 
7
8
  /*
8
9
  NOTE: must keep each libs in different files
@@ -1,4 +1,6 @@
1
+ import { PermissionsAndroid } from 'react-native';
1
2
  import { lib, type Type } from './lib';
3
+ import { videoLoggerSystem } from '@stream-io/video-client';
2
4
 
3
5
  export type NotifeeLib = Type;
4
6
 
@@ -34,9 +36,34 @@ export function getNotifeeLibThrowIfNotInstalledForPush() {
34
36
  }
35
37
 
36
38
  export function getNotifeeLibNoThrowForKeepCallAlive() {
39
+ if (!lib) {
40
+ const logger = videoLoggerSystem.getLogger('getNotifeeLibNoThrow');
41
+ logger.info(
42
+ `${'@notifee/react-native library not installed. It is required to keep call alive in the background for Android. '}${INSTALLATION_INSTRUCTION}`,
43
+ );
44
+ }
37
45
  return lib;
38
46
  }
39
47
 
48
+ export async function getKeepCallAliveForegroundServiceTypes() {
49
+ const types: AndroidForegroundServiceType[] = [
50
+ AndroidForegroundServiceType.FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK,
51
+ ];
52
+ const hasCameraPermission = await PermissionsAndroid.check(
53
+ PermissionsAndroid.PERMISSIONS.CAMERA!,
54
+ );
55
+ if (hasCameraPermission) {
56
+ types.push(AndroidForegroundServiceType.FOREGROUND_SERVICE_TYPE_CAMERA);
57
+ }
58
+ const hasMicrophonePermission = await PermissionsAndroid.check(
59
+ PermissionsAndroid.PERMISSIONS.RECORD_AUDIO!,
60
+ );
61
+ if (hasMicrophonePermission) {
62
+ types.push(AndroidForegroundServiceType.FOREGROUND_SERVICE_TYPE_MICROPHONE);
63
+ }
64
+ return types;
65
+ }
66
+
40
67
  export function getIncomingCallForegroundServiceTypes() {
41
68
  const types: AndroidForegroundServiceType[] = [
42
69
  AndroidForegroundServiceType.FOREGROUND_SERVICE_TYPE_SHORT_SERVICE,
@@ -0,0 +1,17 @@
1
+ export type VoipPushNotificationType =
2
+ typeof import('react-native-voip-push-notification').default;
3
+
4
+ let voipPushNotification: VoipPushNotificationType | undefined;
5
+
6
+ try {
7
+ voipPushNotification = require('react-native-voip-push-notification').default;
8
+ } catch {}
9
+
10
+ export function getVoipPushNotificationLib() {
11
+ if (!voipPushNotification) {
12
+ throw Error(
13
+ "react-native-voip-push-notification library is not installed. Please install it using 'yarn add react-native-voip-push-notification' or 'npm i react-native-voip-push-notification --save'",
14
+ );
15
+ }
16
+ return voipPushNotification;
17
+ }
@@ -0,0 +1,252 @@
1
+ import {
2
+ pushAcceptedIncomingCallCId$,
3
+ voipCallkeepAcceptedCallOnNativeDialerMap$,
4
+ voipCallkeepCallOnForegroundMap$,
5
+ voipPushNotificationCallCId$,
6
+ } from './internal/rxSubjects';
7
+ import { RxUtils, videoLoggerSystem } from '@stream-io/video-client';
8
+ import { getCallKeepLib, getVoipPushNotificationLib } from './libs';
9
+ import type { StreamVideoConfig } from '../StreamVideoRN/types';
10
+ import {
11
+ clearPushWSEventSubscriptions,
12
+ processCallFromPushInBackground,
13
+ } from './internal/utils';
14
+ import { AppState, NativeModules, Platform } from 'react-native';
15
+ import { RTCAudioSession } from '@stream-io/react-native-webrtc';
16
+ import { setPushLogoutCallback } from '../internal/pushLogoutCallback';
17
+
18
+ type PushConfig = NonNullable<StreamVideoConfig['push']>;
19
+
20
+ /**
21
+ * This hook is used to listen to callkeep events and do the necessary actions
22
+ */
23
+ export function setupIosCallKeepEvents(
24
+ pushConfig: NonNullable<StreamVideoConfig['push']>,
25
+ ) {
26
+ if (Platform.OS !== 'ios' || !pushConfig.ios.pushProviderName) {
27
+ return;
28
+ }
29
+ if (!pushConfig.android.incomingCallChannel) {
30
+ // TODO: remove this check and find a better way once we have telecom integration for android
31
+ videoLoggerSystem
32
+ .getLogger('setupIosCallKeepEvents')
33
+ .debug(
34
+ 'android incomingCallChannel is not defined, so skipping the setupIosCallKeepEvents',
35
+ );
36
+ return;
37
+ }
38
+ const logger = videoLoggerSystem.getLogger('setupIosCallKeepEvents');
39
+ const callkeep = getCallKeepLib();
40
+
41
+ async function getCallCid(callUUID: string): Promise<string | undefined> {
42
+ try {
43
+ const call_cid =
44
+ await NativeModules.StreamVideoReactNative.getIncomingCallCid(callUUID);
45
+ // in a case that voipPushNotificationCallCId$ is empty (this should not happen as voipPushNotificationCallCId$ is updated in push reception)]
46
+ // update it with this call_cid
47
+ const voipPushNotificationCallCId = RxUtils.getCurrentValue(
48
+ voipPushNotificationCallCId$,
49
+ );
50
+ if (!voipPushNotificationCallCId) {
51
+ logger.debug(
52
+ `voipPushNotificationCallCId$ is empty, updating it with the call_cid: ${call_cid} for callUUID: ${callUUID}`,
53
+ );
54
+ voipPushNotificationCallCId$.next(call_cid);
55
+ }
56
+ return call_cid;
57
+ } catch {
58
+ logger.debug(
59
+ `Error in getting call cid from native module for callUUID: ${callUUID} - probably the call was already processed, so ignoring this callkeep event`,
60
+ );
61
+ }
62
+ return undefined;
63
+ }
64
+
65
+ function answerCall(callUUID: string) {
66
+ getCallCid(callUUID).then((call_cid) => {
67
+ logger.debug(`answerCall event with call_cid: ${call_cid}`);
68
+ iosCallkeepAcceptCall(call_cid, callUUID);
69
+ });
70
+ }
71
+
72
+ function endCall(callUUID: string) {
73
+ getCallCid(callUUID).then((call_cid) => {
74
+ logger.debug(`endCall event with call_cid: ${call_cid}`);
75
+ iosCallkeepRejectCall(call_cid, callUUID, pushConfig!);
76
+ });
77
+ }
78
+
79
+ /**
80
+ * CallKeep / CallKit audio-session events -> WebRTC (iOS)
81
+ *
82
+ * iOS CallKit is the authority that *activates* and *deactivates* the underlying `AVAudioSession`
83
+ * when a call is answered/ended from the system UI (lock screen, Call UI, Bluetooth, etc).
84
+ *
85
+ * WebRTC on iOS wraps `AVAudioSession` with `RTCAudioSession` and its AudioDeviceModule relies on
86
+ * being notified of those lifecycle transitions to correctly start/stop audio I/O and keep its
87
+ * internal activation state consistent (e.g. activation count, playout/recording start).
88
+ *
89
+ * If these callbacks don’t reach WebRTC, answering via the native dialer UI can result in:
90
+ * - no microphone capture / one-way audio
91
+ * - silent playout until the app forces an audio reconfiguration
92
+ * - flaky audio routing (speaker/earpiece/Bluetooth) across subsequent calls
93
+ *
94
+ * We forward CallKeep’s `didActivateAudioSession` / `didDeactivateAudioSession` events to WebRTC’s
95
+ * `RTCAudioSession.audioSessionDidActivate()` / `audioSessionDidDeactivate()` methods.
96
+ */
97
+ function didActivateAudioSession() {
98
+ logger.debug('didActivateAudioSession');
99
+ RTCAudioSession.audioSessionDidActivate();
100
+ }
101
+
102
+ function didDeactivateAudioSession() {
103
+ logger.debug('didDeactivateAudioSession');
104
+ RTCAudioSession.audioSessionDidDeactivate();
105
+ }
106
+
107
+ function didDisplayIncomingCall(callUUID: string, payload: object) {
108
+ const voipPushNotification = getVoipPushNotificationLib();
109
+ // @ts-expect-error - call_cid is not part of RNCallKeepEventPayload
110
+ const call_cid = payload?.call_cid as string | undefined;
111
+ logger.debug(
112
+ `didDisplayIncomingCall event with callUUID: ${callUUID} call_cid: ${call_cid}`,
113
+ );
114
+ if (call_cid) {
115
+ if (AppState.currentState === 'background') {
116
+ processCallFromPushInBackground(
117
+ pushConfig!,
118
+ call_cid,
119
+ 'backgroundDelivered',
120
+ );
121
+ }
122
+ voipCallkeepCallOnForegroundMap$.next({
123
+ uuid: callUUID,
124
+ cid: call_cid,
125
+ });
126
+ }
127
+ voipPushNotification.onVoipNotificationCompleted(callUUID);
128
+ }
129
+
130
+ const { remove: removeAnswerCall } = callkeep.addEventListener(
131
+ 'answerCall',
132
+ ({ callUUID }) => {
133
+ answerCall(callUUID);
134
+ },
135
+ );
136
+ const { remove: removeEndCall } = callkeep.addEventListener(
137
+ 'endCall',
138
+ ({ callUUID }) => {
139
+ endCall(callUUID);
140
+ },
141
+ );
142
+
143
+ const { remove: removeDisplayIncomingCall } = callkeep.addEventListener(
144
+ 'didDisplayIncomingCall',
145
+ ({ callUUID, payload }) => {
146
+ didDisplayIncomingCall(callUUID, payload);
147
+ },
148
+ );
149
+
150
+ const { remove: removeDidActivateAudioSession } = callkeep.addEventListener(
151
+ 'didActivateAudioSession',
152
+ () => {
153
+ didActivateAudioSession();
154
+ },
155
+ );
156
+
157
+ const { remove: removeDidDeactivateAudioSession } = callkeep.addEventListener(
158
+ 'didDeactivateAudioSession',
159
+ () => {
160
+ didDeactivateAudioSession();
161
+ },
162
+ );
163
+
164
+ const { remove: removeDidLoadWithEvents } = callkeep.addEventListener(
165
+ 'didLoadWithEvents',
166
+ (events) => {
167
+ if (!events || !Array.isArray(events) || events.length < 1) {
168
+ return;
169
+ }
170
+
171
+ events.forEach((event) => {
172
+ const { name, data } = event;
173
+ if (name === 'RNCallKeepDidDisplayIncomingCall') {
174
+ didDisplayIncomingCall(data.callUUID, data.payload);
175
+ } else if (name === 'RNCallKeepPerformAnswerCallAction') {
176
+ answerCall(data.callUUID);
177
+ } else if (name === 'RNCallKeepPerformEndCallAction') {
178
+ endCall(data.callUUID);
179
+ } else if (name === 'RNCallKeepDidActivateAudioSession') {
180
+ didActivateAudioSession();
181
+ } else if (name === 'RNCallKeepDidDeactivateAudioSession') {
182
+ didDeactivateAudioSession();
183
+ }
184
+ });
185
+ },
186
+ );
187
+
188
+ setPushLogoutCallback(async () => {
189
+ removeAnswerCall();
190
+ removeEndCall();
191
+ removeDisplayIncomingCall();
192
+ removeDidActivateAudioSession();
193
+ removeDidDeactivateAudioSession();
194
+ removeDidLoadWithEvents();
195
+ });
196
+ }
197
+
198
+ const iosCallkeepAcceptCall = (
199
+ call_cid: string | undefined,
200
+ callUUIDFromCallkeep: string,
201
+ ) => {
202
+ if (!shouldProcessCallFromCallkeep(call_cid, callUUIDFromCallkeep)) {
203
+ return;
204
+ }
205
+ clearPushWSEventSubscriptions(call_cid);
206
+ // to call end callkeep later if ended in app and not through callkeep
207
+ voipCallkeepAcceptedCallOnNativeDialerMap$.next({
208
+ uuid: callUUIDFromCallkeep,
209
+ cid: call_cid,
210
+ });
211
+ // to process the call in the app
212
+ pushAcceptedIncomingCallCId$.next(call_cid);
213
+ // no need to keep these references anymore
214
+ voipCallkeepCallOnForegroundMap$.next(undefined);
215
+ };
216
+
217
+ const iosCallkeepRejectCall = async (
218
+ call_cid: string | undefined,
219
+ callUUIDFromCallkeep: string,
220
+ pushConfig: PushConfig,
221
+ ) => {
222
+ if (!shouldProcessCallFromCallkeep(call_cid, callUUIDFromCallkeep)) {
223
+ return;
224
+ }
225
+ clearPushWSEventSubscriptions(call_cid);
226
+ // remove the references if the call_cid matches
227
+ const voipPushNotificationCallCId = RxUtils.getCurrentValue(
228
+ voipPushNotificationCallCId$,
229
+ );
230
+ if (voipPushNotificationCallCId === call_cid) {
231
+ voipCallkeepAcceptedCallOnNativeDialerMap$.next(undefined);
232
+ voipCallkeepCallOnForegroundMap$.next(undefined);
233
+ voipPushNotificationCallCId$.next(undefined);
234
+ }
235
+
236
+ await processCallFromPushInBackground(pushConfig, call_cid, 'decline');
237
+ await NativeModules.StreamVideoReactNative?.removeIncomingCall(call_cid);
238
+ };
239
+
240
+ /**
241
+ * Helper function to determine if the answer/end call event from callkeep must be processed
242
+ * Just checks if we have a valid call_cid and acts as a type guard for call_cid
243
+ */
244
+ const shouldProcessCallFromCallkeep = (
245
+ call_cid: string | undefined,
246
+ callUUIDFromCallkeep: string,
247
+ ): call_cid is string => {
248
+ if (!call_cid || !callUUIDFromCallkeep) {
249
+ return false;
250
+ }
251
+ return true;
252
+ };
@@ -1,11 +1,10 @@
1
- // import { getVoipPushNotificationLib } from './libs';
1
+ import { getVoipPushNotificationLib } from './libs';
2
2
 
3
3
  import { Platform } from 'react-native';
4
4
  import { onVoipNotificationReceived } from './internal/ios';
5
5
  import { setPushLogoutCallback } from '../internal/pushLogoutCallback';
6
6
  import { StreamVideoConfig } from '../StreamVideoRN/types';
7
7
  import { videoLoggerSystem } from '@stream-io/video-client';
8
- import { getCallingxLib } from './libs';
9
8
 
10
9
  export function setupIosVoipPushEvents(
11
10
  pushConfig: NonNullable<StreamVideoConfig['push']>,
@@ -21,19 +20,16 @@ export function setupIosVoipPushEvents(
21
20
  );
22
21
  return;
23
22
  }
23
+ const voipPushNotification = getVoipPushNotificationLib();
24
24
 
25
- const callingx = getCallingxLib();
26
- const voipNotificationReceivedListener = callingx.addEventListener(
27
- 'voipNotificationReceived',
28
- (params) => {
29
- onVoipNotificationReceived(params, pushConfig);
30
- },
31
- );
32
-
25
+ logger.debug('notification event listener added');
26
+ voipPushNotification.addEventListener('notification', (notification) => {
27
+ onVoipNotificationReceived(notification, pushConfig);
28
+ });
33
29
  setPushLogoutCallback(async () => {
34
30
  videoLoggerSystem
35
31
  .getLogger('setPushLogoutCallback')
36
32
  .debug('notification event listener removed');
37
- voipNotificationReceivedListener.remove();
33
+ voipPushNotification.removeEventListener('notification');
38
34
  });
39
35
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.29.0-beta.3';
1
+ export const version = '1.29.1';