In-app calls
The rider and driver on a live ride can call each other inside the apps. Neither sees the other's phone number, and the operator needs no telephony contract. The call rings and behaves like a phone call: CallKit on iOS, Android's own call notification and Telecom routing on Android.
How a call works
| Step | Rider / driver app | Server |
|---|---|---|
| Ring | POST /calls {rideId} |
Checks the caller is on the ride and the ride is accepted, arrived or in_progress; records the call; sends call:incoming on the callee's socket and a push |
| Answer | POST /calls/:id/accept |
Only the callee may answer; sends call:accepted to the caller |
| Connect | WebRTC offer → answer → ICE candidates, each POST /calls/:id/signal |
Relays each to the other person's socket (call:signal). Audio goes phone to phone (or via TURN) and never through the server |
| End | POST /calls/:id/end |
Records why (declined, cancelled, missed, hangup, failed) and sends call:ended |
A ring nobody answers is missed after 40 seconds. Only one call can be live
per ride, enforced by a database index. Calls are recorded in ride_calls: who,
when it rang, whether it was answered, how it ended. Audio is never recorded.
When an in-app call is not possible (no microphone permission, the ride is no longer live, no network), the call button falls back to the phone call it made before: masked through Twilio Proxy if the operator has one, otherwise direct. After a declined, missed or failed in-app call, the call screen offers "Call by phone instead".
Operator setup: Admin → Providers → In-app calls
STUN URLs. Blank uses public STUN (
stun:stun.l.google.com:19302), which is enough for most phones on most networks.TURN URLs and TURN shared secret. Some phones sit behind carrier NAT that STUN cannot cross, and calls between two of them need a relay. Run coturn with REST authentication:
# /etc/turnserver.conf listening-port=3478 fingerprint use-auth-secret static-auth-secret=<the secret you paste into the admin> realm=turn.example.comThen enter
turn:turn.example.com:3478?transport=udp, turn:turn.example.com:3478?transport=tcpand the secret. Phones get credentials that expire after six hours, derived from the secret (username = <expiry>:<userId>,password = HMAC-SHA1). The secret itself never leaves the server.
On the phone
- iOS: the call is reported to CallKit, so it rings on the lock screen,
answers from AirPods or CarPlay, shows the green status pill, and is held by a
cellular call. Calls stay out of Recents. Info.plist declares
NSMicrophoneUsageDescription(calls only) and background modeaudio, so the call keeps sound when the person switches to the map. - Android: a self-managed
ConnectionService. The ring is a CallStyle notification (system Answer and Decline buttons, the phone's ringtone, full screen when locked). A live call runs aphoneCallforeground service, so the microphone keeps working in the background. Permissions:RECORD_AUDIO,MANAGE_OWN_CALLS,FOREGROUND_SERVICE_PHONE_CALL,USE_FULL_SCREEN_INTENT,BLUETOOTH_CONNECT. react-native-webrtc's screen-sharing service is removed from the manifest, because a voice call never shares the screen.
Code: backend/src/calls/ (server), mobile/*/src/lib/call.ts (call engine),
mobile/*/app/(app)/call.tsx (screen), mobile/*/modules/ridekit-call (Swift
CallKit, Kotlin ConnectionService). The engine, the screen and the native module
are identical in both apps, and a test keeps them that way.
Staying correct when things go wrong
- A phone that misses the "missed" message (its connection dropped mid-ring) stops ringing on its own 45 seconds after the ring started. The server ends an unanswered ring at 40 seconds.
- An app that dies mid-call (crash, force-quit, flat battery) leaves the call marked "answered". The app ends it on its next launch, or when it returns to the foreground. The server also expires answered calls older than four hours, so a stale call can never block the next one on the ride.
- Answering from the app's own button also tells the system: CallKit activates the iOS audio session only for a call it saw answered, and Android starts the phone-call service.
- The callee attaches its microphone after the caller's offer, so it rides the negotiated audio line. Attached before, it got a second, unused transceiver and the callee was silent.
Verified
Android emulator (driver) and iOS simulator (rider), 31 Oct to 1 Nov 2026:
- Driver calls rider:
- The rider rings with the caller's name.
- The rider answers; both phones connect.
- Audio flows driver to rider (WebRTC byte counters, 0 packets lost).
- Hanging up from either side ends it on both, and the server records the reason.
- Rider calls driver:
- Android rings with its own CallStyle notification (system Answer and Decline).
- Answering from the notification works.
- The driver, as callee, sends audio.
- The phone-call foreground service runs with the ongoing-call notification, and Hang Up from it ends the call on both phones.
- Decline, missed and recovery: a decline shows "Call declined" with "Call by phone instead"; missed calls end at 40 seconds; a dropped connection mid-ring stops ringing locally; a relaunch clears an orphaned call.
Not verifiable on simulators (needs a real iPhone):
- The iOS simulator refuses CallKit (
CXErrorDomain error 0). The module falls back to in-app ringing and hands the audio session to WebRTC. - The simulator's audio I/O unit does not start on this machine
(
AUIOClient_StartIO failed -66637), so it cannot send audio.
Open item: once, an incoming call on Android went active about 18 seconds into
the ring with nobody touching it (Telecom's log shows SET_ACTIVE). It did not
reproduce in three traced attempts.
What is not done yet
Ringing an app that is fully closed, on the lock screen, like a phone call. Today a closed app gets an ordinary push ("Your driver is calling — tap to answer"). Tapping it opens straight into the ringing call. A true wake-and-ring needs:
- iOS: PushKit VoIP pushes. These go straight to Apple (APNs, with the operator's VoIP key), not through the Expo push service the platform uses today.
- Android: a high-priority FCM data message handled natively. This needs the operator's Firebase project.
Both require operator credentials, and they cannot be exercised on a simulator.
Video calls (deliberately out of scope).