Commit 46d5f76b authored by 崔婷婷's avatar 崔婷婷

v2

parent 38039a32
......@@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="alternate icon" href="/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>工厂生产看板</title>
</head>
......
This diff is collapsed.
This diff is collapsed.
......@@ -15,12 +15,13 @@
* VITE_WS_URL — WebSocket 地址,默认 ws://127.0.0.1:8080/ws
*/
const WS_URL = import.meta.env.VITE_WS_URL || 'ws://127.0.0.1:8080/ws'
const RECONNECT_DELAY = 2000 // 断线重连间隔(ms)
const PING_INTERVAL = 10000 // 心跳间隔(ms)
const MAX_RECONNECTS = 0 // 0 = 无限重连
export function connect() {
export function connect(url) {
const wsUrl = url || import.meta.env.VITE_WS_URL || 'ws://127.0.0.1:8080/ws'
const handlers = {}
const api = {
......@@ -41,6 +42,7 @@ export function connect() {
},
close() {
clearInterval(pingTimer)
clearTimeout(reconnectTimer)
reconnectCount = -1 // 阻止重连
if (socket) socket.close()
},
......@@ -57,7 +59,7 @@ export function connect() {
}
function createSocket() {
socket = new WebSocket(WS_URL)
socket = new WebSocket(wsUrl)
socket.addEventListener('open', () => {
reconnectCount = 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment