diff --git a/src/components/list-contact/CollapsibleHistorySection.tsx b/src/components/list-contact/CollapsibleHistorySection.tsx
index a3ad587..719c984 100644
--- a/src/components/list-contact/CollapsibleHistorySection.tsx
+++ b/src/components/list-contact/CollapsibleHistorySection.tsx
@@ -23,10 +23,11 @@ const CollapsibleHistorySection = ({
return (
-
+ {/* 제목과 headerExtra가 한 줄에 들어가지 않으면 headerExtra를 다음 줄 오른쪽으로 내린다. */}
+
- {headerExtra}
+ {headerExtra ?
{headerExtra}
: null}
{open ?
{children}
: null}
diff --git a/src/const/ctiConst.ts b/src/const/ctiConst.ts
index 19dda20..d2d05d8 100644
--- a/src/const/ctiConst.ts
+++ b/src/const/ctiConst.ts
@@ -20,3 +20,9 @@ export const CTI_DIALING_TIMEOUT_MS = 30 * 1000;
// 처리하지 않는 오류(ZCommand에 Error 포함) alert를 같은 ZCommand에 대해 다시 띄우기까지의 최소 간격
export const CTI_ERROR_ALERT_THROTTLE_MS = 10 * 1000;
+// 예상치 못한 소켓 끊김(onclose) 시 자동 재연결 간격. 1초부터 2배씩 늘려 최대 15초까지 무제한 재시도하며,
+// 서버 재시작 시 동시 접속이 몰리지 않도록 매번 0~1초 jitter를 더한다.
+export const CTI_AUTO_RECONNECT_BASE_MS = 1000;
+export const CTI_AUTO_RECONNECT_MAX_MS = 15 * 1000;
+export const CTI_AUTO_RECONNECT_JITTER_MS = 1000;
+
diff --git a/src/lib/cti/ctiClient.ts b/src/lib/cti/ctiClient.ts
index 9fbf4bc..059a51b 100644
--- a/src/lib/cti/ctiClient.ts
+++ b/src/lib/cti/ctiClient.ts
@@ -3,6 +3,9 @@ import { nextApi } from "@/lib/http-client";
import { HttpError } from "@kri/common/http";
import {
CTI_AGENT_GROUP,
+ CTI_AUTO_RECONNECT_BASE_MS,
+ CTI_AUTO_RECONNECT_JITTER_MS,
+ CTI_AUTO_RECONNECT_MAX_MS,
CTI_DIALING_TIMEOUT_MS,
CTI_ERROR_ALERT_THROTTLE_MS,
CTI_ON_CALL_STATUSES,
@@ -96,6 +99,8 @@ let lastCallHistId: number | null = null;
let hangupRequested = false;
let callClosedReceived = false;
let reconnectIntervalId: ReturnType
| null = null;
+let autoReconnectTimeoutId: ReturnType | null = null;
+let autoReconnectAttempt = 0;
let dialingTimeoutId: ReturnType | null = null;
const lastErrorAlertAt = new Map();
@@ -395,6 +400,32 @@ const stopReconnectLoop = () => {
console.log("[CTI][TEMP_LOG] reconnect loop stopped, agentStatus =", agentStatus); // TEMP_CTI_LOG
};
+const clearAutoReconnect = () => {
+ if (autoReconnectTimeoutId === null) return;
+ clearTimeout(autoReconnectTimeoutId);
+ autoReconnectTimeoutId = null;
+};
+
+// 예상치 못한 소켓 끊김(onclose) 시 새로고침과 같은 connectAndLogin 경로로 다시 연결한다.
+// 상태 복원과 통화 이력 복구(recoverLastCallHistId)도 함께 수행된다.
+// HangUp 재연결 루프가 돌고 있으면 그 루프에 맡긴다.
+const scheduleAutoReconnect = () => {
+ if (!currentLoginParams || reconnectIntervalId !== null || autoReconnectTimeoutId !== null) return;
+
+ const delay =
+ Math.min(CTI_AUTO_RECONNECT_BASE_MS * 2 ** autoReconnectAttempt, CTI_AUTO_RECONNECT_MAX_MS) +
+ Math.random() * CTI_AUTO_RECONNECT_JITTER_MS;
+ autoReconnectAttempt += 1;
+ console.log("[CTI][TEMP_LOG] auto reconnect scheduled, attempt =", autoReconnectAttempt, "delay =", Math.round(delay)); // TEMP_CTI_LOG
+
+ autoReconnectTimeoutId = setTimeout(() => {
+ autoReconnectTimeoutId = null;
+ const params = currentLoginParams;
+ if (!params || reconnectIntervalId !== null) return;
+ connectAndLogin(params);
+ }, delay);
+};
+
const setAgentStatus = (next: string | null) => {
agentStatus = next;
if (next !== null && next !== "0") {
@@ -668,6 +699,8 @@ const logout = () => {
hangupRequested = false;
callClosedReceived = false;
stopReconnectLoop();
+ clearAutoReconnect();
+ autoReconnectAttempt = 0;
clearDialingTimeout();
setAgentStatus(null);
setLastCallHistId(null);
@@ -682,6 +715,7 @@ const openSocketAndLogin = (params: CtiLoginParams) => {
socket = ws;
ws.onopen = () => {
+ autoReconnectAttempt = 0;
setConnectionState("open");
sendLogin(params);
};
@@ -698,6 +732,8 @@ const openSocketAndLogin = (params: CtiLoginParams) => {
ws.onclose = (event) => {
setConnectionState("closed");
console.log("[CTI][TEMP_LOG] websocket closed, code =", event.code, "reason =", event.reason, "wasClean =", event.wasClean); // TEMP_CTI_LOG
+ // 의도적인 종료(teardownSocket)는 핸들러를 먼저 떼므로 여기에 오지 않는다.
+ scheduleAutoReconnect();
};
};
@@ -747,6 +783,8 @@ const connectAndLogin = (params: CtiLoginParams) => {
return;
}
+ clearAutoReconnect();
+
if (currentAgentLoginId && currentAgentLoginId !== params.agentLoginId) {
console.log("[CTI][TEMP_LOG] switching agent from", currentAgentLoginId, "to", params.agentLoginId); // TEMP_CTI_LOG
logout();
@@ -769,6 +807,7 @@ const connectAndLogin = (params: CtiLoginParams) => {
const suspendForPageHide = () => {
if (!currentLoginParams) return;
stopReconnectLoop();
+ clearAutoReconnect();
if (currentAgentLoginId && connectionState === "open" && !isCallInProgress()) {
send({ ZCommand: "Logout", AgentLoginID: currentAgentLoginId });
}