Download the PHP package stitch-digital/mobile-call-detection without Composer
On this page you can find all versions of the php package stitch-digital/mobile-call-detection. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stitch-digital/mobile-call-detection
More information about stitch-digital/mobile-call-detection
Files in stitch-digital/mobile-call-detection
Package mobile-call-detection
Short Description Call detection plugin for NativePHP Mobile that fires events when phone calls end
License MIT
Informations about the package mobile-call-detection
Call Detection Plugin for NativePHP Mobile
A NativePHP Mobile plugin that detects when phone calls end and fires a CallEnded event with call metadata.
Useful for apps that need to log calls, trigger workflows after conversations, or track call activity — such as CRM, sales, or support applications.
Platform Support
| Feature | Android | iOS |
|---|---|---|
| Phone number | ✅ | ❌ Not available (Apple privacy) |
| Call direction | ✅ inbound / outbound |
❌ Always unknown |
| Duration | ✅ From call log (accurate) | ⚠️ From timestamps (approximate) |
| Background detection | ✅ BroadcastReceiver | ⚠️ Limited (CXCallObserver) |
| Permissions required | ✅ | ✅ None needed |
How It Works
Android uses a manifest-registered BroadcastReceiver that listens for android.intent.action.PHONE_STATE. A state machine tracks transitions between RINGING, OFFHOOK, and IDLE to determine when a call ends and whether it was inbound or outbound. After the call ends, the plugin waits ~1 second then queries CallLog.Calls.CONTENT_URI for the phone number, direction, and duration.
iOS uses CXCallObserver with a CXCallObserverDelegate. Apple privacy restrictions mean the plugin cannot access the phone number or call direction. It tracks hasConnected timestamps per call UUID to approximate duration, and dispatches the event when hasEnded becomes true.
Requirements
| Minimum | |
|---|---|
| PHP | 8.2 |
| NativePHP Mobile | 3.x |
| Android | API 21+ |
| iOS | 13.0+ |
Installation
The service provider and CallDetection facade are auto-discovered by Laravel — no manual registration needed.
Quick Start
Then listen for the CallEnded event in your Livewire component or event listener.
PHP API
All methods are available via the CallDetection facade or by resolving StitchDigital\CallDetection\CallDetection from the container.
hasPermission(): bool
Check whether the required permissions have been granted.
- Android — checks
READ_PHONE_STATEandREAD_CALL_LOGviaContextCompat.checkSelfPermission. - iOS — always returns
true.CXCallObserverdoes not require explicit permission.
Returns false if running outside NativePHP.
requestPermission(): bool
Request call detection permissions from the user.
- Android — shows the system permission dialog for
READ_PHONE_STATEandREAD_CALL_LOG. Returnsfalseimmediately because the result is asynchronous — callhasPermission()again after the user responds. - iOS — no-op, returns
true. No permission is needed.
Returns false if running outside NativePHP.
JavaScript API
Events
The plugin dispatches a single event that covers the full call lifecycle completion.
| Event | Dispatched when |
|---|---|
CallEnded |
A phone call has finished |
CallEnded Payload
| Property | Type | Description |
|---|---|---|
$phoneNumber |
?string |
The phone number (null on iOS) |
$direction |
string |
'inbound', 'outbound', or 'unknown' |
$duration |
int |
Call duration in seconds |
$platform |
string |
'android' or 'ios' |
Listening with #[OnNative]
Vue Example
React Example
Platform Notes
Android
- The
CallEndedReceiveris registered in the AndroidManifest via the plugin manifest, so it receives call state changes even when the app is in the background. - After detecting
IDLEstate, the plugin waits ~1 second before querying the call log. This delay allows the system to finish writing the log entry. - If
READ_CALL_LOGpermission is denied butREAD_PHONE_STATEis granted, the receiver falls back to the internal state machine for direction and duration (less accurate, no phone number). - The receiver tracks state transitions:
RINGING → OFFHOOK → IDLE(inbound) andOFFHOOK → IDLE(outbound). - The
CallEndedevent is dispatched on the main thread, which is required for WebView JavaScript injection.
iOS
CXCallObserverdoes not require explicit permission — the permission API is a no-op on iOS.- Phone numbers cannot be accessed at the application level. Apple does not expose this data through
CXCallObserver. ThephoneNumberfield is alwaysnull. - Call direction cannot be determined. The
directionfield is always"unknown". - Duration is approximated from the time difference between
hasConnectedandhasEndedtimestamps. Calls that end without connecting (missed/rejected) report a duration of0. - The
CallObserverManagersingleton is initialized at app launch viainit_functionand persists for the app's lifetime.
Testing
Then trigger the permission flow and make a test call:
Android — call CallDetection::requestPermission(), grant both permissions, then make or receive a phone call. The CallEnded event should fire with the phone number, direction, and duration.
iOS — make or receive a phone call. The CallEnded event should fire with null phoneNumber, "unknown" direction, and an approximate duration.
License
The MIT License (MIT). Please see License File for more information.