Исправить маршрутизацию call push по sessionId

This commit is contained in:
AidarKC
2026-06-19 19:18:16 +04:00
parent 47574100f9
commit cc074a941f
7 changed files with 56 additions and 5 deletions
+22 -3
View File
@@ -831,6 +831,9 @@ async function finalizeCall(call, {
localReasonCode = 'error',
debugReason = '',
notifyRemoteHangup = false,
suppressRemoteSignal = false,
suppressReports = false,
suppressSummary = false,
} = {}) {
if (!call) return;
const diagnosticsBeforeClose = getCallDiagnosticsContext(call);
@@ -839,7 +842,8 @@ async function finalizeCall(call, {
stopTone();
const shouldNotifyRemoteFailure =
!notifyRemoteHangup
!suppressRemoteSignal
&& !notifyRemoteHangup
&& Boolean(call.remoteSessionId)
&& String(localReasonCode || '') !== 'completed'
&& String(debugReason || '') !== 'remote_hangup';
@@ -868,7 +872,7 @@ async function finalizeCall(call, {
}
const reasonText = debugReason || localReasonCode;
if (String(localReasonCode || '') !== 'completed') {
if (!suppressReports && String(localReasonCode || '') !== 'completed') {
const failureStage = call.phase || '';
const failureContext = {
failureStage,
@@ -890,7 +894,9 @@ async function finalizeCall(call, {
}
}
pushCallSummary(call, localReasonCode);
if (!suppressSummary) {
pushCallSummary(call, localReasonCode);
}
call.phase = 'ended';
call.statusText = 'Звонок завершён';
@@ -1128,6 +1134,13 @@ function isIncomingCallPushFresh(payload) {
return true;
}
function isCallPushForCurrentSession(payload = {}) {
const targetSessionId = String(payload?.targetSessionId || '').trim();
if (!targetSessionId) return true;
const currentSessionId = String(state?.session?.sessionId || '').trim();
return Boolean(currentSessionId) && currentSessionId === targetSessionId;
}
async function handleIncomingInvitePayload(payload, { source = 'ws' } = {}) {
const callId = String(payload?.callId || '').trim();
const fromLogin = String(payload?.fromLogin || '').trim();
@@ -1627,11 +1640,13 @@ export async function hangupActiveCall() {
}
export async function handleIncomingCallPush(payload = {}) {
if (!isCallPushForCurrentSession(payload)) return;
if (!isIncomingCallPushFresh(payload)) return;
await handleIncomingInvitePayload(payload, { source: 'push' });
}
export async function handleStopCallPush(payload = {}) {
if (!isCallPushForCurrentSession(payload)) return;
const callId = String(payload?.callId || '').trim();
if (!callId) return;
const call = getCall(callId);
@@ -1646,10 +1661,14 @@ export async function handleStopCallPush(payload = {}) {
await finalizeCall(call, {
localReasonCode: call.connectedAtMs ? 'completed' : 'no_answer',
debugReason: `stop_call_push:${reason}`,
suppressRemoteSignal: true,
suppressReports: true,
suppressSummary: true,
});
}
export async function handleCallPushAction(action, payload = {}) {
if (!isCallPushForCurrentSession(payload)) return;
const normalized = String(action || '').trim().toLowerCase();
if (normalized !== 'accept' && normalized !== 'decline') return;
if (!isIncomingCallPushFresh(payload)) return;