260716_01_ENH: 본 서버에서 기동 후 중간 테스트를 위한 커밋

This commit is contained in:
2026-07-16 09:12:57 +09:00
parent c710a60beb
commit 36c7b41191
29 changed files with 864 additions and 532 deletions

View File

@@ -1,7 +1,7 @@
import { clientEnv } from "@/lib/env.client";
import { nextApi } from "@/lib/http-client";
import { CTI_AGENT_GROUP, CTI_AGENT_STATUS } from "@/const/ctiConst";
import type { ListCallHistRequest } from "@/types/list";
import type { ListCallHist, ListCallHistRequest } from "@/types/list";
// TEMP_CTI_LOG: 배포 후 CTI 연동 오류를 콘솔에서 바로 확인하기 위한 임시 로그.
// 안정화되면 "TEMP_CTI_LOG"로 검색해서 이 파일의 관련 로그를 전부 제거할 것.
@@ -35,6 +35,7 @@ let currentConnectionKey: string | null = null;
let currentLoginParams: CtiLoginParams | null = null;
let agentStatus: string | null = null;
let currentCallContext: CtiCallContext | null = null;
let lastCallHistId: number | null = null;
const listeners = new Set<() => void>();
@@ -52,11 +53,17 @@ const setAgentStatus = (next: string | null) => {
notify();
};
// 통화 종료(CallClosed) 시 리스트 통화 이력 저장 API로 전달한다.
const setLastCallHistId = (next: number | null) => {
lastCallHistId = next;
notify();
};
// 통화 세션 시작(StartSessionRecord)/종료(CallClosed) 시 리스트 통화 이력 저장 API로 전달한다.
// listHderId/prjctIdx/sid는 WS 메시지에 없어서 makeCall 시점에 캐시해둔 currentCallContext에서 가져온다.
const saveCallHistory = (parsed: Record<string, unknown>) => {
// clearContextAfter=false: StartSessionRecord는 같은 통화의 CallClosed가 이어서 오므로 컨텍스트를 유지한다.
const saveCallHistory = (parsed: Record<string, unknown>, options: { clearContextAfter: boolean }) => {
if (!currentCallContext) {
console.warn("[CTI][TEMP_LOG] CallClosed received but no call context cached", parsed); // TEMP_CTI_LOG
console.warn("[CTI][TEMP_LOG] call history event received but no call context cached", parsed); // TEMP_CTI_LOG
return;
}
@@ -80,11 +87,19 @@ const saveCallHistory = (parsed: Record<string, unknown>) => {
};
console.log("[CTI][TEMP_LOG] saving call history", { prjctIdx, sid, body }); // TEMP_CTI_LOG
nextApi.put(`/list-call-hist/${prjctIdx}/${sid}`, body).catch((error) => {
console.error("[CTI][TEMP_LOG] failed to save call history", error); // TEMP_CTI_LOG
});
nextApi
.put<ListCallHist>(`/list-call-hist/${prjctIdx}/${sid}`, body)
.then((result) => {
console.log("[CTI][TEMP_LOG] call history saved, listCallHistIdx =", result?.listCallHistIdx); // TEMP_CTI_LOG
setLastCallHistId(result?.listCallHistIdx ?? null);
})
.catch((error) => {
console.error("[CTI][TEMP_LOG] failed to save call history", error); // TEMP_CTI_LOG
});
currentCallContext = null;
if (options.clearContextAfter) {
currentCallContext = null;
}
};
// WS 서버 -> 클라이언트로 오는 메시지는 ZCommand가 기준값이다.
@@ -107,9 +122,14 @@ const handleIncomingMessage = (raw: unknown) => {
setAgentStatus(status);
break;
}
case "StartSessionRecord": {
console.log("[CTI][TEMP_LOG] StartSessionRecord ->", parsed); // TEMP_CTI_LOG
saveCallHistory(parsed, { clearContextAfter: false });
break;
}
case "CallClosed": {
console.log("[CTI][TEMP_LOG] CallClosed ->", parsed); // TEMP_CTI_LOG
saveCallHistory(parsed);
saveCallHistory(parsed, { clearContextAfter: true });
break;
}
default:
@@ -155,6 +175,7 @@ const logout = () => {
currentConnectionKey = null;
currentLoginParams = null;
currentCallContext = null;
setLastCallHistId(null);
};
const connectAndLogin = (params: CtiLoginParams) => {
@@ -229,10 +250,12 @@ export const ctiClient = {
},
getConnectionState: () => connectionState,
getAgentStatus: () => agentStatus,
getLastCallHistId: () => lastCallHistId,
makeCall: (params: CtiMakeCallParams) => {
if (!currentAgentLoginId || !currentLoginParams) return;
console.log("[CTI][TEMP_LOG] makeCall", params); // TEMP_CTI_LOG
currentCallContext = { prjctIdx: params.prjctIdx, sid: params.sid, listHderId: params.listHderId };
setLastCallHistId(null); // 새 통화 시작, 이전 통화의 listCallHistIdx는 더 이상 유효하지 않음
send({
ZCommand: "MakeCall",
AgentLoginID: currentAgentLoginId,