-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
82 lines (68 loc) · 2.2 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
/**
* @format
*/
import {AppRegistry, Platform} from 'react-native';
import App from './App';
import RNCallKeep from 'react-native-callkeep';
import VoipPushNotification from 'react-native-voip-push-notification';
import {name as appName} from './app.json';
const handleIncomingCall = async () => {};
const handleDecline = () => {};
const options = {
ios: {
appName: 'RN VoIP Demo',
},
android: {
alertTitle: 'Permissions required',
alertDescription: 'This application needs to access your phone accounts',
cancelButton: 'Cancel',
okButton: 'ok',
imageName: 'phone_account_icon',
// Required to get audio in background when using Android 11
foregroundService: {
channelId: 'com.example.rn-voip-demo',
channelName: 'Foreground service for my app',
notificationTitle: 'My app is running on background',
notificationIcon: 'Path to the resource icon of the notification',
},
},
};
RNCallKeep.setup(options).then(accepted => {});
RNCallKeep.addEventListener('answerCall', async () => handleIncomingCall());
RNCallKeep.addEventListener('endCall', async () => handleDecline());
if (Platform.OS === 'ios') {
VoipPushNotification.registerVoipToken();
// Register event listener for VoIP push notifications
VoipPushNotification.addEventListener('register', token => {
// Save token for later use
console.log('token', token);
});
VoipPushNotification.addEventListener('notification', notification => {
// Handle incoming VoIP push notification
handleIncomingCall();
});
VoipPushNotification.addEventListener('didLoadWithEvents', events => {
console.log(events);
if (!events || !Array.isArray(events) || events.length < 1) {
return;
}
for (let voipPushEvent of events) {
let {name, data} = voipPushEvent;
if (
name === VoipPushNotification.RNVoipPushRemoteNotificationReceivedEvent
) {
}
}
});
}
const AppFake = () => {
return null;
};
function HeadlessCheck({isHeadless}) {
if (isHeadless) {
return <AppFake />;
/* Notice this component, it is not the App Component but a different one*/
}
return <App />;
}
AppRegistry.registerComponent(appName, () => HeadlessCheck);