From 8cd0f5bd5360a7e12d2e5685a8cccddd8abd3284 Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Wed, 12 Aug 2026 16:38:20 +0900 Subject: [PATCH] =?UTF-8?q?260812=5F03=5FENH:=20cti=EA=B4=80=EB=A0=A8=20?= =?UTF-8?q?=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EB=A6=AC=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EB=B0=B0=EC=A0=95=20=ED=8E=98=EC=9D=B4=EC=A7=80=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EB=AA=A9=EB=A1=9D=EC=97=90=20=EB=8C=80=ED=95=9C=20?= =?UTF-8?q?=ED=95=84=ED=84=B0=EC=99=80=20=EA=B1=B4=EC=88=98=20=EC=9C=84?= =?UTF-8?q?=EC=B9=98=20=EB=92=A4=EC=A7=91=EC=9D=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/assign/AssignTargetList.tsx | 12 ++--- src/lib/cti/ctiClient.ts | 51 ++++++++++++++++++++-- 2 files changed, 53 insertions(+), 10 deletions(-) diff --git a/src/components/assign/AssignTargetList.tsx b/src/components/assign/AssignTargetList.tsx index 160f6d8..e02aee3 100644 --- a/src/components/assign/AssignTargetList.tsx +++ b/src/components/assign/AssignTargetList.tsx @@ -124,6 +124,12 @@ export function AssignTargetList({ return (
+ {summary ? ( +
+ 전체 {summary.totalCount}건 · 미배정 {summary.unassignedCount}건 +
+ ) : null} + {canFilterByCmpn ? (
) : null} - {summary ? ( -
- 전체 {summary.totalCount}건 · 미배정 {summary.unassignedCount}건 -
- ) : null} -
diff --git a/src/lib/cti/ctiClient.ts b/src/lib/cti/ctiClient.ts index a71321b..6737d20 100644 --- a/src/lib/cti/ctiClient.ts +++ b/src/lib/cti/ctiClient.ts @@ -1,5 +1,6 @@ import { clientEnv } from "@/lib/env.client"; import { nextApi } from "@/lib/http-client"; +import { HttpError } from "@kri/common/http"; import { CTI_AGENT_GROUP, CTI_ON_CALL_STATUSES } from "@/const/ctiConst"; import type { ListCallCloseRequest, @@ -250,6 +251,9 @@ const restoreCtiState = (agentLoginId: string) => { return true; }; +const fetchCallHistBySession = (agentSessionId: string) => + nextApi.get(`/list-call-hist/session/${encodeURIComponent(agentSessionId)}`); + const recoverLastCallHistId = async (agentLoginId: string) => { const targetCall = activeCall?.agentSessionId ? activeCall : @@ -259,11 +263,40 @@ const recoverLastCallHistId = async (agentLoginId: string) => { const agentSessionId = targetCall.agentSessionId; const callContext = targetCall.context; + let result: ListCallHist; try { - const result = await nextApi.get( - `/list-call-hist/session/${encodeURIComponent(agentSessionId)}`, - ); + result = await fetchCallHistBySession(agentSessionId); + } catch (firstError) { + // call-start 저장(PUT)이 아직 커밋되기 전에 재연결 복구용 조회가 먼저 도착하는 레이스가 있을 수 있어, + // 바로 포기하지 않고 짧게 대기 후 한 번 더 시도한다. + await new Promise((resolve) => setTimeout(resolve, 1000)); + try { + result = await fetchCallHistBySession(agentSessionId); + } catch (secondError) { + console.warn("[CTI][TEMP_LOG] failed to recover call history after retry", { + agentSessionId, + firstError, + secondError, + }); // TEMP_CTI_LOG + // 재시도까지 404(진짜로 존재하지 않는 세션)로 확인된 경우에만 phantom 상태를 정리한다. + // 다른 오류(네트워크 문제 등)는 통화가 실제로 살아있을 수 있으니 그대로 둔다. + const isConfirmedNotFound = secondError instanceof HttpError && secondError.status === 404; + if (isConfirmedNotFound && currentAgentLoginId === agentLoginId) { + if (closingCall?.agentSessionId === agentSessionId) { + closingCall = null; + } else if (activeCall?.agentSessionId === agentSessionId) { + activeCall = null; + agentStatus = null; + } + persistCtiState(); + notify(); + } + return; + } + } + + try { const isSameCall = currentAgentLoginId === agentLoginId && (activeCall?.agentSessionId === agentSessionId || @@ -484,11 +517,21 @@ const handleIncomingMessage = (raw: unknown) => { const eventAgentSessionId = String(parsed.AgntSessionID ?? ""); const isClosingCall = eventAgentSessionId !== "" && eventAgentSessionId === closingCall?.agentSessionId; + // saveCallHistory가 activeCall/closingCall에서 컨텍스트를 동기적으로 먼저 읽어가므로, + // 아래에서 activeCall을 비우기 전에 반드시 먼저 호출해야 한다(순서 변경 금지). + saveCallHistory(parsed, "close"); if (!isClosingCall) { callClosedReceived = true; setAgentStatus(null); + // CallClosed는 통화가 끝났다는 CTI 서버의 확정 신호이므로, 이력 저장(백엔드 API) 성공 여부와 + // 무관하게 로컬 상태는 즉시 비운다. 저장이 실패해도 이 처리를 기다리다 UI가 "통화 중"에 + // 멈춰있으면 안 된다. 세션ID가 일치할 때만 비워서, 그 사이 새 통화가 시작된 경우를 보호한다. + if (eventAgentSessionId !== "" && activeCall?.agentSessionId === eventAgentSessionId) { + activeCall = null; + persistCtiState(); + notify(); + } } - saveCallHistory(parsed, "close"); break; } default: