차트 설정 수정

This commit is contained in:
Macbook
2026-06-01 01:35:31 +09:00
parent 332019866a
commit f2208aab99
28 changed files with 546 additions and 333 deletions
+25 -8
View File
@@ -15,11 +15,11 @@ interface Listener {
handler: RawHandler;
}
const INITIAL_DELAY = 80;
const RECONNECT_BASE = 2000;
const RECONNECT_MAX = 30_000;
const INITIAL_DELAY = 350;
const RECONNECT_BASE = 3000;
const RECONNECT_MAX = 45_000;
const PING_INTERVAL = 20_000;
const DISCONNECT_IDLE_MS = 5_000;
const DISCONNECT_IDLE_MS = 200;
const refCounts = new Map<UpbitWsChannel, Map<string, number>>();
const listeners = new Set<Listener>();
@@ -33,6 +33,7 @@ let pingTimer: ReturnType<typeof setInterval> | null = null;
let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
let retryCount = 0;
let closingIntentionally = false;
let wsFailureLogged = false;
function getWsUrl(): string {
const proto = window.location.protocol === 'https:' ? 'wss' : 'ws';
@@ -175,6 +176,8 @@ function openSocket(): void {
if (listenerCount() === 0) return;
teardownSocket();
if (!mayOpenSocket()) return;
try {
const socket = new WebSocket(getWsUrl());
ws = socket;
@@ -182,6 +185,7 @@ function openSocket(): void {
socket.onopen = () => {
retryCount = 0;
wsFailureLogged = false;
notifyConnection(true);
sendSubscribe();
clearPing();
@@ -197,7 +201,13 @@ function openSocket(): void {
};
socket.onerror = () => {
console.warn('[upbitWsBroker] socket error');
if (!wsFailureLogged) {
wsFailureLogged = true;
console.warn(
'[upbitWsBroker] WebSocket 연결 실패 — 시세는 REST 폴링으로 대체됩니다. '
+ '서버 nginx에 /upbit-ws 프록시가 있는지 확인하세요.',
);
}
};
socket.onclose = () => {
@@ -207,7 +217,10 @@ function openSocket(): void {
if (!closingIntentionally && listenerCount() > 0) scheduleReconnect();
};
} catch (err) {
console.warn('[upbitWsBroker] connect failed', err);
if (!wsFailureLogged) {
wsFailureLogged = true;
console.warn('[upbitWsBroker] connect failed', err);
}
scheduleReconnect();
}
}
@@ -274,8 +287,12 @@ export function subscribeUpbitWs(
return () => {
listeners.delete(entry);
normalized.forEach(code => bumpRef(channel, code, -1));
if (listenerCount() === 0) scheduleDisconnect();
else if (ws?.readyState === WebSocket.OPEN) sendSubscribe();
if (listenerCount() === 0) {
cancelPendingConnect();
scheduleDisconnect();
} else if (ws?.readyState === WebSocket.OPEN) {
sendSubscribe();
}
};
}