forked from react-native-webrtc/react-native-callkeep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.js
70 lines (55 loc) · 2.81 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
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 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 didActivateAudioSession = handler =>
eventEmitter.addListener(RNCallKeepDidActivateAudioSession, handler);
const didDeactivateAudioSession = handler =>
eventEmitter.addListener(RNCallKeepDidDeactivateAudioSession, handler);
const didDisplayIncomingCall = handler =>
eventEmitter.addListener(RNCallKeepDidDisplayIncomingCall, (data) => handler(data));
const didPerformSetMutedCallAction = handler =>
eventEmitter.addListener(RNCallKeepDidPerformSetMutedCallAction, (data) => handler(data));
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);
export const listeners = {
didReceiveStartCallAction,
answerCall,
endCall,
didActivateAudioSession,
didDeactivateAudioSession,
didDisplayIncomingCall,
didPerformSetMutedCallAction,
didToggleHoldCallAction,
didPerformDTMFAction,
didResetProvider,
checkReachability,
};