260714_01_ENH: 테스트 서버에서 기동 후 중간 테스트를 위한 커밋
This commit is contained in:
42
src/hooks/useCtiConnection.ts
Normal file
42
src/hooks/useCtiConnection.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useAuth } from "@/hooks/useAuth";
|
||||
import { useInternalInfoQuery } from "@/query/internal";
|
||||
import { ctiClient } from "@/lib/cti/ctiClient";
|
||||
|
||||
// TEMP_CTI_LOG: 배포 후 CTI 연동 오류를 콘솔에서 바로 확인하기 위한 임시 로그.
|
||||
// 안정화되면 "TEMP_CTI_LOG"로 검색해서 관련 로그를 전부 제거할 것.
|
||||
|
||||
export function useCtiConnection() {
|
||||
const { auth } = useAuth();
|
||||
const hasUser = !!auth.user;
|
||||
|
||||
// 로그인 시 IP 기반으로 사내 서버에서 내부 정보를 조회한다.
|
||||
// 이 정보가 정상적으로 내려오면(clientId 존재) CTI 웹소켓을 사용하고, 아니면 사용하지 않는다.
|
||||
const internalInfoQuery = useInternalInfoQuery(hasUser);
|
||||
|
||||
const clientId = internalInfoQuery.data?.clientId ?? "";
|
||||
const internalNo = internalInfoQuery.data?.internalNo ?? "";
|
||||
const externalNo = internalInfoQuery.data?.externalNo ?? "";
|
||||
const agentName = auth.user?.userName ?? "";
|
||||
|
||||
useEffect(() => {
|
||||
if (!hasUser) {
|
||||
console.log("[CTI][TEMP_LOG] useCtiConnection skip, not logged in"); // TEMP_CTI_LOG
|
||||
ctiClient.logout();
|
||||
return;
|
||||
}
|
||||
if (!clientId) {
|
||||
console.log("[CTI][TEMP_LOG] useCtiConnection skip, internalInfo.clientId is empty", internalInfoQuery.data); // TEMP_CTI_LOG
|
||||
return;
|
||||
}
|
||||
|
||||
ctiClient.connectAndLogin({
|
||||
agentLoginId: clientId,
|
||||
agentPhone: internalNo,
|
||||
aniNumber: externalNo,
|
||||
agentName,
|
||||
});
|
||||
}, [hasUser, clientId, internalNo, externalNo, agentName]);
|
||||
}
|
||||
Reference in New Issue
Block a user