-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathindex.js
More file actions
67 lines (44 loc) · 1.94 KB
/
Copy pathindex.js
File metadata and controls
67 lines (44 loc) · 1.94 KB
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
/**
* @format
*/
import { AppRegistry, DeviceEventEmitter, Linking } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
import messaging from '@react-native-firebase/messaging';
import { showIncomingCallNotification } from './src/localNotification/LocalNotification';
import RNNotificationCall from 'react-native-full-screen-notification-incoming-call';
import { loadUser } from './src/hook/api';
import notifee, { AndroidImportance, EventType } from '@notifee/react-native';
notifee.onBackgroundEvent(async ({ type, detail }) => {
if (type === EventType.ACTION_PRESS) {
if (detail.pressAction.id === 'answer') {
// Handle answering the call
console.log('User answered the call');
const userData = await loadUser();
console.log(userData?.user?.phone, userData?.user?.code);
if (userData?.user) {
const phone = userData.user.phone;
const roomId = userData.user.code;
const link = `videocall://video-call/${phone}/${roomId}`;
console.log(link);
// Open the deep link
Linking.openURL(link)
.catch(err => console.error('Failed to open URL:', err));
console.log("Call connection successful");
}
} else if (detail.pressAction.id === 'decline') {
// Handle declining the call
console.log('User declined the call');
}
}
});
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
console.log('Message handled in the background!', remoteMessage);
const { data } = remoteMessage;
if (data && data.type === 'call') { // Ensure it's a call notification
console.log('Displaying incoming call:', data);
showIncomingCallNotification()
}
});
// Register the main application component
AppRegistry.registerComponent(appName, () => App);