-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
102 lines (79 loc) · 3.06 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* @format
*/
import { AppRegistry, Platform } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
import invokeApp from 'react-native-invoke-app';
import messaging from "@react-native-firebase/messaging";
import Incomingvideocall from './src/utils/incoming-video-call';
import Navigation from './src/utils/appNavigation'
import socketServcies from './src/utils/socketServices';
import RNCallKeep from 'react-native-callkeep';
Incomingvideocall.setupCallKeep();
const handleNotifications = (remoteMessage) => {
if (Platform.OS === "ios") return;
const data = remoteMessage;
let callerInfo;
let type = 'unknown';
if (remoteMessage?.data?.info) {
const dataInfo = JSON.parse(data?.data?.info);
callerInfo = dataInfo.callerInfo;
type = dataInfo.type;
}
switch (type) {
case 'CALL_INITIATED':
const incomingCallAnswer = ({ callUUID }) => {
console.log("🚀 ~ file: index.js:34 ~ incomingCallAnswer ~ callUUID:", callUUID)
RNCallKeep.endAllCalls();
Incomingvideocall.backToForeground();
setTimeout(() => {
Navigation.navigate('CheckBiometric', {
isGroup: callerInfo.isGroup ? 1 : 0,
recentparams: {
chatId: callerInfo.chatId,
title: callerInfo.title,
fromHome: true,
participants: callerInfo?.participants,
},
handleNotificationClickGoto: "CallingScreen",
});
}, 1000)
Incomingvideocall.endIncomingcallAnswer(callUUID);
};
const endIncomingCall = () => {
socketServcies.emit('declineCall', callerInfo);
console.log('Ending incoming call');
Incomingvideocall.endIncomingcallAnswer();
};
Incomingvideocall.configure(incomingCallAnswer, endIncomingCall);
// Incomingvideocall.endAllCall();
Incomingvideocall.displayIncomingCall(callerInfo.title);
// Incomingvideocall.backToForeground();
break;
case 'CALL_DECLINED':
Incomingvideocall.endAllCall();
break;
default:
console.log('Other Notifications: Unknown');
}
}
const firebaseListener = async (remoteMessage) => handleNotifications(remoteMessage);
messaging().setBackgroundMessageHandler(firebaseListener);
function HeadlessCheck({ isHeadless }) {
if (isHeadless) {
// App has been launched in the background by iOS, ignore
return null;
}
return <App />;
}
if (Platform.OS === 'android') {
// RNCallKeepBackgroundMessagingService
// RNFirebaseBackgroundMessage
// RNCallKeepBackgroundMessage
AppRegistry.registerHeadlessTask(
'RNFirebaseBackgroundMessage',
() => { invokeApp() }
)
}
AppRegistry.registerComponent(appName, () => HeadlessCheck);