Root cause: iOS CallKit auto-dismisses incoming-call UI after ~5s when the
app is in foreground (because AppDelegate.didReceiveIncomingPush MUST call
reportNewIncomingCall — Apple requirement). That CallKit dismiss fires an
endCall event which our useCallKeepEvents.onEnd translated to declineCall,
unmounting the in-app /call screen before the user could tap accept/decline.
Fixes:
- useCallKeepEvents.onEnd: ignore CallKit endCall when iOS app is foreground
AND status==='incoming' (in-app UI is authoritative there). Comment with
big warning not to remove this again.
- call.tsx closeScreen: replace('/') instead of router.back() to avoid
GO_BACK action errors when navigation stack is inconsistent after long
calls (manifested as wrap-jsx.js crash in react-native-css-interop).
- useIncomingCalls: log CANCEL receive events for future diagnostics.
- call.ts: clog hangup/declineCall/closeScreen with reason+status for trace.
Verified: foreground call screen stays up the full UNANSWERED_MS (35s) and
caller-side hangup('unanswered') correctly triggers iPhone closeScreen via
cancel-broadcast.
49 lines
2.0 KiB
TypeScript
49 lines
2.0 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { useRouter } from 'expo-router';
|
|
import { supabase } from '../lib/supabase';
|
|
import { useCallStore, type CallPeer } from '../stores/call';
|
|
|
|
/**
|
|
* Lauscht (app-weit, solange eingeloggt) auf den persönlichen Ring-Channel
|
|
* `call-ring:<myUserId>` und zeigt bei einer eingehenden Einladung den
|
|
* Call-Screen. Phase 1 = foreground-only (klingelt nur bei offener App;
|
|
* Wake-when-closed via VoIP-Push ist Phase 2).
|
|
*/
|
|
export function useIncomingCalls(myUserId: string | undefined) {
|
|
const router = useRouter();
|
|
|
|
useEffect(() => {
|
|
if (!myUserId) return;
|
|
|
|
console.log('[CALL/recv] subscribing call-ring channel for', myUserId);
|
|
const chan = supabase.channel(`call-ring:${myUserId}`);
|
|
chan.on('broadcast', { event: 'ring' }, (msg: any) => {
|
|
console.log('[CALL/recv] RING received', msg?.payload);
|
|
const callId = msg?.payload?.callId as string | undefined;
|
|
const from = msg?.payload?.from as CallPeer | undefined;
|
|
if (!callId || !from) return;
|
|
// Schon in einem Call → ignorieren (MVP: kein call-waiting).
|
|
if (useCallStore.getState().status !== 'idle') return;
|
|
useCallStore.getState().receiveIncoming(callId, from);
|
|
router.push('/call');
|
|
});
|
|
chan.on('broadcast', { event: 'cancel' }, (msg: any) => {
|
|
const callId = msg?.payload?.callId as string | undefined;
|
|
const st = useCallStore.getState();
|
|
console.log('[CALL/recv] CANCEL received callId=', callId, 'storeStatus=', st.status, 'storeCallId=', st.callId);
|
|
if (st.callId === callId && st.status === 'incoming') {
|
|
// Caller hat aufgelegt bevor wir annehmen konnten → verpasster Anruf.
|
|
st.hangup('unanswered');
|
|
}
|
|
});
|
|
chan.subscribe((status: string, err?: any) => {
|
|
console.log('[CALL/recv] call-ring subscribe status:', status, err ?? '');
|
|
});
|
|
|
|
return () => {
|
|
console.log('[CALL/recv] unsubscribing call-ring for', myUserId);
|
|
supabase.removeChannel(chan);
|
|
};
|
|
}, [myUserId, router]);
|
|
}
|