fix: three root causes for federated DM call failures
1. Accept/reject/end from remote instance now resolves federatedId to local dmChannelId via DB lookup, so the host can find its VoiceRoom when the event arrives with only a federatedCallId. Previously silently failed with "No active call" error. 2. Batch all dm_call_incoming state updates into a single useVoiceStore.setState() call. Prevents SoundController from starting multiple ringtone instances (async playSound guard race when 4 separate set() calls each triggered the subscription). 3. Always overwrite callOrigin/federatedCallId (with null if absent) on dm_call_incoming. Prevents stale values from a previous federated call routing local accepts to the wrong instance.
This commit is contained in:
@@ -779,22 +779,20 @@ function handleEvent(origin: string, event: ServerEvent): void {
|
||||
// ─── DM call events (all origins) ──────────────────────────────────────
|
||||
|
||||
case 'dm_call_incoming': {
|
||||
const { setIncomingCall, setFederatedCallData, setFederatedCallId, setCallOrigin } = useVoiceStore.getState();
|
||||
setIncomingCall({
|
||||
dmChannelId: event.dmChannelId ?? null,
|
||||
callerId: event.callerId,
|
||||
callerName: event.callerName,
|
||||
// Batch ALL call state into a single set() to prevent:
|
||||
// 1. Ringtone multiplication (multiple subscription triggers from separate set() calls)
|
||||
// 2. Stale callOrigin/federatedCallId from previous calls (always overwritten)
|
||||
useVoiceStore.setState({
|
||||
incomingCall: {
|
||||
dmChannelId: event.dmChannelId ?? null,
|
||||
callerId: event.callerId,
|
||||
callerName: event.callerName,
|
||||
},
|
||||
federatedCallToken: event.livekitToken ?? null,
|
||||
federatedCallUrl: event.livekitUrl ?? null,
|
||||
federatedCallId: event.federatedCallId ?? null,
|
||||
callOrigin: event.callOrigin ?? null,
|
||||
});
|
||||
// Store federated call data if present (remote LiveKit URL + token)
|
||||
if (event.livekitUrl && event.livekitToken) {
|
||||
setFederatedCallData(event.livekitToken, event.livekitUrl);
|
||||
}
|
||||
if (event.federatedCallId) {
|
||||
setFederatedCallId(event.federatedCallId);
|
||||
}
|
||||
if (event.callOrigin) {
|
||||
setCallOrigin(event.callOrigin);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user