Calls: an incoming call that ended without the in-app /call screen ever mounting (iOS shows the native CallKit banner, not our screen) left the call store stuck in 'ended' forever — the ended→idle reset only lived in the /call screen. A stuck 'ended' then blocked every subsequent incoming call (RING + VoIP push were received but dropped by the status!=='idle' guard), so accepting from the banner produced a phantom CallKit call that ticked as active with no connection, and the caller saw a missed call. - store self-heals back to 'idle' after a call ends (teardown fallback) - receiveIncoming + ring handler tolerate a stale 'ended' state - onAnswer ends the native CallKit call when store has no incoming call - RNCallKeep.endAllCalls() on launch clears leftover CallKit zombies DM online dot: the green avatar dot used follow-gated presence while the "online" text used raw presence → dot hidden for non-followed partners even when online. DM header avatar now uses raw presence (rawPresence prop) → consistent with the text on both platforms. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
60 lines
2.8 KiB
TypeScript
60 lines
2.8 KiB
TypeScript
import { useEffect } from 'react';
|
|
import { Platform } from 'react-native';
|
|
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 AKTIVEN Call → ignorieren (MVP: kein call-waiting).
|
|
// 'ended' ist KEIN aktiver Call (nur ein noch nicht aufgeräumter Rest eines
|
|
// vorherigen Calls) → durchlassen, receiveIncoming räumt ihn auf. Sonst
|
|
// blockt ein stale 'ended' jeden neuen Anruf.
|
|
const st = useCallStore.getState().status;
|
|
if (st !== 'idle' && st !== 'ended') return;
|
|
useCallStore.getState().receiveIncoming(callId, from);
|
|
// iOS: CallKit (via VoIP-Push → reportNewIncomingCall) IST die Eingehend-UI.
|
|
// Hier NICHT zu /call navigieren, sonst Doppel-UI (CallKit-Banner +
|
|
// Fullscreen-/call). Der Realtime-Ring dient auf iOS nur der Store-
|
|
// Hydration; der /call-Screen kommt erst nach „Annehmen" (CallKit →
|
|
// useCallKeepEvents.onAnswer → router.push('/call')).
|
|
// Android: Custom-/call ist die gewünschte Eingehend-UI.
|
|
if (Platform.OS !== 'ios') 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]);
|
|
}
|