-
Notifications
You must be signed in to change notification settings - Fork 445
/
actions.js
111 lines (89 loc) · 4.41 KB
/
actions.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
103
104
105
106
107
108
109
110
111
import { NativeModules, NativeEventEmitter, Platform } from 'react-native';
const RNCallKeepModule = NativeModules.RNCallKeep;
const eventEmitter = new NativeEventEmitter(RNCallKeepModule);
const RNCallKeepDidReceiveStartCallAction = 'RNCallKeepDidReceiveStartCallAction';
const RNCallKeepPerformAnswerCallAction = 'RNCallKeepPerformAnswerCallAction';
const RNCallKeepPerformEndCallAction = 'RNCallKeepPerformEndCallAction';
const RNCallKeepDidActivateAudioSession = 'RNCallKeepDidActivateAudioSession';
const RNCallKeepDidDeactivateAudioSession = 'RNCallKeepDidDeactivateAudioSession';
const RNCallKeepDidDisplayIncomingCall = 'RNCallKeepDidDisplayIncomingCall';
const RNCallKeepDidPerformSetMutedCallAction = 'RNCallKeepDidPerformSetMutedCallAction';
const RNCallKeepDidToggleHoldAction = 'RNCallKeepDidToggleHoldAction';
const RNCallKeepDidPerformDTMFAction = 'RNCallKeepDidPerformDTMFAction';
const RNCallKeepProviderReset = 'RNCallKeepProviderReset';
const RNCallKeepCheckReachability = 'RNCallKeepCheckReachability';
const RNCallKeepDidLoadWithEvents = 'RNCallKeepDidLoadWithEvents';
const RNCallKeepShowIncomingCallUi = 'RNCallKeepShowIncomingCallUi';
const RNCallKeepOnSilenceIncomingCall = 'RNCallKeepOnSilenceIncomingCall';
const RNCallKeepOnIncomingConnectionFailed = 'RNCallKeepOnIncomingConnectionFailed';
const RNCallKeepDidChangeAudioRoute = 'RNCallKeepDidChangeAudioRoute';
const RNCallKeepHasActiveCall = 'RNCallKeepHasActiveCall';
const isIOS = Platform.OS === 'ios';
const didReceiveStartCallAction = handler => {
if (isIOS) {
// Tell CallKeep that we are ready to receive `RNCallKeepDidReceiveStartCallAction` event and prevent delay
RNCallKeepModule._startCallActionEventListenerAdded();
}
return eventEmitter.addListener(RNCallKeepDidReceiveStartCallAction, (data) => handler(data));
};
const answerCall = handler =>
eventEmitter.addListener(RNCallKeepPerformAnswerCallAction, (data) => handler(data));
const endCall = handler =>
eventEmitter.addListener(RNCallKeepPerformEndCallAction, (data) => handler(data));
const didChangeAudioRoute = handler =>
eventEmitter.addListener(RNCallKeepDidChangeAudioRoute, handler);
const didActivateAudioSession = handler =>
eventEmitter.addListener(RNCallKeepDidActivateAudioSession, handler);
const didDeactivateAudioSession = handler =>
eventEmitter.addListener(RNCallKeepDidDeactivateAudioSession, handler);
const didDisplayIncomingCall = handler => eventEmitter.addListener(RNCallKeepDidDisplayIncomingCall, data => {
// On Android the payload parameter is sent a String
// As it requires too much code on Android to convert it to WritableMap, let's do it here.
if (data.payload && typeof data.payload === 'string') {
try {
data.payload = JSON.parse(data.payload);
} catch (_) {
}
}
handler(data);
});
const didPerformSetMutedCallAction = handler =>
eventEmitter.addListener(RNCallKeepDidPerformSetMutedCallAction, (data) => handler(data));
const onHasActiveCall = handler =>
eventEmitter.addListener(RNCallKeepHasActiveCall, handler);
const didToggleHoldCallAction = handler =>
eventEmitter.addListener(RNCallKeepDidToggleHoldAction, handler);
const didPerformDTMFAction = handler =>
eventEmitter.addListener(RNCallKeepDidPerformDTMFAction, (data) => handler(data));
const didResetProvider = handler =>
eventEmitter.addListener(RNCallKeepProviderReset, handler);
const checkReachability = handler =>
eventEmitter.addListener(RNCallKeepCheckReachability, handler);
const didLoadWithEvents = handler =>
eventEmitter.addListener(RNCallKeepDidLoadWithEvents, handler);
const showIncomingCallUi = handler =>
eventEmitter.addListener(RNCallKeepShowIncomingCallUi, (data) => handler(data));
const silenceIncomingCall = handler =>
eventEmitter.addListener(RNCallKeepOnSilenceIncomingCall, (data) => handler(data));
const createIncomingConnectionFailed = handler =>
eventEmitter.addListener(RNCallKeepOnIncomingConnectionFailed, (data) => handler(data));
export const emit = (eventName, payload) => eventEmitter.emit(eventName, payload);
export const listeners = {
didReceiveStartCallAction,
answerCall,
endCall,
didActivateAudioSession,
didDeactivateAudioSession,
didDisplayIncomingCall,
didPerformSetMutedCallAction,
didToggleHoldCallAction,
didPerformDTMFAction,
didResetProvider,
checkReachability,
didLoadWithEvents,
showIncomingCallUi,
silenceIncomingCall,
createIncomingConnectionFailed,
didChangeAudioRoute,
onHasActiveCall
};