forked from react-native-webrtc/react-native-callkeep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.js
82 lines (64 loc) · 3.28 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
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 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);
const didLoadWithEvents = handler =>
eventEmitter.addListener(RNCallKeepDidLoadWithEvents, handler);
const showIncomingCallUi = handler =>
eventEmitter.addListener(RNCallKeepShowIncomingCallUi, (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
};