Skip to content

Commit 5305359

Browse files
committed
Web socket Opt
1 parent 0d6c2c0 commit 5305359

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

dinky-admin/src/main/java/org/dinky/ws/GlobalWebSocket.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ public enum EventType {
9494
private static final Map<Session, RequestDTO> TOPICS = new ConcurrentHashMap<>();
9595

9696
@OnOpen
97-
public void onOpen(Session session) {}
97+
public void onOpen(Session session) {
98+
session.setMaxIdleTimeout(30000);
99+
}
98100

99101
@OnClose
100102
public void onClose(Session session) {

dinky-web/src/models/UseWebSocketModel.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export default () => {
5959
const ws = useRef<WebSocket>();
6060

6161
const reconnect = () => {
62-
if (ws.current && ws.current.readyState === WebSocket.CLOSED) {
62+
if (ws.current && ws.current.readyState === WebSocket.OPEN) {
6363
ws.current.close();
6464
}
6565
ws.current = new WebSocket(wsUrl);
@@ -119,9 +119,9 @@ export default () => {
119119
reconnect();
120120
} else {
121121
const currentTime = new Date().getTime();
122-
if (currentTime - lastPongTimeRef.current > 15000) {
122+
if (currentTime - lastPongTimeRef.current > 15) {
123123
reconnect();
124-
} else if (currentTime - lastPongTimeRef.current > 5000) {
124+
} else if (currentTime - lastPongTimeRef.current > 5) {
125125
const token = JSON.parse(localStorage.getItem(TOKEN_KEY) ?? '{}')?.tokenValue;
126126
ws.current.send(JSON.stringify({ token, type: 'PING' }));
127127
}

0 commit comments

Comments
 (0)