@stream-io/video-react-native-sdk 1.31.1 → 1.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/android/src/main/AndroidManifest.xml +8 -1
- package/android/src/main/AndroidManifestNew.xml +11 -0
- package/android/src/main/java/com/streamvideo/reactnative/StreamVideoReactNativeModule.kt +42 -5
- package/android/src/main/java/com/streamvideo/reactnative/audio/utils/WebRtcAudioUtils.kt +70 -6
- package/android/src/main/java/com/streamvideo/reactnative/callmanager/StreamInCallManagerModule.kt +6 -4
- package/android/src/main/java/com/streamvideo/reactnative/keepalive/KeepAliveNotification.kt +83 -0
- package/android/src/main/java/com/streamvideo/reactnative/keepalive/StreamCallKeepAliveHeadlessService.kt +149 -0
- package/dist/commonjs/hooks/push/index.js +0 -2
- package/dist/commonjs/hooks/push/index.js.map +1 -1
- package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js +146 -0
- package/dist/commonjs/hooks/push/useCallingExpWithCallingStateEffect.js.map +1 -0
- package/dist/commonjs/hooks/push/useIosVoipPushEventsSetupEffect.js +18 -31
- package/dist/commonjs/hooks/push/useIosVoipPushEventsSetupEffect.js.map +1 -1
- package/dist/commonjs/hooks/useAndroidKeepCallAliveEffect.js +41 -106
- package/dist/commonjs/hooks/useAndroidKeepCallAliveEffect.js.map +1 -1
- package/dist/commonjs/index.js +1 -0
- package/dist/commonjs/index.js.map +1 -1
- package/dist/commonjs/modules/call-manager/CallManager.js +26 -0
- package/dist/commonjs/modules/call-manager/CallManager.js.map +1 -1
- package/dist/commonjs/providers/StreamCall/index.js +6 -6
- package/dist/commonjs/providers/StreamCall/index.js.map +1 -1
- package/dist/commonjs/utils/StreamVideoRN/index.js +35 -21
- package/dist/commonjs/utils/StreamVideoRN/index.js.map +1 -1
- package/dist/commonjs/utils/internal/callingx/audioSessionPromise.js +68 -0
- package/dist/commonjs/utils/internal/callingx/audioSessionPromise.js.map +1 -0
- package/dist/commonjs/utils/internal/callingx/callingx.js +150 -0
- package/dist/commonjs/utils/internal/callingx/callingx.js.map +1 -0
- package/dist/commonjs/utils/internal/registerSDKGlobals.js +53 -3
- package/dist/commonjs/utils/internal/registerSDKGlobals.js.map +1 -1
- package/dist/commonjs/utils/keepCallAliveHeadlessTask.js +48 -0
- package/dist/commonjs/utils/keepCallAliveHeadlessTask.js.map +1 -0
- package/dist/commonjs/utils/push/android.js +135 -202
- package/dist/commonjs/utils/push/android.js.map +1 -1
- package/dist/commonjs/utils/push/internal/ios.js +17 -34
- package/dist/commonjs/utils/push/internal/ios.js.map +1 -1
- package/dist/commonjs/utils/push/internal/rxSubjects.js +1 -45
- package/dist/commonjs/utils/push/internal/rxSubjects.js.map +1 -1
- package/dist/commonjs/utils/push/internal/utils.js +71 -53
- package/dist/commonjs/utils/push/internal/utils.js.map +1 -1
- package/dist/commonjs/utils/push/ios.js.map +1 -1
- package/dist/commonjs/utils/push/libs/callingx.js +75 -0
- package/dist/commonjs/utils/push/libs/callingx.js.map +1 -0
- package/dist/commonjs/utils/push/libs/index.js +8 -19
- package/dist/commonjs/utils/push/libs/index.js.map +1 -1
- package/dist/commonjs/utils/push/libs/notifee/index.js +0 -23
- package/dist/commonjs/utils/push/libs/notifee/index.js.map +1 -1
- package/dist/commonjs/utils/push/setupCallingExpEvents.js +105 -0
- package/dist/commonjs/utils/push/setupCallingExpEvents.js.map +1 -0
- package/dist/commonjs/utils/push/setupIosVoipPushEvents.js +7 -6
- package/dist/commonjs/utils/push/setupIosVoipPushEvents.js.map +1 -1
- package/dist/commonjs/version.js +1 -1
- package/dist/module/hooks/push/index.js +0 -2
- package/dist/module/hooks/push/index.js.map +1 -1
- package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js +139 -0
- package/dist/module/hooks/push/useCallingExpWithCallingStateEffect.js.map +1 -0
- package/dist/module/hooks/push/useIosVoipPushEventsSetupEffect.js +18 -31
- package/dist/module/hooks/push/useIosVoipPushEventsSetupEffect.js.map +1 -1
- package/dist/module/hooks/useAndroidKeepCallAliveEffect.js +42 -107
- package/dist/module/hooks/useAndroidKeepCallAliveEffect.js.map +1 -1
- package/dist/module/index.js +1 -0
- package/dist/module/index.js.map +1 -1
- package/dist/module/modules/call-manager/CallManager.js +26 -0
- package/dist/module/modules/call-manager/CallManager.js.map +1 -1
- package/dist/module/providers/StreamCall/index.js +6 -6
- package/dist/module/providers/StreamCall/index.js.map +1 -1
- package/dist/module/utils/StreamVideoRN/index.js +35 -21
- package/dist/module/utils/StreamVideoRN/index.js.map +1 -1
- package/dist/module/utils/internal/callingx/audioSessionPromise.js +61 -0
- package/dist/module/utils/internal/callingx/audioSessionPromise.js.map +1 -0
- package/dist/module/utils/internal/callingx/callingx.js +140 -0
- package/dist/module/utils/internal/callingx/callingx.js.map +1 -0
- package/dist/module/utils/internal/registerSDKGlobals.js +53 -3
- package/dist/module/utils/internal/registerSDKGlobals.js.map +1 -1
- package/dist/module/utils/keepCallAliveHeadlessTask.js +42 -0
- package/dist/module/utils/keepCallAliveHeadlessTask.js.map +1 -0
- package/dist/module/utils/push/android.js +137 -204
- package/dist/module/utils/push/android.js.map +1 -1
- package/dist/module/utils/push/internal/ios.js +17 -34
- package/dist/module/utils/push/internal/ios.js.map +1 -1
- package/dist/module/utils/push/internal/rxSubjects.js +0 -44
- package/dist/module/utils/push/internal/rxSubjects.js.map +1 -1
- package/dist/module/utils/push/internal/utils.js +67 -50
- package/dist/module/utils/push/internal/utils.js.map +1 -1
- package/dist/module/utils/push/ios.js.map +1 -1
- package/dist/module/utils/push/libs/callingx.js +67 -0
- package/dist/module/utils/push/libs/callingx.js.map +1 -0
- package/dist/module/utils/push/libs/index.js +1 -2
- package/dist/module/utils/push/libs/index.js.map +1 -1
- package/dist/module/utils/push/libs/notifee/index.js +0 -21
- package/dist/module/utils/push/libs/notifee/index.js.map +1 -1
- package/dist/module/utils/push/setupCallingExpEvents.js +99 -0
- package/dist/module/utils/push/setupCallingExpEvents.js.map +1 -0
- package/dist/module/utils/push/setupIosVoipPushEvents.js +7 -6
- package/dist/module/utils/push/setupIosVoipPushEvents.js.map +1 -1
- package/dist/module/version.js +1 -1
- package/dist/typescript/hooks/push/index.d.ts.map +1 -1
- package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts +5 -0
- package/dist/typescript/hooks/push/useCallingExpWithCallingStateEffect.d.ts.map +1 -0
- package/dist/typescript/hooks/push/useIosVoipPushEventsSetupEffect.d.ts.map +1 -1
- package/dist/typescript/hooks/useAndroidKeepCallAliveEffect.d.ts.map +1 -1
- package/dist/typescript/index.d.ts +1 -0
- package/dist/typescript/index.d.ts.map +1 -1
- package/dist/typescript/modules/call-manager/CallManager.d.ts +5 -0
- package/dist/typescript/modules/call-manager/CallManager.d.ts.map +1 -1
- package/dist/typescript/utils/StreamVideoRN/index.d.ts +22 -2
- package/dist/typescript/utils/StreamVideoRN/index.d.ts.map +1 -1
- package/dist/typescript/utils/StreamVideoRN/types.d.ts +59 -25
- package/dist/typescript/utils/StreamVideoRN/types.d.ts.map +1 -1
- package/dist/typescript/utils/internal/callingx/audioSessionPromise.d.ts +16 -0
- package/dist/typescript/utils/internal/callingx/audioSessionPromise.d.ts.map +1 -0
- package/dist/typescript/utils/internal/callingx/callingx.d.ts +18 -0
- package/dist/typescript/utils/internal/callingx/callingx.d.ts.map +1 -0
- package/dist/typescript/utils/internal/registerSDKGlobals.d.ts.map +1 -1
- package/dist/typescript/utils/keepCallAliveHeadlessTask.d.ts +10 -0
- package/dist/typescript/utils/keepCallAliveHeadlessTask.d.ts.map +1 -0
- package/dist/typescript/utils/push/android.d.ts +1 -2
- package/dist/typescript/utils/push/android.d.ts.map +1 -1
- package/dist/typescript/utils/push/internal/ios.d.ts.map +1 -1
- package/dist/typescript/utils/push/internal/rxSubjects.d.ts +0 -33
- package/dist/typescript/utils/push/internal/rxSubjects.d.ts.map +1 -1
- package/dist/typescript/utils/push/internal/utils.d.ts +14 -8
- package/dist/typescript/utils/push/internal/utils.d.ts.map +1 -1
- package/dist/typescript/utils/push/ios.d.ts +1 -2
- package/dist/typescript/utils/push/ios.d.ts.map +1 -1
- package/dist/typescript/utils/push/libs/callingx.d.ts +9 -0
- package/dist/typescript/utils/push/libs/callingx.d.ts.map +1 -0
- package/dist/typescript/utils/push/libs/index.d.ts +1 -2
- package/dist/typescript/utils/push/libs/index.d.ts.map +1 -1
- package/dist/typescript/utils/push/libs/notifee/index.d.ts +0 -2
- package/dist/typescript/utils/push/libs/notifee/index.d.ts.map +1 -1
- package/dist/typescript/utils/push/setupCallingExpEvents.d.ts +8 -0
- package/dist/typescript/utils/push/setupCallingExpEvents.d.ts.map +1 -0
- package/dist/typescript/utils/push/setupIosVoipPushEvents.d.ts.map +1 -1
- package/dist/typescript/version.d.ts +1 -1
- package/expo-config-plugin/dist/withAndroidManifest.js +1 -33
- package/expo-config-plugin/dist/withAndroidPermissions.js +2 -7
- package/expo-config-plugin/dist/withAppDelegate.js +19 -197
- package/expo-config-plugin/dist/withMainActivity.js +1 -1
- package/expo-config-plugin/dist/withiOSInfoPlist.js +2 -3
- package/ios/StreamInCallManager.m +2 -0
- package/ios/StreamInCallManager.swift +19 -7
- package/ios/StreamVideoReactNative-Bridging-Header.h +3 -1
- package/ios/StreamVideoReactNative.h +7 -4
- package/ios/StreamVideoReactNative.m +199 -84
- package/package.json +11 -16
- package/src/hooks/push/index.ts +0 -2
- package/src/hooks/push/useCallingExpWithCallingStateEffect.ts +193 -0
- package/src/hooks/push/useIosVoipPushEventsSetupEffect.ts +21 -34
- package/src/hooks/useAndroidKeepCallAliveEffect.ts +63 -129
- package/src/index.ts +1 -0
- package/src/modules/call-manager/CallManager.ts +36 -0
- package/src/modules/call-manager/native-module.d.ts +7 -0
- package/src/providers/StreamCall/index.tsx +6 -6
- package/src/utils/StreamVideoRN/index.ts +42 -30
- package/src/utils/StreamVideoRN/types.ts +61 -25
- package/src/utils/internal/callingx/audioSessionPromise.ts +65 -0
- package/src/utils/internal/callingx/callingx.ts +197 -0
- package/src/utils/internal/registerSDKGlobals.ts +52 -4
- package/src/utils/keepCallAliveHeadlessTask.ts +54 -0
- package/src/utils/push/android.ts +198 -311
- package/src/utils/push/internal/ios.ts +28 -44
- package/src/utils/push/internal/rxSubjects.ts +0 -61
- package/src/utils/push/internal/utils.ts +108 -64
- package/src/utils/push/ios.ts +1 -6
- package/src/utils/push/libs/callingx.ts +89 -0
- package/src/utils/push/libs/index.ts +1 -2
- package/src/utils/push/libs/notifee/index.ts +0 -31
- package/src/utils/push/setupCallingExpEvents.ts +135 -0
- package/src/utils/push/setupIosVoipPushEvents.ts +11 -7
- package/src/version.ts +1 -1
- package/android/src/main/java/com/streamvideo/reactnative/util/CallAliveServiceChecker.kt +0 -95
- package/dist/commonjs/hooks/push/useIosCallkeepWithCallingStateEffect.js +0 -160
- package/dist/commonjs/hooks/push/useIosCallkeepWithCallingStateEffect.js.map +0 -1
- package/dist/commonjs/hooks/push/useProcessPushCallEffect.js +0 -67
- package/dist/commonjs/hooks/push/useProcessPushCallEffect.js.map +0 -1
- package/dist/commonjs/utils/push/libs/callkeep.js +0 -17
- package/dist/commonjs/utils/push/libs/callkeep.js.map +0 -1
- package/dist/commonjs/utils/push/libs/voipPushNotification.js +0 -17
- package/dist/commonjs/utils/push/libs/voipPushNotification.js.map +0 -1
- package/dist/commonjs/utils/push/setupIosCallKeepEvents.js +0 -205
- package/dist/commonjs/utils/push/setupIosCallKeepEvents.js.map +0 -1
- package/dist/module/hooks/push/useIosCallkeepWithCallingStateEffect.js +0 -153
- package/dist/module/hooks/push/useIosCallkeepWithCallingStateEffect.js.map +0 -1
- package/dist/module/hooks/push/useProcessPushCallEffect.js +0 -60
- package/dist/module/hooks/push/useProcessPushCallEffect.js.map +0 -1
- package/dist/module/utils/push/libs/callkeep.js +0 -11
- package/dist/module/utils/push/libs/callkeep.js.map +0 -1
- package/dist/module/utils/push/libs/voipPushNotification.js +0 -11
- package/dist/module/utils/push/libs/voipPushNotification.js.map +0 -1
- package/dist/module/utils/push/setupIosCallKeepEvents.js +0 -199
- package/dist/module/utils/push/setupIosCallKeepEvents.js.map +0 -1
- package/dist/typescript/hooks/push/useIosCallkeepWithCallingStateEffect.d.ts +0 -5
- package/dist/typescript/hooks/push/useIosCallkeepWithCallingStateEffect.d.ts.map +0 -1
- package/dist/typescript/hooks/push/useProcessPushCallEffect.d.ts +0 -8
- package/dist/typescript/hooks/push/useProcessPushCallEffect.d.ts.map +0 -1
- package/dist/typescript/utils/push/libs/callkeep.d.ts +0 -3
- package/dist/typescript/utils/push/libs/callkeep.d.ts.map +0 -1
- package/dist/typescript/utils/push/libs/voipPushNotification.d.ts +0 -3
- package/dist/typescript/utils/push/libs/voipPushNotification.d.ts.map +0 -1
- package/dist/typescript/utils/push/setupIosCallKeepEvents.d.ts +0 -6
- package/dist/typescript/utils/push/setupIosCallKeepEvents.d.ts.map +0 -1
- package/src/hooks/push/useIosCallkeepWithCallingStateEffect.ts +0 -235
- package/src/hooks/push/useProcessPushCallEffect.ts +0 -108
- package/src/utils/push/libs/callkeep.ts +0 -16
- package/src/utils/push/libs/voipPushNotification.ts +0 -17
- package/src/utils/push/setupIosCallKeepEvents.ts +0 -252
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
Call,
|
|
3
2
|
CallingState,
|
|
4
3
|
StreamVideoClient,
|
|
5
4
|
videoLoggerSystem,
|
|
@@ -15,30 +14,15 @@ import {
|
|
|
15
14
|
getExpoNotificationsLibNoThrow,
|
|
16
15
|
getFirebaseMessagingLib,
|
|
17
16
|
getFirebaseMessagingLibNoThrow,
|
|
18
|
-
getIncomingCallForegroundServiceTypes,
|
|
19
17
|
getNotifeeLibThrowIfNotInstalledForPush,
|
|
20
18
|
type NotifeeLib,
|
|
21
19
|
} from './libs';
|
|
22
|
-
import {
|
|
23
|
-
pushAcceptedIncomingCallCId$,
|
|
24
|
-
pushAndroidBackgroundDeliveredIncomingCallCId$,
|
|
25
|
-
pushNonRingingCallData$,
|
|
26
|
-
pushRejectedIncomingCallCId$,
|
|
27
|
-
pushTappedIncomingCallCId$,
|
|
28
|
-
} from './internal/rxSubjects';
|
|
20
|
+
import { pushNonRingingCallData$ } from './internal/rxSubjects';
|
|
29
21
|
import { pushUnsubscriptionCallbacks } from './internal/constants';
|
|
30
|
-
import {
|
|
31
|
-
canAddPushWSSubscriptionsRef,
|
|
32
|
-
clearPushWSEventSubscriptions,
|
|
33
|
-
processCallFromPushInBackground,
|
|
34
|
-
shouldCallBeEnded,
|
|
35
|
-
} from './internal/utils';
|
|
22
|
+
import { canListenToWS, shouldCallBeClosed } from './internal/utils';
|
|
36
23
|
import { setPushLogoutCallback } from '../internal/pushLogoutCallback';
|
|
37
|
-
import { getAndroidDefaultRingtoneUrl } from '../getAndroidDefaultRingtoneUrl';
|
|
38
24
|
import { StreamVideoRN } from '../StreamVideoRN';
|
|
39
|
-
|
|
40
|
-
const ACCEPT_CALL_ACTION_ID = 'accept';
|
|
41
|
-
const DECLINE_CALL_ACTION_ID = 'decline';
|
|
25
|
+
import { getCallingxLib } from './libs/callingx';
|
|
42
26
|
|
|
43
27
|
type PushConfig = NonNullable<StreamVideoConfig['push']>;
|
|
44
28
|
|
|
@@ -107,11 +91,10 @@ export async function initAndroidPushToken(
|
|
|
107
91
|
await setDeviceToken(token);
|
|
108
92
|
}
|
|
109
93
|
}
|
|
110
|
-
|
|
111
|
-
const messaging =
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
: getFirebaseMessagingLib();
|
|
94
|
+
|
|
95
|
+
const messaging = pushConfig.isExpo
|
|
96
|
+
? getFirebaseMessagingLibNoThrow(true)
|
|
97
|
+
: getFirebaseMessagingLib();
|
|
115
98
|
if (messaging) {
|
|
116
99
|
logger.debug(`setting firebase token listeners`);
|
|
117
100
|
const unsubscribe = messaging().onTokenRefresh((refreshedToken) =>
|
|
@@ -127,10 +110,10 @@ export async function initAndroidPushToken(
|
|
|
127
110
|
* Creates notification from the push message data.
|
|
128
111
|
* For Ringing and Non-Ringing calls.
|
|
129
112
|
*/
|
|
113
|
+
|
|
130
114
|
export const firebaseDataHandler = async (
|
|
131
115
|
data: FirebaseMessagingTypes.RemoteMessage['data'],
|
|
132
116
|
) => {
|
|
133
|
-
if (Platform.OS !== 'android') return;
|
|
134
117
|
/* Example data from firebase
|
|
135
118
|
"message": {
|
|
136
119
|
"data": {
|
|
@@ -146,227 +129,217 @@ export const firebaseDataHandler = async (
|
|
|
146
129
|
// other stuff
|
|
147
130
|
}
|
|
148
131
|
*/
|
|
132
|
+
if (Platform.OS !== 'android') return;
|
|
133
|
+
|
|
134
|
+
const logger = videoLoggerSystem.getLogger('firebaseDataHandler');
|
|
149
135
|
const pushConfig = StreamVideoRN.getConfig().push;
|
|
150
136
|
if (!pushConfig || !data || data.sender !== 'stream.video') {
|
|
151
137
|
return;
|
|
152
138
|
}
|
|
153
|
-
const notifeeLib = getNotifeeLibThrowIfNotInstalledForPush();
|
|
154
|
-
const notifee = notifeeLib.default;
|
|
155
|
-
const settings = await notifee.getNotificationSettings();
|
|
156
|
-
if (settings.authorizationStatus !== 1) {
|
|
157
|
-
const logger = videoLoggerSystem.getLogger('firebaseDataHandler');
|
|
158
|
-
logger.debug(
|
|
159
|
-
`Notification permission not granted, unable to post ${data.type} notifications`,
|
|
160
|
-
);
|
|
161
|
-
return;
|
|
162
|
-
}
|
|
163
139
|
|
|
164
140
|
if (data.type === 'call.ring') {
|
|
165
141
|
const call_cid = data.call_cid as string;
|
|
166
|
-
const
|
|
167
|
-
const receiver_id = data.receiver_id as string;
|
|
168
|
-
|
|
169
|
-
const video_client = await pushConfig.createStreamVideoClient();
|
|
170
|
-
await video_client?.onRingingCall(call_cid);
|
|
142
|
+
const callingx = getCallingxLib();
|
|
171
143
|
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
receiver_id,
|
|
144
|
+
const client = await pushConfig.createStreamVideoClient();
|
|
145
|
+
if (!client) {
|
|
146
|
+
logger.debug(
|
|
147
|
+
`video client not found, skipping the call.ring notification`,
|
|
177
148
|
);
|
|
178
|
-
|
|
179
|
-
|
|
149
|
+
await callingx.stopService();
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
180
152
|
|
|
181
|
-
const canListenToWS = () =>
|
|
182
|
-
canAddPushWSSubscriptionsRef.current &&
|
|
183
|
-
AppState.currentState !== 'active';
|
|
184
153
|
const asForegroundService = canListenToWS();
|
|
185
154
|
|
|
186
155
|
if (asForegroundService) {
|
|
187
156
|
// Listen to call events from WS through fg service
|
|
188
157
|
// note: this will replace the current empty fg service runner
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
158
|
+
//we need to start service (e.g. by calling display incoming call) and than launch bg task, consider making those steps independent
|
|
159
|
+
await callingx.startBackgroundTask((_: unknown, stopTask: () => void) => {
|
|
160
|
+
return new Promise((resolve) => {
|
|
161
|
+
const finishBackgroundTask = () => {
|
|
162
|
+
callingx.log(
|
|
163
|
+
`Finishing background task for callCid: ${call_cid}`,
|
|
164
|
+
'debug',
|
|
165
|
+
);
|
|
166
|
+
resolve(undefined);
|
|
167
|
+
stopTask();
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
(async () => {
|
|
171
|
+
try {
|
|
172
|
+
const _client = await pushConfig.createStreamVideoClient();
|
|
173
|
+
if (!_client) {
|
|
174
|
+
logger.debug(
|
|
175
|
+
`Closing fg service as there is no client to create from push config`,
|
|
176
|
+
);
|
|
177
|
+
finishBackgroundTask();
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const callFromPush = await _client.onRingingCall(call_cid);
|
|
182
|
+
const { mustEndCall, endCallReason } = shouldCallBeClosed(
|
|
183
|
+
callFromPush,
|
|
184
|
+
data,
|
|
208
185
|
);
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const unsubscribeFunctions: Array<() => void> = [];
|
|
213
|
-
// check if service needs to be closed if accept/decline event was done on another device
|
|
214
|
-
const unsubscribe = callFromPush.on('all', (event) => {
|
|
215
|
-
const _canListenToWS = canListenToWS();
|
|
216
|
-
if (!_canListenToWS) {
|
|
217
|
-
videoLoggerSystem
|
|
218
|
-
.getLogger('firebaseMessagingOnMessageHandler')
|
|
219
|
-
.debug(
|
|
220
|
-
`Closing fg service from event callCid: ${call_cid} canListenToWS: ${_canListenToWS}`,
|
|
221
|
-
{ event },
|
|
186
|
+
if (mustEndCall) {
|
|
187
|
+
logger.debug(
|
|
188
|
+
`Closing fg service callCid: ${call_cid} endCallReason: ${endCallReason}`,
|
|
222
189
|
);
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
_shouldCallBeClosed = shouldCallBeClosed(callFromPush);
|
|
228
|
-
if (_shouldCallBeClosed) {
|
|
229
|
-
videoLoggerSystem
|
|
230
|
-
.getLogger('firebaseMessagingOnMessageHandler')
|
|
231
|
-
.debug(
|
|
232
|
-
`Closing fg service from event callCid: ${call_cid} canListenToWS: ${_canListenToWS} shouldCallBeClosed: ${_shouldCallBeClosed}`,
|
|
233
|
-
{ event },
|
|
190
|
+
|
|
191
|
+
callingx.log(
|
|
192
|
+
`Ending call with callCid: ${call_cid} endCallReason: ${endCallReason}`,
|
|
193
|
+
'debug',
|
|
234
194
|
);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
});
|
|
239
|
-
// check if service needs to be closed if call was left
|
|
240
|
-
const subscription = callFromPush.state.callingState$.subscribe(
|
|
241
|
-
(callingState) => {
|
|
242
|
-
if (
|
|
243
|
-
callingState === CallingState.IDLE ||
|
|
244
|
-
callingState === CallingState.LEFT
|
|
245
|
-
) {
|
|
246
|
-
videoLoggerSystem
|
|
247
|
-
.getLogger('firebaseMessagingOnMessageHandler')
|
|
248
|
-
.debug(
|
|
249
|
-
`Closing fg service from callingState callCid: ${call_cid} callingState: ${callingState}`,
|
|
250
|
-
);
|
|
251
|
-
unsubscribeFunctions.forEach((fn) => fn());
|
|
252
|
-
notifee.stopForegroundService();
|
|
195
|
+
callingx.endCallWithReason(call_cid, endCallReason);
|
|
196
|
+
resolve(undefined);
|
|
197
|
+
return;
|
|
253
198
|
}
|
|
254
|
-
},
|
|
255
|
-
);
|
|
256
|
-
unsubscribeFunctions.push(unsubscribe);
|
|
257
|
-
unsubscribeFunctions.push(() => subscription.unsubscribe());
|
|
258
|
-
pushUnsubscriptionCallbacks.get(call_cid)?.forEach((cb) => cb());
|
|
259
|
-
pushUnsubscriptionCallbacks.set(call_cid, unsubscribeFunctions);
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
}
|
|
263
|
-
const incomingCallChannel = pushConfig.android.incomingCallChannel;
|
|
264
|
-
const incomingCallNotificationTextGetters =
|
|
265
|
-
pushConfig.android.incomingCallNotificationTextGetters;
|
|
266
|
-
if (!incomingCallChannel || !incomingCallNotificationTextGetters) {
|
|
267
|
-
const logger = videoLoggerSystem.getLogger(
|
|
268
|
-
'firebaseMessagingOnMessageHandler',
|
|
269
|
-
);
|
|
270
|
-
logger.error(
|
|
271
|
-
"Can't show incoming call notification as either or both incomingCallChannel and incomingCallNotificationTextGetters were not provided",
|
|
272
|
-
);
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
/*
|
|
276
|
-
* Sound has to be set on channel level for android 8 and above and cant be updated later after creation!
|
|
277
|
-
* For android 7 and below, sound should be set on notification level
|
|
278
|
-
*/
|
|
279
|
-
// set default ringtone if not provided
|
|
280
|
-
if (!incomingCallChannel.sound) {
|
|
281
|
-
incomingCallChannel.sound = await getAndroidDefaultRingtoneUrl();
|
|
282
|
-
}
|
|
283
|
-
await notifee.createChannel(incomingCallChannel);
|
|
284
|
-
const { getTitle, getBody, getAcceptButtonTitle, getDeclineButtonTitle } =
|
|
285
|
-
incomingCallNotificationTextGetters;
|
|
286
|
-
const createdUserName = data.created_by_display_name as string;
|
|
287
199
|
|
|
288
|
-
|
|
289
|
-
|
|
200
|
+
const unsubscribeFunctions: Array<() => void> = [];
|
|
201
|
+
// check if service needs to be closed if accept/decline event was done on another device
|
|
202
|
+
const unsubscribe = callFromPush.on('all', (event) => {
|
|
203
|
+
const _canListenToWS = canListenToWS();
|
|
204
|
+
if (!_canListenToWS) {
|
|
205
|
+
logger.debug(
|
|
206
|
+
`Closing fg service from event callCid: ${call_cid} canListenToWS: ${_canListenToWS}`,
|
|
207
|
+
{ event },
|
|
208
|
+
);
|
|
209
|
+
unsubscribeFunctions.forEach((fn) => fn());
|
|
290
210
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
`Displaying incoming call notification with callCid: ${call_cid} title: ${title} body: ${body} asForegroundService: ${asForegroundService}`,
|
|
295
|
-
);
|
|
211
|
+
finishBackgroundTask();
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
296
214
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
215
|
+
const {
|
|
216
|
+
mustEndCall: mustEndCallFromEvent,
|
|
217
|
+
endCallReason: endCallReasonFromEvent,
|
|
218
|
+
} = shouldCallBeClosed(callFromPush, data);
|
|
219
|
+
if (mustEndCallFromEvent) {
|
|
220
|
+
logger.debug(
|
|
221
|
+
`Closing fg service from event callCid: ${call_cid} canListenToWS: ${_canListenToWS} shouldCallBeClosed`,
|
|
222
|
+
{ event },
|
|
223
|
+
);
|
|
224
|
+
unsubscribeFunctions.forEach((fn) => fn());
|
|
225
|
+
|
|
226
|
+
callingx.endCallWithReason(call_cid, endCallReasonFromEvent);
|
|
227
|
+
resolve(undefined);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// check if service needs to be closed if call was left
|
|
232
|
+
const stateSubscription =
|
|
233
|
+
callFromPush.state.callingState$.subscribe((callingState) => {
|
|
234
|
+
if (
|
|
235
|
+
callingState === CallingState.IDLE ||
|
|
236
|
+
callingState === CallingState.LEFT
|
|
237
|
+
) {
|
|
238
|
+
logger.debug(
|
|
239
|
+
`Closing fg service from callingState callCid: ${call_cid} callingState: ${callingState}`,
|
|
240
|
+
);
|
|
241
|
+
unsubscribeFunctions.forEach((fn) => fn());
|
|
242
|
+
callingx.log(
|
|
243
|
+
`Ending call with callCid: ${call_cid} callingState: ${callingState}`,
|
|
244
|
+
'debug',
|
|
245
|
+
);
|
|
246
|
+
resolve(undefined);
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
const endCallSubscription = callingx.addEventListener(
|
|
251
|
+
'endCall',
|
|
252
|
+
async ({ callId }: { callId: string }) => {
|
|
253
|
+
unsubscribeFunctions.forEach((fn) => fn());
|
|
254
|
+
try {
|
|
255
|
+
await callFromPush.leave({
|
|
256
|
+
reject:
|
|
257
|
+
callFromPush.state.callingState ===
|
|
258
|
+
CallingState.RINGING,
|
|
259
|
+
reason: 'decline',
|
|
260
|
+
});
|
|
261
|
+
} catch (error) {
|
|
262
|
+
logger.error(
|
|
263
|
+
`Failed to leave call with callCid: ${call_cid} error: ${error}`,
|
|
264
|
+
);
|
|
265
|
+
} finally {
|
|
266
|
+
callingx.log(
|
|
267
|
+
`Ending call with callCid: ${call_cid} callId: ${callId}`,
|
|
268
|
+
'debug',
|
|
269
|
+
);
|
|
270
|
+
resolve(undefined);
|
|
271
|
+
}
|
|
272
|
+
},
|
|
273
|
+
);
|
|
274
|
+
|
|
275
|
+
//stop background task when app comes to foreground
|
|
276
|
+
const appStateSubscription = AppState.addEventListener(
|
|
277
|
+
'change',
|
|
278
|
+
(nextAppState) => {
|
|
279
|
+
const _canListenToWS = canListenToWS();
|
|
280
|
+
callingx.log(
|
|
281
|
+
`AppState changed to: ${nextAppState} for callCid: ${call_cid} canListenToWS: ${_canListenToWS}`,
|
|
282
|
+
'debug',
|
|
283
|
+
);
|
|
284
|
+
if (!_canListenToWS) {
|
|
285
|
+
unsubscribeFunctions.forEach((fn) => fn());
|
|
286
|
+
finishBackgroundTask();
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
);
|
|
291
|
+
|
|
292
|
+
unsubscribeFunctions.push(unsubscribe);
|
|
293
|
+
unsubscribeFunctions.push(() => stateSubscription.unsubscribe());
|
|
294
|
+
unsubscribeFunctions.push(() => endCallSubscription.remove());
|
|
295
|
+
unsubscribeFunctions.push(() => appStateSubscription.remove());
|
|
296
|
+
pushUnsubscriptionCallbacks.get(call_cid)?.forEach((cb) => cb());
|
|
297
|
+
pushUnsubscriptionCallbacks.set(call_cid, unsubscribeFunctions);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
callingx.log(
|
|
300
|
+
`Failed to start background task with callCid: ${call_cid} error: ${error}`,
|
|
301
|
+
'error',
|
|
302
|
+
);
|
|
303
|
+
finishBackgroundTask();
|
|
304
|
+
}
|
|
305
|
+
})();
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
}
|
|
339
309
|
|
|
340
310
|
if (asForegroundService) {
|
|
341
311
|
// no need to check if call has be closed as that will be handled by the fg service
|
|
342
312
|
return;
|
|
343
313
|
}
|
|
344
314
|
|
|
345
|
-
// check if call needs to be closed if accept/decline event was done
|
|
346
|
-
// before the notification was shown
|
|
347
|
-
const client = await pushConfig.createStreamVideoClient();
|
|
348
|
-
if (!client) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
315
|
const callFromPush = await client.onRingingCall(call_cid);
|
|
352
316
|
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
317
|
+
const { mustEndCall, endCallReason } = shouldCallBeClosed(
|
|
318
|
+
callFromPush,
|
|
319
|
+
data,
|
|
320
|
+
);
|
|
321
|
+
if (mustEndCall) {
|
|
322
|
+
logger.debug(
|
|
323
|
+
`Removing incoming call notification immediately with callCid: ${call_cid} as it should be closed`,
|
|
324
|
+
);
|
|
325
|
+
callingx.endCallWithReason(call_cid, endCallReason);
|
|
360
326
|
}
|
|
361
327
|
} else {
|
|
328
|
+
const notifeeLib = getNotifeeLibThrowIfNotInstalledForPush();
|
|
329
|
+
const notifee = notifeeLib.default;
|
|
330
|
+
const settings = await notifee.getNotificationSettings();
|
|
331
|
+
if (settings.authorizationStatus !== 1) {
|
|
332
|
+
logger.debug(
|
|
333
|
+
`Notification permission not granted, unable to post ${data.type} notifications`,
|
|
334
|
+
);
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
|
|
362
338
|
// the other types are call.live_started and call.notification
|
|
363
339
|
const callChannel = pushConfig.android.callChannel;
|
|
364
340
|
const callNotificationTextGetters =
|
|
365
341
|
pushConfig.android.callNotificationTextGetters;
|
|
366
342
|
if (!callChannel || !callNotificationTextGetters) {
|
|
367
|
-
const logger = videoLoggerSystem.getLogger(
|
|
368
|
-
'firebaseMessagingOnMessageHandler',
|
|
369
|
-
);
|
|
370
343
|
logger.debug(
|
|
371
344
|
"Can't show call notification as either or both callChannel and callNotificationTextGetters is not provided",
|
|
372
345
|
);
|
|
@@ -382,14 +355,12 @@ export const firebaseDataHandler = async (
|
|
|
382
355
|
const title = getTitle(type, createdUserName);
|
|
383
356
|
const body = getBody(type, createdUserName);
|
|
384
357
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
`Displaying NonRingingPushEvent ${type} notification with title: ${title} body: ${body}`,
|
|
389
|
-
);
|
|
358
|
+
logger.debug(
|
|
359
|
+
`Displaying NonRingingPushEvent ${type} notification with title: ${title} body: ${body}`,
|
|
360
|
+
);
|
|
390
361
|
await notifee.displayNotification({
|
|
391
|
-
title
|
|
392
|
-
body
|
|
362
|
+
title,
|
|
363
|
+
body,
|
|
393
364
|
data,
|
|
394
365
|
android: {
|
|
395
366
|
sound: callChannel.sound,
|
|
@@ -409,16 +380,10 @@ export const firebaseDataHandler = async (
|
|
|
409
380
|
}
|
|
410
381
|
};
|
|
411
382
|
|
|
412
|
-
export const onAndroidNotifeeEvent = async ({
|
|
413
|
-
event,
|
|
414
|
-
isBackground,
|
|
415
|
-
}: {
|
|
416
|
-
event: Event;
|
|
417
|
-
isBackground: boolean;
|
|
418
|
-
}) => {
|
|
383
|
+
export const onAndroidNotifeeEvent = async ({ event }: { event: Event }) => {
|
|
419
384
|
if (Platform.OS !== 'android') return;
|
|
420
385
|
const { type, detail } = event;
|
|
421
|
-
const { notification
|
|
386
|
+
const { notification } = detail;
|
|
422
387
|
const notificationId = notification?.id;
|
|
423
388
|
const data = notification?.data;
|
|
424
389
|
const pushConfig = StreamVideoRN.getConfig().push;
|
|
@@ -434,92 +399,14 @@ export const onAndroidNotifeeEvent = async ({
|
|
|
434
399
|
// we can safely cast to string because the data is from "stream.video"
|
|
435
400
|
const call_cid = data.call_cid as string;
|
|
436
401
|
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
const didPressDecline =
|
|
447
|
-
type === notifeeLib.EventType.ACTION_PRESS &&
|
|
448
|
-
pressAction?.id === DECLINE_CALL_ACTION_ID;
|
|
449
|
-
const didDismiss = type === notifeeLib.EventType.DISMISSED;
|
|
450
|
-
const mustDecline = didPressDecline || didDismiss;
|
|
451
|
-
// Check if we need to accept the call
|
|
452
|
-
const mustAccept =
|
|
453
|
-
type === notifeeLib.EventType.ACTION_PRESS &&
|
|
454
|
-
pressAction?.id === ACCEPT_CALL_ACTION_ID;
|
|
455
|
-
|
|
456
|
-
if (
|
|
457
|
-
mustAccept ||
|
|
458
|
-
mustDecline ||
|
|
459
|
-
type === notifeeLib.EventType.ACTION_PRESS
|
|
460
|
-
) {
|
|
461
|
-
videoLoggerSystem
|
|
462
|
-
.getLogger('onAndroidNotifeeEvent')
|
|
463
|
-
.debug(
|
|
464
|
-
`clearPushWSEventSubscriptions for callCId: ${call_cid} mustAccept: ${mustAccept} mustDecline: ${mustDecline}`,
|
|
465
|
-
);
|
|
466
|
-
clearPushWSEventSubscriptions(call_cid);
|
|
467
|
-
notifee.stopForegroundService();
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
if (mustAccept) {
|
|
471
|
-
videoLoggerSystem
|
|
472
|
-
.getLogger('onAndroidNotifeeEvent')
|
|
473
|
-
.debug(`pushAcceptedIncomingCallCId$ added with callCId: ${call_cid}`);
|
|
474
|
-
pushAcceptedIncomingCallCId$.next(call_cid);
|
|
475
|
-
// NOTE: accept will be handled by the app with rxjs observers as the app will go to foreground always
|
|
476
|
-
} else if (mustDecline) {
|
|
477
|
-
videoLoggerSystem
|
|
478
|
-
.getLogger('onAndroidNotifeeEvent')
|
|
479
|
-
.debug(`pushRejectedIncomingCallCId$ added with callCId: ${call_cid}`);
|
|
480
|
-
pushRejectedIncomingCallCId$.next(call_cid);
|
|
481
|
-
if (hasObservers) {
|
|
482
|
-
// if we had observers we can return here as the observers will handle the call as the app is in the foreground state
|
|
483
|
-
videoLoggerSystem
|
|
484
|
-
.getLogger('onAndroidNotifeeEvent')
|
|
485
|
-
.debug(
|
|
486
|
-
`Skipped processCallFromPushInBackground for Declining call with callCId: ${call_cid} as the app is in the foreground state`,
|
|
487
|
-
);
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
videoLoggerSystem
|
|
491
|
-
.getLogger('onAndroidNotifeeEvent')
|
|
492
|
-
.debug(
|
|
493
|
-
`start processCallFromPushInBackground - Declining call with callCId: ${call_cid}`,
|
|
494
|
-
);
|
|
495
|
-
await processCallFromPushInBackground(pushConfig, call_cid, 'decline');
|
|
496
|
-
} else {
|
|
497
|
-
if (type === notifeeLib.EventType.PRESS) {
|
|
498
|
-
videoLoggerSystem
|
|
499
|
-
.getLogger('onAndroidNotifeeEvent')
|
|
500
|
-
.debug(`pushTappedIncomingCallCId$ added with callCId: ${call_cid}`);
|
|
501
|
-
pushTappedIncomingCallCId$.next(call_cid);
|
|
502
|
-
// pressed state will be handled by the app with rxjs observers as the app will go to foreground always
|
|
503
|
-
} else if (isBackground && type === notifeeLib.EventType.DELIVERED) {
|
|
504
|
-
videoLoggerSystem
|
|
505
|
-
.getLogger('onAndroidNotifeeEvent')
|
|
506
|
-
.debug(
|
|
507
|
-
`pushAndroidBackgroundDeliveredIncomingCallCId$ added with callCId: ${call_cid}`,
|
|
508
|
-
);
|
|
509
|
-
pushAndroidBackgroundDeliveredIncomingCallCId$.next(call_cid);
|
|
510
|
-
// background delivered state will be handled by the app with rxjs observers as processing needs to happen only when app is opened
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
} else {
|
|
514
|
-
const notifeeLib = getNotifeeLibThrowIfNotInstalledForPush();
|
|
515
|
-
if (type === notifeeLib.EventType.PRESS) {
|
|
516
|
-
videoLoggerSystem
|
|
517
|
-
.getLogger('onAndroidNotifeeEvent')
|
|
518
|
-
.debug(`onTapNonRingingCallNotification with callCId: ${call_cid}`);
|
|
519
|
-
pushConfig.onTapNonRingingCallNotification?.(
|
|
520
|
-
call_cid,
|
|
521
|
-
data.type as NonRingingPushEvent,
|
|
522
|
-
);
|
|
523
|
-
}
|
|
402
|
+
const notifeeLib = getNotifeeLibThrowIfNotInstalledForPush();
|
|
403
|
+
if (type === notifeeLib.EventType.PRESS) {
|
|
404
|
+
videoLoggerSystem
|
|
405
|
+
.getLogger('onAndroidNotifeeEvent')
|
|
406
|
+
.debug(`onTapNonRingingCallNotification with callCId: ${call_cid}`);
|
|
407
|
+
pushConfig.onTapNonRingingCallNotification?.(
|
|
408
|
+
call_cid,
|
|
409
|
+
data.type as NonRingingPushEvent,
|
|
410
|
+
);
|
|
524
411
|
}
|
|
525
412
|
};
|