@softtee/react-native-call-detector
v1.0.2
Published
This library let you detector call states in your react-native/expo application
Maintainers
Readme
React Native Call Detector
A lightweight React Native utility for listening to native call state changes on Android. This module provides a unified API with TypeScript support and automatic listener cleanup.
Features
Detect incoming, outgoing, missed, rejected, and idle call states
Typed CallEvent and CallData interfaces
Simple subscription system
Easy start/stop lifecycle
Installation
npm install @softtee/react-native-call-detector
# or
yarn add @softtee/react-native-call-detectorUsage
import * as CallDetector from '@softtee/react-native-call-detector';Permissions
let perms = await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.READ_PHONE_STATE,
PermissionsAndroid.PERMISSIONS.READ_CALL_LOG,
PermissionsAndroid.PERMISSIONS.READ_PHONE_NUMBERS,
]);
if (
perms['android.permission.READ_CALL_LOG'] == 'granted' &&
perms['android.permission.READ_PHONE_STATE'] == 'granted'
) {
CallDetector.start();
const unsubscribe = CallDetector.onCallStateChange(({ state, call }) => {
console.log(state, call);
});
unsubscribe()
CallDetector.stop() // stop all listner
}Event Types
CallEvent
interface CallEvent {
state: 'Incoming' | 'Offhook' | 'Idle' | 'Missed' | 'Rejected' | 'Disconnected';
call: CallData;
}CallData
interface CallData {
number: string;
name?: string;
type?: 'INCOMING' | 'OUTGOING' | 'MISSED' | 'REJECTED' | 'UNKNOWN';
date?: string;
duration?: string;
}Example event:
{
"state": "Incoming",
"call": {
"number": "+2349030687052",
"name": "Toheeb Bello",
"type": "INCOMING",
"date": "2025-01-10T12:42:00Z",
"duration": "59"
}
}License
MIT
