forked from priteshrnandgaonkar/react-native-call-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
41 lines (35 loc) · 1.47 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
/*
* @providesModule react-native-call-detection
*/
import { NativeModules, NativeEventEmitter, Platform } from 'react-native'
const BatchedBridge = require('react-native/Libraries/BatchedBridge/BatchedBridge')
const NativeCallDetector = NativeModules.CallDetectionManager
const NativeCallDetectorAndroid = NativeModules.CallDetectionManagerAndroid
var CallStateUpdateActionModule = require('./CallStateUpdateActionModule')
BatchedBridge.registerCallableModule('CallStateUpdateActionModule', CallStateUpdateActionModule)
class CallDetectorManager {
subscription;
callback
constructor(callback) {
this.callback = callback
if (Platform.OS === 'ios') {
NativeCallDetector && NativeCallDetector.startListener()
this.subscription = new NativeEventEmitter(NativeCallDetector)
this.subscription.addListener('PhoneCallStateUpdate', callback);
}
else {
NativeCallDetectorAndroid && NativeCallDetectorAndroid.startListener()
CallStateUpdateActionModule.callback = callback
}
}
dispose() {
NativeCallDetector && NativeCallDetector.stopListener()
NativeCallDetectorAndroid && NativeCallDetectorAndroid.stopListener()
CallStateUpdateActionModule.callback = undefined
if(this.subscription) {
this.subscription.removeAllListeners('PhoneCallStateUpdate');
this.subscription = undefined
}
}
}
export default module.exports = CallDetectorManager;