-
Notifications
You must be signed in to change notification settings - Fork 502
Expand file tree
/
Copy pathactions.js
More file actions
62 lines (48 loc) · 2.29 KB
/
actions.js
File metadata and controls
62 lines (48 loc) · 2.29 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
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 RNCallKeepDidDisplayIncomingCall = 'RNCallKeepDidDisplayIncomingCall';
const RNCallKeepDidPerformSetMutedCallAction = 'RNCallKeepDidPerformSetMutedCallAction';
const RNCallKeepDidPerformHoldAction = 'RNCallKeepDidPerformHoldAction';
const RNCallKeepDidPerformUnHoldAction = 'RNCallKeepDidPerformUnHoldAction';
const RNCallKeepDidPerformDTMFAction = 'RNCallKeepDidPerformDTMFAction';
const isIOS = Platform.OS === 'ios';
const didReceiveStartCallAction = handler => {
const listener = eventEmitter.addListener(
RNCallKeepDidReceiveStartCallAction, (data) => {
handler(isIOS ? data : { handle: data.number });
}
);
if (isIOS) {
RNCallKeepModule._startCallActionEventListenerAdded();
}
return listener;
};
const answerCall = handler =>
eventEmitter.addListener(RNCallKeepPerformAnswerCallAction, (data) => handler(isIOS ? data : {}));
const endCall = handler =>
eventEmitter.addListener(RNCallKeepPerformEndCallAction, (data) => handler(isIOS ? data : {}));
const didActivateAudioSession = handler =>
eventEmitter.addListener(RNCallKeepDidActivateAudioSession, handler);
const didDisplayIncomingCall = handler =>
eventEmitter.addListener(RNCallKeepDidDisplayIncomingCall, (data) => handler(isIOS ? data.error : null));
const didPerformSetMutedCallAction = handler =>
eventEmitter.addListener(RNCallKeepDidPerformSetMutedCallAction, (data) => handler(data.muted));
const didPerformDTMFAction = handler =>
eventEmitter.addListener(RNCallKeepDidPerformDTMFAction, (data) => {
const payload = isIOS ? { dtmf: data.digits, callUUID: data.callUUID } : data;
return handler(payload);
});
export const listeners = {
didReceiveStartCallAction,
answerCall,
endCall,
didActivateAudioSession,
didDisplayIncomingCall,
didPerformSetMutedCallAction,
didPerformDTMFAction,
};