@stream-io/video-react-native-sdk 1.31.1-beta.0 → 1.31.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 (217) hide show
  1. package/CHANGELOG.md +11 -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/Participant/ParticipantView/ParticipantLabel.js +2 -6
  9. package/dist/commonjs/components/Participant/ParticipantView/ParticipantLabel.js.map +1 -1
  10. package/dist/commonjs/hooks/push/index.js +2 -0
  11. package/dist/commonjs/hooks/push/index.js.map +1 -1
  12. package/dist/commonjs/hooks/push/useIosCallkeepWithCallingStateEffect.js +160 -0
  13. package/dist/commonjs/hooks/push/useIosCallkeepWithCallingStateEffect.js.map +1 -0
  14. package/dist/commonjs/hooks/push/useIosVoipPushEventsSetupEffect.js +31 -18
  15. package/dist/commonjs/hooks/push/useIosVoipPushEventsSetupEffect.js.map +1 -1
  16. package/dist/commonjs/hooks/push/useProcessPushCallEffect.js +67 -0
  17. package/dist/commonjs/hooks/push/useProcessPushCallEffect.js.map +1 -0
  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 -35
  27. package/dist/commonjs/utils/StreamVideoRN/index.js.map +1 -1
  28. package/dist/commonjs/utils/internal/registerSDKGlobals.js +3 -53
  29. package/dist/commonjs/utils/internal/registerSDKGlobals.js.map +1 -1
  30. package/dist/commonjs/utils/push/android.js +202 -135
  31. package/dist/commonjs/utils/push/android.js.map +1 -1
  32. package/dist/commonjs/utils/push/internal/ios.js +34 -17
  33. package/dist/commonjs/utils/push/internal/ios.js.map +1 -1
  34. package/dist/commonjs/utils/push/internal/rxSubjects.js +45 -1
  35. package/dist/commonjs/utils/push/internal/rxSubjects.js.map +1 -1
  36. package/dist/commonjs/utils/push/internal/utils.js +53 -71
  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/Participant/ParticipantView/ParticipantLabel.js +2 -6
  54. package/dist/module/components/Participant/ParticipantView/ParticipantLabel.js.map +1 -1
  55. package/dist/module/hooks/push/index.js +2 -0
  56. package/dist/module/hooks/push/index.js.map +1 -1
  57. package/dist/module/hooks/push/useIosCallkeepWithCallingStateEffect.js +153 -0
  58. package/dist/module/hooks/push/useIosCallkeepWithCallingStateEffect.js.map +1 -0
  59. package/dist/module/hooks/push/useIosVoipPushEventsSetupEffect.js +31 -18
  60. package/dist/module/hooks/push/useIosVoipPushEventsSetupEffect.js.map +1 -1
  61. package/dist/module/hooks/push/useProcessPushCallEffect.js +60 -0
  62. package/dist/module/hooks/push/useProcessPushCallEffect.js.map +1 -0
  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 -35
  72. package/dist/module/utils/StreamVideoRN/index.js.map +1 -1
  73. package/dist/module/utils/internal/registerSDKGlobals.js +3 -53
  74. package/dist/module/utils/internal/registerSDKGlobals.js.map +1 -1
  75. package/dist/module/utils/push/android.js +204 -137
  76. package/dist/module/utils/push/android.js.map +1 -1
  77. package/dist/module/utils/push/internal/ios.js +34 -17
  78. package/dist/module/utils/push/internal/ios.js.map +1 -1
  79. package/dist/module/utils/push/internal/rxSubjects.js +44 -0
  80. package/dist/module/utils/push/internal/rxSubjects.js.map +1 -1
  81. package/dist/module/utils/push/internal/utils.js +50 -67
  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/Participant/ParticipantView/ParticipantLabel.d.ts.map +1 -1
  99. package/dist/typescript/hooks/push/index.d.ts.map +1 -1
  100. package/dist/typescript/hooks/push/useIosCallkeepWithCallingStateEffect.d.ts +5 -0
  101. package/dist/typescript/hooks/push/useIosCallkeepWithCallingStateEffect.d.ts.map +1 -0
  102. package/dist/typescript/hooks/push/useIosVoipPushEventsSetupEffect.d.ts.map +1 -1
  103. package/dist/typescript/hooks/push/useProcessPushCallEffect.d.ts +8 -0
  104. package/dist/typescript/hooks/push/useProcessPushCallEffect.d.ts.map +1 -0
  105. package/dist/typescript/hooks/useAndroidKeepCallAliveEffect.d.ts.map +1 -1
  106. package/dist/typescript/index.d.ts +0 -1
  107. package/dist/typescript/index.d.ts.map +1 -1
  108. package/dist/typescript/modules/call-manager/CallManager.d.ts +0 -5
  109. package/dist/typescript/modules/call-manager/CallManager.d.ts.map +1 -1
  110. package/dist/typescript/utils/StreamVideoRN/index.d.ts +2 -22
  111. package/dist/typescript/utils/StreamVideoRN/index.d.ts.map +1 -1
  112. package/dist/typescript/utils/StreamVideoRN/types.d.ts +25 -59
  113. package/dist/typescript/utils/StreamVideoRN/types.d.ts.map +1 -1
  114. package/dist/typescript/utils/internal/registerSDKGlobals.d.ts.map +1 -1
  115. package/dist/typescript/utils/push/android.d.ts +2 -1
  116. package/dist/typescript/utils/push/android.d.ts.map +1 -1
  117. package/dist/typescript/utils/push/internal/ios.d.ts.map +1 -1
  118. package/dist/typescript/utils/push/internal/rxSubjects.d.ts +33 -0
  119. package/dist/typescript/utils/push/internal/rxSubjects.d.ts.map +1 -1
  120. package/dist/typescript/utils/push/internal/utils.d.ts +8 -14
  121. package/dist/typescript/utils/push/internal/utils.d.ts.map +1 -1
  122. package/dist/typescript/utils/push/ios.d.ts +2 -1
  123. package/dist/typescript/utils/push/ios.d.ts.map +1 -1
  124. package/dist/typescript/utils/push/libs/callkeep.d.ts +3 -0
  125. package/dist/typescript/utils/push/libs/callkeep.d.ts.map +1 -0
  126. package/dist/typescript/utils/push/libs/firebaseMessaging/index.d.ts +2 -16
  127. package/dist/typescript/utils/push/libs/firebaseMessaging/index.d.ts.map +1 -1
  128. package/dist/typescript/utils/push/libs/index.d.ts +2 -1
  129. package/dist/typescript/utils/push/libs/index.d.ts.map +1 -1
  130. package/dist/typescript/utils/push/libs/notifee/index.d.ts +1 -0
  131. package/dist/typescript/utils/push/libs/notifee/index.d.ts.map +1 -1
  132. package/dist/typescript/utils/push/libs/voipPushNotification.d.ts +3 -0
  133. package/dist/typescript/utils/push/libs/voipPushNotification.d.ts.map +1 -0
  134. package/dist/typescript/utils/push/setupIosCallKeepEvents.d.ts +6 -0
  135. package/dist/typescript/utils/push/setupIosCallKeepEvents.d.ts.map +1 -0
  136. package/dist/typescript/utils/push/setupIosVoipPushEvents.d.ts.map +1 -1
  137. package/dist/typescript/version.d.ts +1 -1
  138. package/dist/typescript/version.d.ts.map +1 -1
  139. package/expo-config-plugin/dist/withAndroidManifest.js +33 -1
  140. package/expo-config-plugin/dist/withAndroidPermissions.js +7 -2
  141. package/expo-config-plugin/dist/withAppDelegate.js +197 -19
  142. package/expo-config-plugin/dist/withMainActivity.js +1 -1
  143. package/expo-config-plugin/dist/withiOSInfoPlist.js +3 -2
  144. package/ios/StreamInCallManager.m +0 -2
  145. package/ios/StreamInCallManager.swift +7 -19
  146. package/ios/StreamVideoReactNative.h +4 -7
  147. package/ios/StreamVideoReactNative.m +82 -189
  148. package/package.json +16 -11
  149. package/src/components/Participant/ParticipantView/ParticipantLabel.tsx +2 -7
  150. package/src/hooks/push/index.ts +2 -0
  151. package/src/hooks/push/useIosCallkeepWithCallingStateEffect.ts +235 -0
  152. package/src/hooks/push/useIosVoipPushEventsSetupEffect.ts +34 -21
  153. package/src/hooks/push/useProcessPushCallEffect.ts +108 -0
  154. package/src/hooks/useAndroidKeepCallAliveEffect.ts +120 -94
  155. package/src/index.ts +0 -1
  156. package/src/modules/call-manager/CallManager.ts +0 -36
  157. package/src/modules/call-manager/native-module.d.ts +0 -7
  158. package/src/providers/StreamCall/index.tsx +6 -6
  159. package/src/utils/StreamVideoRN/index.ts +30 -42
  160. package/src/utils/StreamVideoRN/types.ts +25 -61
  161. package/src/utils/internal/registerSDKGlobals.ts +4 -52
  162. package/src/utils/push/android.ts +311 -198
  163. package/src/utils/push/internal/ios.ts +44 -28
  164. package/src/utils/push/internal/rxSubjects.ts +61 -0
  165. package/src/utils/push/internal/utils.ts +64 -108
  166. package/src/utils/push/ios.ts +6 -1
  167. package/src/utils/push/libs/callkeep.ts +16 -0
  168. package/src/utils/push/libs/index.ts +2 -1
  169. package/src/utils/push/libs/notifee/index.ts +27 -0
  170. package/src/utils/push/libs/voipPushNotification.ts +17 -0
  171. package/src/utils/push/setupIosCallKeepEvents.ts +252 -0
  172. package/src/utils/push/setupIosVoipPushEvents.ts +7 -11
  173. package/src/version.ts +1 -1
  174. package/android/src/main/java/com/streamvideo/reactnative/keepalive/KeepAliveNotification.kt +0 -83
  175. package/android/src/main/java/com/streamvideo/reactnative/keepalive/StreamCallKeepAliveHeadlessService.kt +0 -149
  176. package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js +0 -144
  177. package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js.map +0 -1
  178. package/dist/commonjs/utils/internal/callingx/audioSessionPromise.js +0 -68
  179. package/dist/commonjs/utils/internal/callingx/audioSessionPromise.js.map +0 -1
  180. package/dist/commonjs/utils/internal/callingx/callingx.js +0 -150
  181. package/dist/commonjs/utils/internal/callingx/callingx.js.map +0 -1
  182. package/dist/commonjs/utils/keepCallAliveHeadlessTask.js +0 -48
  183. package/dist/commonjs/utils/keepCallAliveHeadlessTask.js.map +0 -1
  184. package/dist/commonjs/utils/push/libs/callingx.js +0 -75
  185. package/dist/commonjs/utils/push/libs/callingx.js.map +0 -1
  186. package/dist/commonjs/utils/push/setupCallingExpEvents.js +0 -105
  187. package/dist/commonjs/utils/push/setupCallingExpEvents.js.map +0 -1
  188. package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js +0 -137
  189. package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js.map +0 -1
  190. package/dist/module/utils/internal/callingx/audioSessionPromise.js +0 -61
  191. package/dist/module/utils/internal/callingx/audioSessionPromise.js.map +0 -1
  192. package/dist/module/utils/internal/callingx/callingx.js +0 -140
  193. package/dist/module/utils/internal/callingx/callingx.js.map +0 -1
  194. package/dist/module/utils/keepCallAliveHeadlessTask.js +0 -42
  195. package/dist/module/utils/keepCallAliveHeadlessTask.js.map +0 -1
  196. package/dist/module/utils/push/libs/callingx.js +0 -67
  197. package/dist/module/utils/push/libs/callingx.js.map +0 -1
  198. package/dist/module/utils/push/setupCallingExpEvents.js +0 -99
  199. package/dist/module/utils/push/setupCallingExpEvents.js.map +0 -1
  200. package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts +0 -5
  201. package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts.map +0 -1
  202. package/dist/typescript/utils/internal/callingx/audioSessionPromise.d.ts +0 -16
  203. package/dist/typescript/utils/internal/callingx/audioSessionPromise.d.ts.map +0 -1
  204. package/dist/typescript/utils/internal/callingx/callingx.d.ts +0 -18
  205. package/dist/typescript/utils/internal/callingx/callingx.d.ts.map +0 -1
  206. package/dist/typescript/utils/keepCallAliveHeadlessTask.d.ts +0 -10
  207. package/dist/typescript/utils/keepCallAliveHeadlessTask.d.ts.map +0 -1
  208. package/dist/typescript/utils/push/libs/callingx.d.ts +0 -9
  209. package/dist/typescript/utils/push/libs/callingx.d.ts.map +0 -1
  210. package/dist/typescript/utils/push/setupCallingExpEvents.d.ts +0 -8
  211. package/dist/typescript/utils/push/setupCallingExpEvents.d.ts.map +0 -1
  212. package/src/hooks/push/useCallingExpWithCallingStateEffect.ts +0 -189
  213. package/src/utils/internal/callingx/audioSessionPromise.ts +0 -65
  214. package/src/utils/internal/callingx/callingx.ts +0 -194
  215. package/src/utils/keepCallAliveHeadlessTask.ts +0 -54
  216. package/src/utils/push/libs/callingx.ts +0 -89
  217. package/src/utils/push/setupCallingExpEvents.ts +0 -135
@@ -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.isCallTracked(call_cid)) {
52
- //same call_cid is already tracked, so we skip the notification
53
- logger.debug(
54
- `the same call_cid ${call_cid} is already tracked, 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,9 +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
- // callingx event listeners (setupCallingExpEvents) will handle accept/reject
124
+ // send the info to this subject, it is listened by callkeep events
125
+ // callkeep events will then accept/reject the call
111
126
  logger.debug(
112
- `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`,
113
128
  );
129
+ voipPushNotificationCallCId$.next(call_cid);
114
130
  };
@@ -8,3 +8,64 @@ import type { NonRingingPushEvent } from '../../StreamVideoRN/types';
8
8
  export const pushNonRingingCallData$ = new BehaviorSubject<
9
9
  { cid: string; type: NonRingingPushEvent } | undefined
10
10
  >(undefined);
11
+
12
+ /**
13
+ * This rxjs subject is used to store the call cid of the accepted incoming call from push notification
14
+ * Note: it is should be subscribed only when a user has connected to the websocket of Stream
15
+ */
16
+ export const pushAcceptedIncomingCallCId$ = new BehaviorSubject<
17
+ string | undefined
18
+ >(undefined);
19
+
20
+ /**
21
+ * This rxjs subject is used to store the call cid of the tapped incoming call from push notification it is neither accepted nor rejected yet
22
+ * Note: it should be subscribed only when a user has connected to the websocket of Stream
23
+ */
24
+ export const pushTappedIncomingCallCId$ = new BehaviorSubject<
25
+ string | undefined
26
+ >(undefined);
27
+
28
+ /**
29
+ * This rxjs subject is used to store the call cid of the delivered incoming call from push notification it is neither accepted nor rejected yet
30
+ * Used so that the call is navigated to when app is open from being killed
31
+ * Note: it should be subscribed only when a user has connected to the websocket of Stream
32
+ */
33
+ export const pushAndroidBackgroundDeliveredIncomingCallCId$ =
34
+ new BehaviorSubject<string | undefined>(undefined);
35
+
36
+ /**
37
+ * This rxjs subject is used to store the call cid of the accepted incoming call from push notification
38
+ * Note: it should be subscribed only when a user has connected to the websocket of Stream
39
+ */
40
+ export const pushRejectedIncomingCallCId$ = new BehaviorSubject<
41
+ string | undefined
42
+ >(undefined);
43
+
44
+ /**
45
+ * This rxjs subject is used to store the call cid of the incoming call from ios voip pushkit notification
46
+ */
47
+ export const voipPushNotificationCallCId$ = new BehaviorSubject<
48
+ string | undefined
49
+ >(undefined);
50
+
51
+ /** The pair of cid of a call and its corresponding uuid created in the native side */
52
+ type CallkeepMap = {
53
+ uuid: string;
54
+ cid: string;
55
+ };
56
+
57
+ /*
58
+ * This rxjs subject should only used to store the CallkeepMap
59
+ * for the incoming call when on foreground
60
+ * or in other words, when we get didDisplayIncomingCall from callkeep lib
61
+ */
62
+ export const voipCallkeepCallOnForegroundMap$ = new BehaviorSubject<
63
+ CallkeepMap | undefined
64
+ >(undefined);
65
+
66
+ /*
67
+ * This rxjs subject should only used to store the CallkeepMap when it was accepted in the native dialer
68
+ */
69
+ export const voipCallkeepAcceptedCallOnNativeDialerMap$ = new BehaviorSubject<
70
+ CallkeepMap | undefined
71
+ >(undefined);
@@ -10,12 +10,9 @@ 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
 
18
- const logger = videoLoggerSystem.getLogger('callingx');
19
16
  type CanAddPushWSSubscriptionsRef = { current: boolean };
20
17
 
21
18
  /**
@@ -27,40 +24,44 @@ export const shouldCallBeEnded = (
27
24
  created_by_id: string | undefined,
28
25
  receiver_id: string | undefined,
29
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
+ */
30
35
  const callSession = callFromPush.state.session;
31
36
  const rejected_by = callSession?.rejected_by;
32
37
  const accepted_by = callSession?.accepted_by;
33
38
  let mustEndCall = false;
34
- let endCallReason: EndCallReason = 'unknown';
35
-
36
- if (callFromPush.state.endedAt) {
37
- mustEndCall = true;
38
- endCallReason = 'remote';
39
- } else if (created_by_id && rejected_by) {
39
+ let callkeepReason = 0;
40
+ if (created_by_id && rejected_by) {
40
41
  if (rejected_by[created_by_id]) {
41
- // call was cancelled by the caller before the receiver could answer
42
+ // call was cancelled by the caller
42
43
  mustEndCall = true;
43
- endCallReason = 'canceled';
44
+ callkeepReason = 2;
44
45
  }
45
46
  } else if (receiver_id && rejected_by) {
46
47
  if (rejected_by[receiver_id]) {
47
48
  // call was rejected by the receiver in some other device
48
49
  mustEndCall = true;
49
- endCallReason = 'rejected';
50
+ callkeepReason = 5;
50
51
  }
51
52
  } else if (receiver_id && accepted_by) {
52
53
  if (accepted_by[receiver_id]) {
53
54
  // call was accepted by the receiver in some other device
54
55
  mustEndCall = true;
55
- endCallReason = 'answeredElsewhere';
56
+ callkeepReason = 4;
56
57
  }
57
58
  }
58
59
  videoLoggerSystem
59
60
  .getLogger('shouldCallBeEnded')
60
61
  .debug(
61
- `callCid: ${callFromPush.cid} mustEndCall: ${mustEndCall} endCallReason: ${endCallReason}`,
62
+ `callCid: ${callFromPush.cid} mustEndCall: ${mustEndCall} callkeepReason: ${callkeepReason}`,
62
63
  );
63
- return { mustEndCall, endCallReason };
64
+ return { mustEndCall, callkeepReason };
64
65
  };
65
66
 
66
67
  /* An action for the notification or callkeep and app does not have JS context setup yet, so we need to do two steps:
@@ -70,95 +71,71 @@ export const shouldCallBeEnded = (
70
71
  export const processCallFromPushInBackground = async (
71
72
  pushConfig: PushConfig,
72
73
  call_cid: string,
73
- action: 'accept' | 'decline' | 'pressed' | 'backgroundDelivered',
74
- /**
75
- * Callback to inform iOS CallKit that the action can be fulfilled
76
- * Needed for iOS CallKit fullfillment of action
77
- * as per ios docs "Instead, wait until you establish a connection and then fulfill the object."
78
- * This means we wait until call.get() is done and call.join() or call.leave() is invoked (not completed) to fulfill the action
79
- */
80
- onIOSActionCanBeFulfilled: (didFail: boolean) => void,
74
+ action: Parameters<typeof processCallFromPush>[2],
81
75
  ) => {
82
76
  let videoClient: StreamVideoClient | undefined;
83
77
 
84
78
  try {
85
79
  videoClient = await pushConfig.createStreamVideoClient();
86
80
  if (!videoClient) {
87
- throw new Error('createStreamVideoClient returned null');
81
+ return;
88
82
  }
89
83
  } catch (e) {
90
- logger.error(
91
- 'processCallFromPushInBackground: failed to create video client',
92
- e,
84
+ const logger = videoLoggerSystem.getLogger(
85
+ 'processCallFromPushInBackground',
93
86
  );
94
- onIOSActionCanBeFulfilled(true);
87
+ logger.error('failed to create video client', e);
95
88
  return;
96
89
  }
90
+ await processCallFromPush(videoClient, call_cid, action, pushConfig);
91
+ };
97
92
 
93
+ /**
94
+ * This function is used process the call from push notifications due to incoming call
95
+ * It does the following steps:
96
+ * 1. Get the call from the client if present or create a new call
97
+ * 2. Fetch the latest state of the call from the server if its not already in ringing state
98
+ * 3. Join or leave the call based on the user's action.
99
+ */
100
+ export const processCallFromPush = async (
101
+ client: StreamVideoClient,
102
+ call_cid: string,
103
+ action: 'accept' | 'decline' | 'pressed' | 'backgroundDelivered',
104
+ pushConfig: PushConfig,
105
+ ) => {
98
106
  let callFromPush: Call;
99
107
  try {
100
- callFromPush = await videoClient.onRingingCall(call_cid);
108
+ callFromPush = await client.onRingingCall(call_cid);
101
109
  } catch (e) {
102
- logger.error(
103
- 'processCallFromPushInBackground: failed to fetch call from push notification',
104
- e,
105
- );
106
- onIOSActionCanBeFulfilled(true);
110
+ const logger = videoLoggerSystem.getLogger('processCallFromPush');
111
+ logger.error('failed to fetch call from push notification', e);
107
112
  return;
108
113
  }
109
- if (action === 'accept') {
110
- if (pushConfig.publishOptions) {
111
- callFromPush.updatePublishOptions(pushConfig.publishOptions);
112
- }
113
- logger.debug(
114
- `joining call from push notification with callCid: ${callFromPush.cid}`,
115
- );
116
- const callingState = callFromPush.state.callingState;
117
- if (
118
- callingState !== CallingState.RINGING &&
119
- callingState !== CallingState.IDLE
120
- ) {
121
- logger.debug(
122
- `skipping join call as it is not in ringing or idle state from push notification. callCid: ${callFromPush.cid}`,
123
- );
124
- onIOSActionCanBeFulfilled(true);
125
- return;
126
- }
127
- try {
128
- onIOSActionCanBeFulfilled(false);
114
+ // note: when action was pressed or delivered, we dont need to do anything as the only thing is to do is to get the call which adds it to the client
115
+ try {
116
+ if (action === 'accept') {
117
+ if (pushConfig.publishOptions) {
118
+ callFromPush.updatePublishOptions(pushConfig.publishOptions);
119
+ }
120
+ videoLoggerSystem
121
+ .getLogger('processCallFromPush')
122
+ .debug(
123
+ `joining call from push notification with callCid: ${callFromPush.cid}`,
124
+ );
129
125
  await callFromPush.join();
130
- } catch (e) {
131
- logger.warn(
132
- 'processCallFromPushInBackground: failed to join call from push notification',
133
- e,
134
- );
135
- }
136
- } else if (action === 'decline') {
137
- const alreadyLeft = callFromPush.state.callingState === CallingState.LEFT;
138
- if (alreadyLeft) {
139
- onIOSActionCanBeFulfilled(false);
140
- return;
141
- }
142
- const canReject =
143
- callFromPush.state.callingState === CallingState.RINGING ||
144
- callFromPush.state.callingState === CallingState.IDLE;
145
- const isCurrentUserMember = callFromPush.state.members.some(
146
- (member) => member.user_id === callFromPush.currentUserId,
147
- );
148
- const reject = canReject && isCurrentUserMember;
149
- logger.debug(
150
- `declining call from push notification with callCid: ${callFromPush.cid} reject: ${reject}`,
151
- );
152
- try {
153
- await callFromPush.leave({ reject, reason: 'decline' });
154
- onIOSActionCanBeFulfilled(false);
155
- } catch (e) {
156
- logger.warn(
157
- 'processCallFromPushInBackground: failed to decline call from push notification',
158
- e,
159
- );
160
- onIOSActionCanBeFulfilled(true);
126
+ } else if (action === 'decline') {
127
+ const canReject =
128
+ callFromPush.state.callingState === CallingState.RINGING;
129
+ videoLoggerSystem
130
+ .getLogger('processCallFromPush')
131
+ .debug(
132
+ `declining call from push notification with callCid: ${callFromPush.cid} reject: ${canReject}`,
133
+ );
134
+ await callFromPush.leave({ reject: canReject, reason: 'decline' });
161
135
  }
136
+ } catch (e) {
137
+ const logger = videoLoggerSystem.getLogger('processCallFromPush');
138
+ logger.warn(`failed to process ${action} call from push notification`, e);
162
139
  }
163
140
  };
164
141
 
@@ -186,13 +163,10 @@ export const processNonIncomingCallFromPush = async (
186
163
  await callFromPush.get();
187
164
  }
188
165
  } catch (e) {
189
- const nonRingingCallLogger = videoLoggerSystem.getLogger(
166
+ const logger = videoLoggerSystem.getLogger(
190
167
  'processNonIncomingCallFromPush',
191
168
  );
192
- nonRingingCallLogger.error(
193
- 'failed to fetch call from push notification',
194
- e,
195
- );
169
+ logger.error('failed to fetch call from push notification', e);
196
170
  return;
197
171
  }
198
172
  onNewCallNotification(callFromPush, nonRingingNotificationType);
@@ -217,21 +191,3 @@ export const clearPushWSEventSubscriptions = (call_cid: string) => {
217
191
  export const canAddPushWSSubscriptionsRef: CanAddPushWSSubscriptionsRef = {
218
192
  current: true,
219
193
  };
220
-
221
- export const canListenToWS = () =>
222
- canAddPushWSSubscriptionsRef.current && AppState.currentState !== 'active';
223
-
224
- export const shouldCallBeClosed = (
225
- call: Call,
226
- pushData: { [key: string]: string | object },
227
- ) => {
228
- const created_by_id = pushData?.created_by_id as string;
229
- const receiver_id = pushData?.receiver_id as string;
230
-
231
- const { mustEndCall, endCallReason } = shouldCallBeEnded(
232
- call,
233
- created_by_id,
234
- receiver_id,
235
- );
236
- return { mustEndCall, endCallReason };
237
- };
@@ -62,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
+ }