@ichaingo/web-socket 1.3.72 → 1.3.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +119 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +235 -1497
- package/dist/useSocket.d.ts +57 -0
- package/dist/useSocket.d.ts.map +1 -0
- package/dist/useSocket.js +203 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,1523 +1,261 @@
|
|
|
1
|
-
var Ge = Object.defineProperty;
|
|
2
|
-
var Be = (_, r, h) => r in _ ? Ge(_, r, { enumerable: !0, configurable: !0, writable: !0, value: h }) : _[r] = h;
|
|
3
|
-
var q = (_, r, h) => Be(_, typeof r != "symbol" ? r + "" : r, h);
|
|
4
|
-
var Ee = { exports: {} }, f = {};
|
|
5
1
|
/**
|
|
6
|
-
*
|
|
7
|
-
* react.production.js
|
|
8
|
-
*
|
|
9
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
10
|
-
*
|
|
11
|
-
* This source code is licensed under the MIT license found in the
|
|
12
|
-
* LICENSE file in the root directory of this source tree.
|
|
2
|
+
* WebSocket连接状态枚举
|
|
13
3
|
*/
|
|
14
|
-
var
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
4
|
+
export var ConnectionStatus;
|
|
5
|
+
(function (ConnectionStatus) {
|
|
6
|
+
ConnectionStatus["CONNECTING"] = "connecting";
|
|
7
|
+
ConnectionStatus["CONNECTED"] = "connected";
|
|
8
|
+
ConnectionStatus["DISCONNECTED"] = "disconnected";
|
|
9
|
+
ConnectionStatus["RECONNECTING"] = "reconnecting";
|
|
10
|
+
ConnectionStatus["ERROR"] = "error";
|
|
11
|
+
})(ConnectionStatus || (ConnectionStatus = {}));
|
|
12
|
+
/**
|
|
13
|
+
* WebSocket单例连接类
|
|
14
|
+
* 提供WebSocket连接的创建、管理、重连等功能
|
|
15
|
+
*/
|
|
16
|
+
class SocketConnection {
|
|
17
|
+
static instance = null;
|
|
18
|
+
socket = null;
|
|
19
|
+
config;
|
|
20
|
+
status = ConnectionStatus.DISCONNECTED;
|
|
21
|
+
reconnectAttempts = 0;
|
|
22
|
+
reconnectTimer = null;
|
|
23
|
+
heartbeatTimer = null;
|
|
24
|
+
eventListeners = {};
|
|
25
|
+
constructor(config) {
|
|
26
|
+
this.config = {
|
|
27
|
+
reconnectInterval: 3000,
|
|
28
|
+
maxReconnectAttempts: 5,
|
|
29
|
+
heartbeatInterval: 30000,
|
|
30
|
+
debug: false,
|
|
31
|
+
...config
|
|
32
|
+
};
|
|
31
33
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
this.updater.enqueueSetState(this, t, o, "setState");
|
|
42
|
-
}, U.prototype.forceUpdate = function(t) {
|
|
43
|
-
this.updater.enqueueForceUpdate(this, t, "forceUpdate");
|
|
44
|
-
};
|
|
45
|
-
function G() {
|
|
46
|
-
}
|
|
47
|
-
G.prototype = U.prototype;
|
|
48
|
-
function Z(t, o, a) {
|
|
49
|
-
this.props = t, this.context = o, this.refs = ee, this.updater = a || F;
|
|
50
|
-
}
|
|
51
|
-
var l = Z.prototype = new G();
|
|
52
|
-
l.constructor = Z, V(l, U.prototype), l.isPureReactComponent = !0;
|
|
53
|
-
var O = Array.isArray, g = { H: null, A: null, T: null, S: null, V: null }, oe = Object.prototype.hasOwnProperty;
|
|
54
|
-
function se(t, o, a, c, v, b) {
|
|
55
|
-
return a = b.ref, {
|
|
56
|
-
$$typeof: _,
|
|
57
|
-
type: t,
|
|
58
|
-
key: o,
|
|
59
|
-
ref: a !== void 0 ? a : null,
|
|
60
|
-
props: b
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
function B(t, o) {
|
|
64
|
-
return se(
|
|
65
|
-
t.type,
|
|
66
|
-
o,
|
|
67
|
-
void 0,
|
|
68
|
-
void 0,
|
|
69
|
-
void 0,
|
|
70
|
-
t.props
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
function Q(t) {
|
|
74
|
-
return typeof t == "object" && t !== null && t.$$typeof === _;
|
|
75
|
-
}
|
|
76
|
-
function me(t) {
|
|
77
|
-
var o = { "=": "=0", ":": "=2" };
|
|
78
|
-
return "$" + t.replace(/[=:]/g, function(a) {
|
|
79
|
-
return o[a];
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
var C = /\/+/g;
|
|
83
|
-
function ue(t, o) {
|
|
84
|
-
return typeof t == "object" && t !== null && t.key != null ? me("" + t.key) : o.toString(36);
|
|
85
|
-
}
|
|
86
|
-
function x() {
|
|
87
|
-
}
|
|
88
|
-
function J(t) {
|
|
89
|
-
switch (t.status) {
|
|
90
|
-
case "fulfilled":
|
|
91
|
-
return t.value;
|
|
92
|
-
case "rejected":
|
|
93
|
-
throw t.reason;
|
|
94
|
-
default:
|
|
95
|
-
switch (typeof t.status == "string" ? t.then(x, x) : (t.status = "pending", t.then(
|
|
96
|
-
function(o) {
|
|
97
|
-
t.status === "pending" && (t.status = "fulfilled", t.value = o);
|
|
98
|
-
},
|
|
99
|
-
function(o) {
|
|
100
|
-
t.status === "pending" && (t.status = "rejected", t.reason = o);
|
|
101
|
-
}
|
|
102
|
-
)), t.status) {
|
|
103
|
-
case "fulfilled":
|
|
104
|
-
return t.value;
|
|
105
|
-
case "rejected":
|
|
106
|
-
throw t.reason;
|
|
34
|
+
/**
|
|
35
|
+
* 获取单例实例
|
|
36
|
+
*/
|
|
37
|
+
static getInstance(config) {
|
|
38
|
+
if (!SocketConnection.instance) {
|
|
39
|
+
if (!config) {
|
|
40
|
+
throw new Error('首次创建SocketConnection实例时必须提供配置');
|
|
41
|
+
}
|
|
42
|
+
SocketConnection.instance = new SocketConnection(config);
|
|
107
43
|
}
|
|
44
|
+
else if (config) {
|
|
45
|
+
if (JSON.stringify(SocketConnection.instance.config) !== JSON.stringify(config)) {
|
|
46
|
+
SocketConnection.instance = new SocketConnection(config);
|
|
47
|
+
}
|
|
48
|
+
if (config) {
|
|
49
|
+
SocketConnection.instance.config = {
|
|
50
|
+
...SocketConnection.instance.config,
|
|
51
|
+
...config
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return SocketConnection.instance;
|
|
108
56
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (O(t))
|
|
152
|
-
for (var k = 0; k < t.length; k++)
|
|
153
|
-
c = t[k], b = W + ue(c, k), d += M(
|
|
154
|
-
c,
|
|
155
|
-
o,
|
|
156
|
-
a,
|
|
157
|
-
b,
|
|
158
|
-
v
|
|
159
|
-
);
|
|
160
|
-
else if (k = z(t), typeof k == "function")
|
|
161
|
-
for (t = k.call(t), k = 0; !(c = t.next()).done; )
|
|
162
|
-
c = c.value, b = W + ue(c, k++), d += M(
|
|
163
|
-
c,
|
|
164
|
-
o,
|
|
165
|
-
a,
|
|
166
|
-
b,
|
|
167
|
-
v
|
|
168
|
-
);
|
|
169
|
-
else if (b === "object") {
|
|
170
|
-
if (typeof t.then == "function")
|
|
171
|
-
return M(
|
|
172
|
-
J(t),
|
|
173
|
-
o,
|
|
174
|
-
a,
|
|
175
|
-
c,
|
|
176
|
-
v
|
|
177
|
-
);
|
|
178
|
-
throw o = String(t), Error(
|
|
179
|
-
"Objects are not valid as a React child (found: " + (o === "[object Object]" ? "object with keys {" + Object.keys(t).join(", ") + "}" : o) + "). If you meant to render a collection of children, use an array instead."
|
|
180
|
-
);
|
|
57
|
+
/**
|
|
58
|
+
* 连接WebSocket
|
|
59
|
+
*/
|
|
60
|
+
connect(config) {
|
|
61
|
+
this.config = {
|
|
62
|
+
...this.config,
|
|
63
|
+
...config
|
|
64
|
+
};
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
if (this.socket?.readyState === WebSocket.OPEN) {
|
|
67
|
+
resolve();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
const url = this.config.url + (this.config?.params ? `?${Object.entries(this.config.params).map(([key, value]) => `${key}=${value}`).join('&')}` : '');
|
|
71
|
+
if (url) {
|
|
72
|
+
this.setStatus(ConnectionStatus.CONNECTING);
|
|
73
|
+
this.log('正在连接WebSocket...', url);
|
|
74
|
+
try {
|
|
75
|
+
this.socket = new WebSocket(url, this.config.protocols);
|
|
76
|
+
this.setupEventListeners();
|
|
77
|
+
this.socket.onopen = () => {
|
|
78
|
+
this.log('WebSocket连接成功');
|
|
79
|
+
this.setStatus(ConnectionStatus.CONNECTED);
|
|
80
|
+
this.reconnectAttempts = 0;
|
|
81
|
+
this.startHeartbeat();
|
|
82
|
+
this.eventListeners.open?.();
|
|
83
|
+
resolve();
|
|
84
|
+
};
|
|
85
|
+
this.socket.onerror = (error) => {
|
|
86
|
+
this.log('WebSocket连接错误:', error);
|
|
87
|
+
this.setStatus(ConnectionStatus.ERROR);
|
|
88
|
+
this.eventListeners.error?.(error);
|
|
89
|
+
reject(error);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
this.log('创建WebSocket连接失败:', error);
|
|
94
|
+
this.setStatus(ConnectionStatus.ERROR);
|
|
95
|
+
reject(error);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
181
99
|
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
if (t._status === -1) {
|
|
193
|
-
var o = t._result;
|
|
194
|
-
o = o(), o.then(
|
|
195
|
-
function(a) {
|
|
196
|
-
(t._status === 0 || t._status === -1) && (t._status = 1, t._result = a);
|
|
197
|
-
},
|
|
198
|
-
function(a) {
|
|
199
|
-
(t._status === 0 || t._status === -1) && (t._status = 2, t._result = a);
|
|
100
|
+
/**
|
|
101
|
+
* 断开连接
|
|
102
|
+
*/
|
|
103
|
+
disconnect() {
|
|
104
|
+
this.log('正在断开WebSocket连接...');
|
|
105
|
+
this.stopHeartbeat();
|
|
106
|
+
this.clearReconnectTimer();
|
|
107
|
+
if (this.socket) {
|
|
108
|
+
this.socket.close(1000, '主动断开连接');
|
|
109
|
+
this.socket = null;
|
|
200
110
|
}
|
|
201
|
-
|
|
111
|
+
this.setStatus(ConnectionStatus.DISCONNECTED);
|
|
202
112
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
process.emit("uncaughtException", t);
|
|
217
|
-
return;
|
|
113
|
+
/**
|
|
114
|
+
* 发送消息
|
|
115
|
+
*/
|
|
116
|
+
send(data) {
|
|
117
|
+
if (this.socket?.readyState === WebSocket.OPEN) {
|
|
118
|
+
this.socket.send(data);
|
|
119
|
+
this.log('发送消息:', data);
|
|
120
|
+
return true;
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
this.log('WebSocket未连接,无法发送消息');
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
218
126
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
map: K,
|
|
225
|
-
forEach: function(t, o, a) {
|
|
226
|
-
K(
|
|
227
|
-
t,
|
|
228
|
-
function() {
|
|
229
|
-
o.apply(this, arguments);
|
|
230
|
-
},
|
|
231
|
-
a
|
|
232
|
-
);
|
|
233
|
-
},
|
|
234
|
-
count: function(t) {
|
|
235
|
-
var o = 0;
|
|
236
|
-
return K(t, function() {
|
|
237
|
-
o++;
|
|
238
|
-
}), o;
|
|
239
|
-
},
|
|
240
|
-
toArray: function(t) {
|
|
241
|
-
return K(t, function(o) {
|
|
242
|
-
return o;
|
|
243
|
-
}) || [];
|
|
244
|
-
},
|
|
245
|
-
only: function(t) {
|
|
246
|
-
if (!Q(t))
|
|
247
|
-
throw Error(
|
|
248
|
-
"React.Children.only expected to receive a single React element child."
|
|
249
|
-
);
|
|
250
|
-
return t;
|
|
127
|
+
/**
|
|
128
|
+
* 发送JSON消息
|
|
129
|
+
*/
|
|
130
|
+
sendJSON(data) {
|
|
131
|
+
return this.send(JSON.stringify(data));
|
|
251
132
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
133
|
+
/**
|
|
134
|
+
* 添加事件监听器
|
|
135
|
+
*/
|
|
136
|
+
on(event, listener) {
|
|
137
|
+
this.eventListeners[event] = listener;
|
|
256
138
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
if (t == null)
|
|
263
|
-
throw Error(
|
|
264
|
-
"The argument must be a React element, but you passed " + t + "."
|
|
265
|
-
);
|
|
266
|
-
var c = V({}, t.props), v = t.key, b = void 0;
|
|
267
|
-
if (o != null)
|
|
268
|
-
for (d in o.ref !== void 0 && (b = void 0), o.key !== void 0 && (v = "" + o.key), o)
|
|
269
|
-
!oe.call(o, d) || d === "key" || d === "__self" || d === "__source" || d === "ref" && o.ref === void 0 || (c[d] = o[d]);
|
|
270
|
-
var d = arguments.length - 2;
|
|
271
|
-
if (d === 1) c.children = a;
|
|
272
|
-
else if (1 < d) {
|
|
273
|
-
for (var W = Array(d), k = 0; k < d; k++)
|
|
274
|
-
W[k] = arguments[k + 2];
|
|
275
|
-
c.children = W;
|
|
139
|
+
/**
|
|
140
|
+
* 移除事件监听器
|
|
141
|
+
*/
|
|
142
|
+
off(event) {
|
|
143
|
+
delete this.eventListeners[event];
|
|
276
144
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
_currentValue2: t,
|
|
283
|
-
_threadCount: 0,
|
|
284
|
-
Provider: null,
|
|
285
|
-
Consumer: null
|
|
286
|
-
}, t.Provider = t, t.Consumer = {
|
|
287
|
-
$$typeof: P,
|
|
288
|
-
_context: t
|
|
289
|
-
}, t;
|
|
290
|
-
}, f.createElement = function(t, o, a) {
|
|
291
|
-
var c, v = {}, b = null;
|
|
292
|
-
if (o != null)
|
|
293
|
-
for (c in o.key !== void 0 && (b = "" + o.key), o)
|
|
294
|
-
oe.call(o, c) && c !== "key" && c !== "__self" && c !== "__source" && (v[c] = o[c]);
|
|
295
|
-
var d = arguments.length - 2;
|
|
296
|
-
if (d === 1) v.children = a;
|
|
297
|
-
else if (1 < d) {
|
|
298
|
-
for (var W = Array(d), k = 0; k < d; k++)
|
|
299
|
-
W[k] = arguments[k + 2];
|
|
300
|
-
v.children = W;
|
|
145
|
+
/**
|
|
146
|
+
* 获取连接状态
|
|
147
|
+
*/
|
|
148
|
+
getStatus() {
|
|
149
|
+
return this.status;
|
|
301
150
|
}
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
return { current: null };
|
|
308
|
-
}, f.forwardRef = function(t) {
|
|
309
|
-
return { $$typeof: T, render: t };
|
|
310
|
-
}, f.isValidElement = Q, f.lazy = function(t) {
|
|
311
|
-
return {
|
|
312
|
-
$$typeof: L,
|
|
313
|
-
_payload: { _status: -1, _result: t },
|
|
314
|
-
_init: ie
|
|
315
|
-
};
|
|
316
|
-
}, f.memo = function(t, o) {
|
|
317
|
-
return {
|
|
318
|
-
$$typeof: I,
|
|
319
|
-
type: t,
|
|
320
|
-
compare: o === void 0 ? null : o
|
|
321
|
-
};
|
|
322
|
-
}, f.startTransition = function(t) {
|
|
323
|
-
var o = g.T, a = {};
|
|
324
|
-
g.T = a;
|
|
325
|
-
try {
|
|
326
|
-
var c = t(), v = g.S;
|
|
327
|
-
v !== null && v(a, c), typeof c == "object" && c !== null && typeof c.then == "function" && c.then(ae, te);
|
|
328
|
-
} catch (b) {
|
|
329
|
-
te(b);
|
|
330
|
-
} finally {
|
|
331
|
-
g.T = o;
|
|
151
|
+
/**
|
|
152
|
+
* 检查是否已连接
|
|
153
|
+
*/
|
|
154
|
+
isConnected() {
|
|
155
|
+
return this.status === ConnectionStatus.CONNECTED && this.socket?.readyState === WebSocket.OPEN;
|
|
332
156
|
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}, f.useDebugValue = function() {
|
|
344
|
-
}, f.useDeferredValue = function(t, o) {
|
|
345
|
-
return g.H.useDeferredValue(t, o);
|
|
346
|
-
}, f.useEffect = function(t, o, a) {
|
|
347
|
-
var c = g.H;
|
|
348
|
-
if (typeof a == "function")
|
|
349
|
-
throw Error(
|
|
350
|
-
"useEffect CRUD overload is not enabled in this build of React."
|
|
351
|
-
);
|
|
352
|
-
return c.useEffect(t, o);
|
|
353
|
-
}, f.useId = function() {
|
|
354
|
-
return g.H.useId();
|
|
355
|
-
}, f.useImperativeHandle = function(t, o, a) {
|
|
356
|
-
return g.H.useImperativeHandle(t, o, a);
|
|
357
|
-
}, f.useInsertionEffect = function(t, o) {
|
|
358
|
-
return g.H.useInsertionEffect(t, o);
|
|
359
|
-
}, f.useLayoutEffect = function(t, o) {
|
|
360
|
-
return g.H.useLayoutEffect(t, o);
|
|
361
|
-
}, f.useMemo = function(t, o) {
|
|
362
|
-
return g.H.useMemo(t, o);
|
|
363
|
-
}, f.useOptimistic = function(t, o) {
|
|
364
|
-
return g.H.useOptimistic(t, o);
|
|
365
|
-
}, f.useReducer = function(t, o, a) {
|
|
366
|
-
return g.H.useReducer(t, o, a);
|
|
367
|
-
}, f.useRef = function(t) {
|
|
368
|
-
return g.H.useRef(t);
|
|
369
|
-
}, f.useState = function(t) {
|
|
370
|
-
return g.H.useState(t);
|
|
371
|
-
}, f.useSyncExternalStore = function(t, o, a) {
|
|
372
|
-
return g.H.useSyncExternalStore(
|
|
373
|
-
t,
|
|
374
|
-
o,
|
|
375
|
-
a
|
|
376
|
-
);
|
|
377
|
-
}, f.useTransition = function() {
|
|
378
|
-
return g.H.useTransition();
|
|
379
|
-
}, f.version = "19.1.1", f;
|
|
380
|
-
}
|
|
381
|
-
var ce = { exports: {} };
|
|
382
|
-
/**
|
|
383
|
-
* @license React
|
|
384
|
-
* react.development.js
|
|
385
|
-
*
|
|
386
|
-
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
387
|
-
*
|
|
388
|
-
* This source code is licensed under the MIT license found in the
|
|
389
|
-
* LICENSE file in the root directory of this source tree.
|
|
390
|
-
*/
|
|
391
|
-
ce.exports;
|
|
392
|
-
var De;
|
|
393
|
-
function Ke() {
|
|
394
|
-
return De || (De = 1, (function(_, r) {
|
|
395
|
-
process.env.NODE_ENV !== "production" && (function() {
|
|
396
|
-
function h(e, n) {
|
|
397
|
-
Object.defineProperty(P.prototype, e, {
|
|
398
|
-
get: function() {
|
|
399
|
-
console.warn(
|
|
400
|
-
"%s(...) is deprecated in plain JavaScript React classes. %s",
|
|
401
|
-
n[0],
|
|
402
|
-
n[1]
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
}
|
|
407
|
-
function w(e) {
|
|
408
|
-
return e === null || typeof e != "object" ? null : (e = _e && e[_e] || e["@@iterator"], typeof e == "function" ? e : null);
|
|
409
|
-
}
|
|
410
|
-
function A(e, n) {
|
|
411
|
-
e = (e = e.constructor) && (e.displayName || e.name) || "ReactClass";
|
|
412
|
-
var s = e + "." + n;
|
|
413
|
-
Re[s] || (console.error(
|
|
414
|
-
"Can't call %s on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to `this.state` directly or define a `state = {};` class property with the desired state in the %s component.",
|
|
415
|
-
n,
|
|
416
|
-
e
|
|
417
|
-
), Re[s] = !0);
|
|
418
|
-
}
|
|
419
|
-
function P(e, n, s) {
|
|
420
|
-
this.props = e, this.context = n, this.refs = ye, this.updater = s || we;
|
|
421
|
-
}
|
|
422
|
-
function Y() {
|
|
423
|
-
}
|
|
424
|
-
function T(e, n, s) {
|
|
425
|
-
this.props = e, this.context = n, this.refs = ye, this.updater = s || we;
|
|
426
|
-
}
|
|
427
|
-
function N(e) {
|
|
428
|
-
return "" + e;
|
|
429
|
-
}
|
|
430
|
-
function I(e) {
|
|
431
|
-
try {
|
|
432
|
-
N(e);
|
|
433
|
-
var n = !1;
|
|
434
|
-
} catch {
|
|
435
|
-
n = !0;
|
|
436
|
-
}
|
|
437
|
-
if (n) {
|
|
438
|
-
n = console;
|
|
439
|
-
var s = n.error, u = typeof Symbol == "function" && Symbol.toStringTag && e[Symbol.toStringTag] || e.constructor.name || "Object";
|
|
440
|
-
return s.call(
|
|
441
|
-
n,
|
|
442
|
-
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
443
|
-
u
|
|
444
|
-
), N(e);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
function L(e) {
|
|
448
|
-
if (e == null) return null;
|
|
449
|
-
if (typeof e == "function")
|
|
450
|
-
return e.$$typeof === Ye ? null : e.displayName || e.name || null;
|
|
451
|
-
if (typeof e == "string") return e;
|
|
452
|
-
switch (e) {
|
|
453
|
-
case t:
|
|
454
|
-
return "Fragment";
|
|
455
|
-
case a:
|
|
456
|
-
return "Profiler";
|
|
457
|
-
case o:
|
|
458
|
-
return "StrictMode";
|
|
459
|
-
case d:
|
|
460
|
-
return "Suspense";
|
|
461
|
-
case W:
|
|
462
|
-
return "SuspenseList";
|
|
463
|
-
case He:
|
|
464
|
-
return "Activity";
|
|
465
|
-
}
|
|
466
|
-
if (typeof e == "object")
|
|
467
|
-
switch (typeof e.tag == "number" && console.error(
|
|
468
|
-
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
469
|
-
), e.$$typeof) {
|
|
470
|
-
case ae:
|
|
471
|
-
return "Portal";
|
|
472
|
-
case v:
|
|
473
|
-
return (e.displayName || "Context") + ".Provider";
|
|
474
|
-
case c:
|
|
475
|
-
return (e._context.displayName || "Context") + ".Consumer";
|
|
476
|
-
case b:
|
|
477
|
-
var n = e.render;
|
|
478
|
-
return e = e.displayName, e || (e = n.displayName || n.name || "", e = e !== "" ? "ForwardRef(" + e + ")" : "ForwardRef"), e;
|
|
479
|
-
case k:
|
|
480
|
-
return n = e.displayName || null, n !== null ? n : L(e.type) || "Memo";
|
|
481
|
-
case ne:
|
|
482
|
-
n = e._payload, e = e._init;
|
|
483
|
-
try {
|
|
484
|
-
return L(e(n));
|
|
485
|
-
} catch {
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
return null;
|
|
489
|
-
}
|
|
490
|
-
function $(e) {
|
|
491
|
-
if (e === t) return "<>";
|
|
492
|
-
if (typeof e == "object" && e !== null && e.$$typeof === ne)
|
|
493
|
-
return "<...>";
|
|
494
|
-
try {
|
|
495
|
-
var n = L(e);
|
|
496
|
-
return n ? "<" + n + ">" : "<...>";
|
|
497
|
-
} catch {
|
|
498
|
-
return "<...>";
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
function z() {
|
|
502
|
-
var e = m.A;
|
|
503
|
-
return e === null ? null : e.getOwner();
|
|
504
|
-
}
|
|
505
|
-
function F() {
|
|
506
|
-
return Error("react-stack-top-frame");
|
|
507
|
-
}
|
|
508
|
-
function V(e) {
|
|
509
|
-
if (le.call(e, "key")) {
|
|
510
|
-
var n = Object.getOwnPropertyDescriptor(e, "key").get;
|
|
511
|
-
if (n && n.isReactWarning) return !1;
|
|
512
|
-
}
|
|
513
|
-
return e.key !== void 0;
|
|
514
|
-
}
|
|
515
|
-
function ee(e, n) {
|
|
516
|
-
function s() {
|
|
517
|
-
ke || (ke = !0, console.error(
|
|
518
|
-
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
519
|
-
n
|
|
520
|
-
));
|
|
521
|
-
}
|
|
522
|
-
s.isReactWarning = !0, Object.defineProperty(e, "key", {
|
|
523
|
-
get: s,
|
|
524
|
-
configurable: !0
|
|
525
|
-
});
|
|
526
|
-
}
|
|
527
|
-
function U() {
|
|
528
|
-
var e = L(this.type);
|
|
529
|
-
return Se[e] || (Se[e] = !0, console.error(
|
|
530
|
-
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
531
|
-
)), e = this.props.ref, e !== void 0 ? e : null;
|
|
532
|
-
}
|
|
533
|
-
function G(e, n, s, u, i, y, p, R) {
|
|
534
|
-
return s = y.ref, e = {
|
|
535
|
-
$$typeof: te,
|
|
536
|
-
type: e,
|
|
537
|
-
key: n,
|
|
538
|
-
props: y,
|
|
539
|
-
_owner: i
|
|
540
|
-
}, (s !== void 0 ? s : null) !== null ? Object.defineProperty(e, "ref", {
|
|
541
|
-
enumerable: !1,
|
|
542
|
-
get: U
|
|
543
|
-
}) : Object.defineProperty(e, "ref", { enumerable: !1, value: null }), e._store = {}, Object.defineProperty(e._store, "validated", {
|
|
544
|
-
configurable: !1,
|
|
545
|
-
enumerable: !1,
|
|
546
|
-
writable: !0,
|
|
547
|
-
value: 0
|
|
548
|
-
}), Object.defineProperty(e, "_debugInfo", {
|
|
549
|
-
configurable: !1,
|
|
550
|
-
enumerable: !1,
|
|
551
|
-
writable: !0,
|
|
552
|
-
value: null
|
|
553
|
-
}), Object.defineProperty(e, "_debugStack", {
|
|
554
|
-
configurable: !1,
|
|
555
|
-
enumerable: !1,
|
|
556
|
-
writable: !0,
|
|
557
|
-
value: p
|
|
558
|
-
}), Object.defineProperty(e, "_debugTask", {
|
|
559
|
-
configurable: !1,
|
|
560
|
-
enumerable: !1,
|
|
561
|
-
writable: !0,
|
|
562
|
-
value: R
|
|
563
|
-
}), Object.freeze && (Object.freeze(e.props), Object.freeze(e)), e;
|
|
564
|
-
}
|
|
565
|
-
function Z(e, n) {
|
|
566
|
-
return n = G(
|
|
567
|
-
e.type,
|
|
568
|
-
n,
|
|
569
|
-
void 0,
|
|
570
|
-
void 0,
|
|
571
|
-
e._owner,
|
|
572
|
-
e.props,
|
|
573
|
-
e._debugStack,
|
|
574
|
-
e._debugTask
|
|
575
|
-
), e._store && (n._store.validated = e._store.validated), n;
|
|
576
|
-
}
|
|
577
|
-
function l(e) {
|
|
578
|
-
return typeof e == "object" && e !== null && e.$$typeof === te;
|
|
579
|
-
}
|
|
580
|
-
function O(e) {
|
|
581
|
-
var n = { "=": "=0", ":": "=2" };
|
|
582
|
-
return "$" + e.replace(/[=:]/g, function(s) {
|
|
583
|
-
return n[s];
|
|
584
|
-
});
|
|
585
|
-
}
|
|
586
|
-
function g(e, n) {
|
|
587
|
-
return typeof e == "object" && e !== null && e.key != null ? (I(e.key), O("" + e.key)) : n.toString(36);
|
|
588
|
-
}
|
|
589
|
-
function oe() {
|
|
590
|
-
}
|
|
591
|
-
function se(e) {
|
|
592
|
-
switch (e.status) {
|
|
593
|
-
case "fulfilled":
|
|
594
|
-
return e.value;
|
|
595
|
-
case "rejected":
|
|
596
|
-
throw e.reason;
|
|
597
|
-
default:
|
|
598
|
-
switch (typeof e.status == "string" ? e.then(oe, oe) : (e.status = "pending", e.then(
|
|
599
|
-
function(n) {
|
|
600
|
-
e.status === "pending" && (e.status = "fulfilled", e.value = n);
|
|
601
|
-
},
|
|
602
|
-
function(n) {
|
|
603
|
-
e.status === "pending" && (e.status = "rejected", e.reason = n);
|
|
604
|
-
}
|
|
605
|
-
)), e.status) {
|
|
606
|
-
case "fulfilled":
|
|
607
|
-
return e.value;
|
|
608
|
-
case "rejected":
|
|
609
|
-
throw e.reason;
|
|
610
|
-
}
|
|
611
|
-
}
|
|
612
|
-
throw e;
|
|
613
|
-
}
|
|
614
|
-
function B(e, n, s, u, i) {
|
|
615
|
-
var y = typeof e;
|
|
616
|
-
(y === "undefined" || y === "boolean") && (e = null);
|
|
617
|
-
var p = !1;
|
|
618
|
-
if (e === null) p = !0;
|
|
619
|
-
else
|
|
620
|
-
switch (y) {
|
|
621
|
-
case "bigint":
|
|
622
|
-
case "string":
|
|
623
|
-
case "number":
|
|
624
|
-
p = !0;
|
|
625
|
-
break;
|
|
626
|
-
case "object":
|
|
627
|
-
switch (e.$$typeof) {
|
|
628
|
-
case te:
|
|
629
|
-
case ae:
|
|
630
|
-
p = !0;
|
|
631
|
-
break;
|
|
632
|
-
case ne:
|
|
633
|
-
return p = e._init, B(
|
|
634
|
-
p(e._payload),
|
|
635
|
-
n,
|
|
636
|
-
s,
|
|
637
|
-
u,
|
|
638
|
-
i
|
|
639
|
-
);
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
if (p) {
|
|
643
|
-
p = e, i = i(p);
|
|
644
|
-
var R = u === "" ? "." + g(p, 0) : u;
|
|
645
|
-
return be(i) ? (s = "", R != null && (s = R.replace(Ne, "$&/") + "/"), B(i, n, s, "", function(X) {
|
|
646
|
-
return X;
|
|
647
|
-
})) : i != null && (l(i) && (i.key != null && (p && p.key === i.key || I(i.key)), s = Z(
|
|
648
|
-
i,
|
|
649
|
-
s + (i.key == null || p && p.key === i.key ? "" : ("" + i.key).replace(
|
|
650
|
-
Ne,
|
|
651
|
-
"$&/"
|
|
652
|
-
) + "/") + R
|
|
653
|
-
), u !== "" && p != null && l(p) && p.key == null && p._store && !p._store.validated && (s._store.validated = 2), i = s), n.push(i)), 1;
|
|
654
|
-
}
|
|
655
|
-
if (p = 0, R = u === "" ? "." : u + ":", be(e))
|
|
656
|
-
for (var E = 0; E < e.length; E++)
|
|
657
|
-
u = e[E], y = R + g(u, E), p += B(
|
|
658
|
-
u,
|
|
659
|
-
n,
|
|
660
|
-
s,
|
|
661
|
-
y,
|
|
662
|
-
i
|
|
663
|
-
);
|
|
664
|
-
else if (E = w(e), typeof E == "function")
|
|
665
|
-
for (E === e.entries && (Ae || console.warn(
|
|
666
|
-
"Using Maps as children is not supported. Use an array of keyed ReactElements instead."
|
|
667
|
-
), Ae = !0), e = E.call(e), E = 0; !(u = e.next()).done; )
|
|
668
|
-
u = u.value, y = R + g(u, E++), p += B(
|
|
669
|
-
u,
|
|
670
|
-
n,
|
|
671
|
-
s,
|
|
672
|
-
y,
|
|
673
|
-
i
|
|
674
|
-
);
|
|
675
|
-
else if (y === "object") {
|
|
676
|
-
if (typeof e.then == "function")
|
|
677
|
-
return B(
|
|
678
|
-
se(e),
|
|
679
|
-
n,
|
|
680
|
-
s,
|
|
681
|
-
u,
|
|
682
|
-
i
|
|
683
|
-
);
|
|
684
|
-
throw n = String(e), Error(
|
|
685
|
-
"Objects are not valid as a React child (found: " + (n === "[object Object]" ? "object with keys {" + Object.keys(e).join(", ") + "}" : n) + "). If you meant to render a collection of children, use an array instead."
|
|
686
|
-
);
|
|
687
|
-
}
|
|
688
|
-
return p;
|
|
689
|
-
}
|
|
690
|
-
function Q(e, n, s) {
|
|
691
|
-
if (e == null) return e;
|
|
692
|
-
var u = [], i = 0;
|
|
693
|
-
return B(e, u, "", "", function(y) {
|
|
694
|
-
return n.call(s, y, i++);
|
|
695
|
-
}), u;
|
|
696
|
-
}
|
|
697
|
-
function me(e) {
|
|
698
|
-
if (e._status === -1) {
|
|
699
|
-
var n = e._result;
|
|
700
|
-
n = n(), n.then(
|
|
701
|
-
function(s) {
|
|
702
|
-
(e._status === 0 || e._status === -1) && (e._status = 1, e._result = s);
|
|
703
|
-
},
|
|
704
|
-
function(s) {
|
|
705
|
-
(e._status === 0 || e._status === -1) && (e._status = 2, e._result = s);
|
|
157
|
+
/**
|
|
158
|
+
* 设置事件监听器
|
|
159
|
+
*/
|
|
160
|
+
setupEventListeners() {
|
|
161
|
+
if (!this.socket)
|
|
162
|
+
return;
|
|
163
|
+
this.socket.onmessage = (event) => {
|
|
164
|
+
this.log('收到消息:', event.data);
|
|
165
|
+
if (event.data !== 'pong') {
|
|
166
|
+
this.eventListeners.message?.(event.data);
|
|
706
167
|
}
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
Did you accidentally put curly braces around the import?`,
|
|
717
|
-
n
|
|
718
|
-
), "default" in n || console.error(
|
|
719
|
-
`lazy: Expected the result of a dynamic import() call. Instead received: %s
|
|
720
|
-
|
|
721
|
-
Your code should look like:
|
|
722
|
-
const MyComponent = lazy(() => import('./MyComponent'))`,
|
|
723
|
-
n
|
|
724
|
-
), n.default;
|
|
725
|
-
throw e._result;
|
|
726
|
-
}
|
|
727
|
-
function C() {
|
|
728
|
-
var e = m.H;
|
|
729
|
-
return e === null && console.error(
|
|
730
|
-
`Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
|
|
731
|
-
1. You might have mismatching versions of React and the renderer (such as React DOM)
|
|
732
|
-
2. You might be breaking the Rules of Hooks
|
|
733
|
-
3. You might have more than one copy of React in the same app
|
|
734
|
-
See https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem.`
|
|
735
|
-
), e;
|
|
736
|
-
}
|
|
737
|
-
function ue() {
|
|
738
|
-
}
|
|
739
|
-
function x(e) {
|
|
740
|
-
if (pe === null)
|
|
741
|
-
try {
|
|
742
|
-
var n = ("require" + Math.random()).slice(0, 7);
|
|
743
|
-
pe = (_ && _[n]).call(
|
|
744
|
-
_,
|
|
745
|
-
"timers"
|
|
746
|
-
).setImmediate;
|
|
747
|
-
} catch {
|
|
748
|
-
pe = function(u) {
|
|
749
|
-
je === !1 && (je = !0, typeof MessageChannel > "u" && console.error(
|
|
750
|
-
"This browser does not have a MessageChannel implementation, so enqueuing tasks via await act(async () => ...) will fail. Please file an issue at https://github.com/facebook/react/issues if you encounter this warning."
|
|
751
|
-
));
|
|
752
|
-
var i = new MessageChannel();
|
|
753
|
-
i.port1.onmessage = u, i.port2.postMessage(void 0);
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
return pe(e);
|
|
757
|
-
}
|
|
758
|
-
function J(e) {
|
|
759
|
-
return 1 < e.length && typeof AggregateError == "function" ? new AggregateError(e) : e[0];
|
|
760
|
-
}
|
|
761
|
-
function M(e, n) {
|
|
762
|
-
n !== de - 1 && console.error(
|
|
763
|
-
"You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one. "
|
|
764
|
-
), de = n;
|
|
765
|
-
}
|
|
766
|
-
function K(e, n, s) {
|
|
767
|
-
var u = m.actQueue;
|
|
768
|
-
if (u !== null)
|
|
769
|
-
if (u.length !== 0)
|
|
770
|
-
try {
|
|
771
|
-
ie(u), x(function() {
|
|
772
|
-
return K(e, n, s);
|
|
773
|
-
});
|
|
774
|
-
return;
|
|
775
|
-
} catch (i) {
|
|
776
|
-
m.thrownErrors.push(i);
|
|
777
|
-
}
|
|
778
|
-
else m.actQueue = null;
|
|
779
|
-
0 < m.thrownErrors.length ? (u = J(m.thrownErrors), m.thrownErrors.length = 0, s(u)) : n(e);
|
|
780
|
-
}
|
|
781
|
-
function ie(e) {
|
|
782
|
-
if (!ve) {
|
|
783
|
-
ve = !0;
|
|
784
|
-
var n = 0;
|
|
785
|
-
try {
|
|
786
|
-
for (; n < e.length; n++) {
|
|
787
|
-
var s = e[n];
|
|
788
|
-
do {
|
|
789
|
-
m.didUsePromise = !1;
|
|
790
|
-
var u = s(!1);
|
|
791
|
-
if (u !== null) {
|
|
792
|
-
if (m.didUsePromise) {
|
|
793
|
-
e[n] = s, e.splice(0, n);
|
|
794
|
-
return;
|
|
795
|
-
}
|
|
796
|
-
s = u;
|
|
797
|
-
} else break;
|
|
798
|
-
} while (!0);
|
|
799
|
-
}
|
|
800
|
-
e.length = 0;
|
|
801
|
-
} catch (i) {
|
|
802
|
-
e.splice(0, n + 1), m.thrownErrors.push(i);
|
|
803
|
-
} finally {
|
|
804
|
-
ve = !1;
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
809
|
-
var te = Symbol.for("react.transitional.element"), ae = Symbol.for("react.portal"), t = Symbol.for("react.fragment"), o = Symbol.for("react.strict_mode"), a = Symbol.for("react.profiler"), c = Symbol.for("react.consumer"), v = Symbol.for("react.context"), b = Symbol.for("react.forward_ref"), d = Symbol.for("react.suspense"), W = Symbol.for("react.suspense_list"), k = Symbol.for("react.memo"), ne = Symbol.for("react.lazy"), He = Symbol.for("react.activity"), _e = Symbol.iterator, Re = {}, we = {
|
|
810
|
-
isMounted: function() {
|
|
811
|
-
return !1;
|
|
812
|
-
},
|
|
813
|
-
enqueueForceUpdate: function(e) {
|
|
814
|
-
A(e, "forceUpdate");
|
|
815
|
-
},
|
|
816
|
-
enqueueReplaceState: function(e) {
|
|
817
|
-
A(e, "replaceState");
|
|
818
|
-
},
|
|
819
|
-
enqueueSetState: function(e) {
|
|
820
|
-
A(e, "setState");
|
|
821
|
-
}
|
|
822
|
-
}, Te = Object.assign, ye = {};
|
|
823
|
-
Object.freeze(ye), P.prototype.isReactComponent = {}, P.prototype.setState = function(e, n) {
|
|
824
|
-
if (typeof e != "object" && typeof e != "function" && e != null)
|
|
825
|
-
throw Error(
|
|
826
|
-
"takes an object of state variables to update or a function which returns an object of state variables."
|
|
827
|
-
);
|
|
828
|
-
this.updater.enqueueSetState(this, e, n, "setState");
|
|
829
|
-
}, P.prototype.forceUpdate = function(e) {
|
|
830
|
-
this.updater.enqueueForceUpdate(this, e, "forceUpdate");
|
|
831
|
-
};
|
|
832
|
-
var D = {
|
|
833
|
-
isMounted: [
|
|
834
|
-
"isMounted",
|
|
835
|
-
"Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks."
|
|
836
|
-
],
|
|
837
|
-
replaceState: [
|
|
838
|
-
"replaceState",
|
|
839
|
-
"Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236)."
|
|
840
|
-
]
|
|
841
|
-
}, fe;
|
|
842
|
-
for (fe in D)
|
|
843
|
-
D.hasOwnProperty(fe) && h(fe, D[fe]);
|
|
844
|
-
Y.prototype = P.prototype, D = T.prototype = new Y(), D.constructor = T, Te(D, P.prototype), D.isPureReactComponent = !0;
|
|
845
|
-
var be = Array.isArray, Ye = Symbol.for("react.client.reference"), m = {
|
|
846
|
-
H: null,
|
|
847
|
-
A: null,
|
|
848
|
-
T: null,
|
|
849
|
-
S: null,
|
|
850
|
-
V: null,
|
|
851
|
-
actQueue: null,
|
|
852
|
-
isBatchingLegacy: !1,
|
|
853
|
-
didScheduleLegacyUpdate: !1,
|
|
854
|
-
didUsePromise: !1,
|
|
855
|
-
thrownErrors: [],
|
|
856
|
-
getCurrentStack: null,
|
|
857
|
-
recentlyCreatedOwnerStacks: 0
|
|
858
|
-
}, le = Object.prototype.hasOwnProperty, Ce = console.createTask ? console.createTask : function() {
|
|
859
|
-
return null;
|
|
860
|
-
};
|
|
861
|
-
D = {
|
|
862
|
-
react_stack_bottom_frame: function(e) {
|
|
863
|
-
return e();
|
|
864
|
-
}
|
|
865
|
-
};
|
|
866
|
-
var ke, Oe, Se = {}, Ue = D.react_stack_bottom_frame.bind(
|
|
867
|
-
D,
|
|
868
|
-
F
|
|
869
|
-
)(), We = Ce($(F)), Ae = !1, Ne = /\/+/g, Pe = typeof reportError == "function" ? reportError : function(e) {
|
|
870
|
-
if (typeof window == "object" && typeof window.ErrorEvent == "function") {
|
|
871
|
-
var n = new window.ErrorEvent("error", {
|
|
872
|
-
bubbles: !0,
|
|
873
|
-
cancelable: !0,
|
|
874
|
-
message: typeof e == "object" && e !== null && typeof e.message == "string" ? String(e.message) : String(e),
|
|
875
|
-
error: e
|
|
876
|
-
});
|
|
877
|
-
if (!window.dispatchEvent(n)) return;
|
|
878
|
-
} else if (typeof process == "object" && typeof process.emit == "function") {
|
|
879
|
-
process.emit("uncaughtException", e);
|
|
880
|
-
return;
|
|
881
|
-
}
|
|
882
|
-
console.error(e);
|
|
883
|
-
}, je = !1, pe = null, de = 0, he = !1, ve = !1, Ie = typeof queueMicrotask == "function" ? function(e) {
|
|
884
|
-
queueMicrotask(function() {
|
|
885
|
-
return queueMicrotask(e);
|
|
886
|
-
});
|
|
887
|
-
} : x;
|
|
888
|
-
D = Object.freeze({
|
|
889
|
-
__proto__: null,
|
|
890
|
-
c: function(e) {
|
|
891
|
-
return C().useMemoCache(e);
|
|
892
|
-
}
|
|
893
|
-
}), r.Children = {
|
|
894
|
-
map: Q,
|
|
895
|
-
forEach: function(e, n, s) {
|
|
896
|
-
Q(
|
|
897
|
-
e,
|
|
898
|
-
function() {
|
|
899
|
-
n.apply(this, arguments);
|
|
900
|
-
},
|
|
901
|
-
s
|
|
902
|
-
);
|
|
903
|
-
},
|
|
904
|
-
count: function(e) {
|
|
905
|
-
var n = 0;
|
|
906
|
-
return Q(e, function() {
|
|
907
|
-
n++;
|
|
908
|
-
}), n;
|
|
909
|
-
},
|
|
910
|
-
toArray: function(e) {
|
|
911
|
-
return Q(e, function(n) {
|
|
912
|
-
return n;
|
|
913
|
-
}) || [];
|
|
914
|
-
},
|
|
915
|
-
only: function(e) {
|
|
916
|
-
if (!l(e))
|
|
917
|
-
throw Error(
|
|
918
|
-
"React.Children.only expected to receive a single React element child."
|
|
919
|
-
);
|
|
920
|
-
return e;
|
|
921
|
-
}
|
|
922
|
-
}, r.Component = P, r.Fragment = t, r.Profiler = a, r.PureComponent = T, r.StrictMode = o, r.Suspense = d, r.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = m, r.__COMPILER_RUNTIME = D, r.act = function(e) {
|
|
923
|
-
var n = m.actQueue, s = de;
|
|
924
|
-
de++;
|
|
925
|
-
var u = m.actQueue = n !== null ? n : [], i = !1;
|
|
926
|
-
try {
|
|
927
|
-
var y = e();
|
|
928
|
-
} catch (E) {
|
|
929
|
-
m.thrownErrors.push(E);
|
|
930
|
-
}
|
|
931
|
-
if (0 < m.thrownErrors.length)
|
|
932
|
-
throw M(n, s), e = J(m.thrownErrors), m.thrownErrors.length = 0, e;
|
|
933
|
-
if (y !== null && typeof y == "object" && typeof y.then == "function") {
|
|
934
|
-
var p = y;
|
|
935
|
-
return Ie(function() {
|
|
936
|
-
i || he || (he = !0, console.error(
|
|
937
|
-
"You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes. You should - await act(async () => ...);"
|
|
938
|
-
));
|
|
939
|
-
}), {
|
|
940
|
-
then: function(E, X) {
|
|
941
|
-
i = !0, p.then(
|
|
942
|
-
function(re) {
|
|
943
|
-
if (M(n, s), s === 0) {
|
|
944
|
-
try {
|
|
945
|
-
ie(u), x(function() {
|
|
946
|
-
return K(
|
|
947
|
-
re,
|
|
948
|
-
E,
|
|
949
|
-
X
|
|
950
|
-
);
|
|
951
|
-
});
|
|
952
|
-
} catch (ze) {
|
|
953
|
-
m.thrownErrors.push(ze);
|
|
954
|
-
}
|
|
955
|
-
if (0 < m.thrownErrors.length) {
|
|
956
|
-
var qe = J(
|
|
957
|
-
m.thrownErrors
|
|
958
|
-
);
|
|
959
|
-
m.thrownErrors.length = 0, X(qe);
|
|
960
|
-
}
|
|
961
|
-
} else E(re);
|
|
962
|
-
},
|
|
963
|
-
function(re) {
|
|
964
|
-
M(n, s), 0 < m.thrownErrors.length && (re = J(
|
|
965
|
-
m.thrownErrors
|
|
966
|
-
), m.thrownErrors.length = 0), X(re);
|
|
967
|
-
}
|
|
968
|
-
);
|
|
168
|
+
};
|
|
169
|
+
this.socket.onclose = (event) => {
|
|
170
|
+
this.log('WebSocket连接关闭:', event.code, event.reason);
|
|
171
|
+
this.setStatus(ConnectionStatus.DISCONNECTED);
|
|
172
|
+
this.stopHeartbeat();
|
|
173
|
+
this.eventListeners.close?.(event);
|
|
174
|
+
// 如果不是主动断开,尝试重连
|
|
175
|
+
if (event.code !== 1000 && this.reconnectAttempts < (this.config.maxReconnectAttempts || 5)) {
|
|
176
|
+
this.scheduleReconnect();
|
|
969
177
|
}
|
|
970
|
-
};
|
|
971
|
-
}
|
|
972
|
-
var R = y;
|
|
973
|
-
if (M(n, s), s === 0 && (ie(u), u.length !== 0 && Ie(function() {
|
|
974
|
-
i || he || (he = !0, console.error(
|
|
975
|
-
"A component suspended inside an `act` scope, but the `act` call was not awaited. When testing React components that depend on asynchronous data, you must await the result:\n\nawait act(() => ...)"
|
|
976
|
-
));
|
|
977
|
-
}), m.actQueue = null), 0 < m.thrownErrors.length)
|
|
978
|
-
throw e = J(m.thrownErrors), m.thrownErrors.length = 0, e;
|
|
979
|
-
return {
|
|
980
|
-
then: function(E, X) {
|
|
981
|
-
i = !0, s === 0 ? (m.actQueue = u, x(function() {
|
|
982
|
-
return K(
|
|
983
|
-
R,
|
|
984
|
-
E,
|
|
985
|
-
X
|
|
986
|
-
);
|
|
987
|
-
})) : E(R);
|
|
988
|
-
}
|
|
989
178
|
};
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
179
|
+
this.socket.onerror = (error) => {
|
|
180
|
+
this.log('WebSocket错误:', error);
|
|
181
|
+
this.setStatus(ConnectionStatus.ERROR);
|
|
182
|
+
this.eventListeners.error?.(error);
|
|
993
183
|
};
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
if (n != null) {
|
|
1004
|
-
var p;
|
|
1005
|
-
e: {
|
|
1006
|
-
if (le.call(n, "ref") && (p = Object.getOwnPropertyDescriptor(
|
|
1007
|
-
n,
|
|
1008
|
-
"ref"
|
|
1009
|
-
).get) && p.isReactWarning) {
|
|
1010
|
-
p = !1;
|
|
1011
|
-
break e;
|
|
1012
|
-
}
|
|
1013
|
-
p = n.ref !== void 0;
|
|
1014
|
-
}
|
|
1015
|
-
p && (y = z()), V(n) && (I(n.key), i = "" + n.key);
|
|
1016
|
-
for (R in n)
|
|
1017
|
-
!le.call(n, R) || R === "key" || R === "__self" || R === "__source" || R === "ref" && n.ref === void 0 || (u[R] = n[R]);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* 设置连接状态
|
|
187
|
+
*/
|
|
188
|
+
setStatus(status) {
|
|
189
|
+
if (this.status !== status) {
|
|
190
|
+
this.status = status;
|
|
191
|
+
this.log('连接状态变更:', status);
|
|
192
|
+
this.eventListeners.statusChange?.(status);
|
|
1018
193
|
}
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* 安排重连
|
|
197
|
+
*/
|
|
198
|
+
scheduleReconnect() {
|
|
199
|
+
if (this.reconnectTimer)
|
|
200
|
+
return;
|
|
201
|
+
this.reconnectAttempts++;
|
|
202
|
+
this.setStatus(ConnectionStatus.RECONNECTING);
|
|
203
|
+
this.log(`准备重连 (第${this.reconnectAttempts}次)...`);
|
|
204
|
+
this.reconnectTimer = setTimeout(() => {
|
|
205
|
+
this.reconnectTimer = null;
|
|
206
|
+
this.connect().catch(() => {
|
|
207
|
+
// 重连失败,继续尝试
|
|
208
|
+
});
|
|
209
|
+
}, this.config.reconnectInterval || 3000);
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* 清除重连定时器
|
|
213
|
+
*/
|
|
214
|
+
clearReconnectTimer() {
|
|
215
|
+
if (this.reconnectTimer) {
|
|
216
|
+
clearTimeout(this.reconnectTimer);
|
|
217
|
+
this.reconnectTimer = null;
|
|
1026
218
|
}
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
}, r.createContext = function(e) {
|
|
1040
|
-
return e = {
|
|
1041
|
-
$$typeof: v,
|
|
1042
|
-
_currentValue: e,
|
|
1043
|
-
_currentValue2: e,
|
|
1044
|
-
_threadCount: 0,
|
|
1045
|
-
Provider: null,
|
|
1046
|
-
Consumer: null
|
|
1047
|
-
}, e.Provider = e, e.Consumer = {
|
|
1048
|
-
$$typeof: c,
|
|
1049
|
-
_context: e
|
|
1050
|
-
}, e._currentRenderer = null, e._currentRenderer2 = null, e;
|
|
1051
|
-
}, r.createElement = function(e, n, s) {
|
|
1052
|
-
for (var u = 2; u < arguments.length; u++) {
|
|
1053
|
-
var i = arguments[u];
|
|
1054
|
-
l(i) && i._store && (i._store.validated = 1);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* 开始心跳检测
|
|
222
|
+
*/
|
|
223
|
+
startHeartbeat() {
|
|
224
|
+
this.stopHeartbeat();
|
|
225
|
+
if (this.config.heartbeatInterval && this.config.heartbeatInterval > 0) {
|
|
226
|
+
this.heartbeatTimer = setInterval(() => {
|
|
227
|
+
if (this.isConnected()) {
|
|
228
|
+
this.send('ping');
|
|
229
|
+
}
|
|
230
|
+
}, this.config.heartbeatInterval);
|
|
1055
231
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
for (var p = Array(y), R = 0; R < y; R++)
|
|
1065
|
-
p[R] = arguments[R + 2];
|
|
1066
|
-
Object.freeze && Object.freeze(p), u.children = p;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* 停止心跳检测
|
|
235
|
+
*/
|
|
236
|
+
stopHeartbeat() {
|
|
237
|
+
if (this.heartbeatTimer) {
|
|
238
|
+
clearInterval(this.heartbeatTimer);
|
|
239
|
+
this.heartbeatTimer = null;
|
|
1067
240
|
}
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
var E = 1e4 > m.recentlyCreatedOwnerStacks++;
|
|
1076
|
-
return G(
|
|
1077
|
-
e,
|
|
1078
|
-
i,
|
|
1079
|
-
void 0,
|
|
1080
|
-
void 0,
|
|
1081
|
-
z(),
|
|
1082
|
-
u,
|
|
1083
|
-
E ? Error("react-stack-top-frame") : Ue,
|
|
1084
|
-
E ? Ce($(e)) : We
|
|
1085
|
-
);
|
|
1086
|
-
}, r.createRef = function() {
|
|
1087
|
-
var e = { current: null };
|
|
1088
|
-
return Object.seal(e), e;
|
|
1089
|
-
}, r.forwardRef = function(e) {
|
|
1090
|
-
e != null && e.$$typeof === k ? console.error(
|
|
1091
|
-
"forwardRef requires a render function but received a `memo` component. Instead of forwardRef(memo(...)), use memo(forwardRef(...))."
|
|
1092
|
-
) : typeof e != "function" ? console.error(
|
|
1093
|
-
"forwardRef requires a render function but was given %s.",
|
|
1094
|
-
e === null ? "null" : typeof e
|
|
1095
|
-
) : e.length !== 0 && e.length !== 2 && console.error(
|
|
1096
|
-
"forwardRef render functions accept exactly two parameters: props and ref. %s",
|
|
1097
|
-
e.length === 1 ? "Did you forget to use the ref parameter?" : "Any additional parameter will be undefined."
|
|
1098
|
-
), e != null && e.defaultProps != null && console.error(
|
|
1099
|
-
"forwardRef render functions do not support defaultProps. Did you accidentally pass a React component?"
|
|
1100
|
-
);
|
|
1101
|
-
var n = { $$typeof: b, render: e }, s;
|
|
1102
|
-
return Object.defineProperty(n, "displayName", {
|
|
1103
|
-
enumerable: !1,
|
|
1104
|
-
configurable: !0,
|
|
1105
|
-
get: function() {
|
|
1106
|
-
return s;
|
|
1107
|
-
},
|
|
1108
|
-
set: function(u) {
|
|
1109
|
-
s = u, e.name || e.displayName || (Object.defineProperty(e, "name", { value: u }), e.displayName = u);
|
|
1110
|
-
}
|
|
1111
|
-
}), n;
|
|
1112
|
-
}, r.isValidElement = l, r.lazy = function(e) {
|
|
1113
|
-
return {
|
|
1114
|
-
$$typeof: ne,
|
|
1115
|
-
_payload: { _status: -1, _result: e },
|
|
1116
|
-
_init: me
|
|
1117
|
-
};
|
|
1118
|
-
}, r.memo = function(e, n) {
|
|
1119
|
-
e == null && console.error(
|
|
1120
|
-
"memo: The first argument must be a component. Instead received: %s",
|
|
1121
|
-
e === null ? "null" : typeof e
|
|
1122
|
-
), n = {
|
|
1123
|
-
$$typeof: k,
|
|
1124
|
-
type: e,
|
|
1125
|
-
compare: n === void 0 ? null : n
|
|
1126
|
-
};
|
|
1127
|
-
var s;
|
|
1128
|
-
return Object.defineProperty(n, "displayName", {
|
|
1129
|
-
enumerable: !1,
|
|
1130
|
-
configurable: !0,
|
|
1131
|
-
get: function() {
|
|
1132
|
-
return s;
|
|
1133
|
-
},
|
|
1134
|
-
set: function(u) {
|
|
1135
|
-
s = u, e.name || e.displayName || (Object.defineProperty(e, "name", { value: u }), e.displayName = u);
|
|
1136
|
-
}
|
|
1137
|
-
}), n;
|
|
1138
|
-
}, r.startTransition = function(e) {
|
|
1139
|
-
var n = m.T, s = {};
|
|
1140
|
-
m.T = s, s._updatedFibers = /* @__PURE__ */ new Set();
|
|
1141
|
-
try {
|
|
1142
|
-
var u = e(), i = m.S;
|
|
1143
|
-
i !== null && i(s, u), typeof u == "object" && u !== null && typeof u.then == "function" && u.then(ue, Pe);
|
|
1144
|
-
} catch (y) {
|
|
1145
|
-
Pe(y);
|
|
1146
|
-
} finally {
|
|
1147
|
-
n === null && s._updatedFibers && (e = s._updatedFibers.size, s._updatedFibers.clear(), 10 < e && console.warn(
|
|
1148
|
-
"Detected a large number of updates inside startTransition. If this is due to a subscription please re-write it to use React provided hooks. Otherwise concurrent mode guarantees are off the table."
|
|
1149
|
-
)), m.T = n;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* 日志输出
|
|
244
|
+
*/
|
|
245
|
+
log(...args) {
|
|
246
|
+
if (this.config.debug) {
|
|
247
|
+
console.log('[SocketConnection]', ...args);
|
|
1150
248
|
}
|
|
1151
|
-
}, r.unstable_useCacheRefresh = function() {
|
|
1152
|
-
return C().useCacheRefresh();
|
|
1153
|
-
}, r.use = function(e) {
|
|
1154
|
-
return C().use(e);
|
|
1155
|
-
}, r.useActionState = function(e, n, s) {
|
|
1156
|
-
return C().useActionState(
|
|
1157
|
-
e,
|
|
1158
|
-
n,
|
|
1159
|
-
s
|
|
1160
|
-
);
|
|
1161
|
-
}, r.useCallback = function(e, n) {
|
|
1162
|
-
return C().useCallback(e, n);
|
|
1163
|
-
}, r.useContext = function(e) {
|
|
1164
|
-
var n = C();
|
|
1165
|
-
return e.$$typeof === c && console.error(
|
|
1166
|
-
"Calling useContext(Context.Consumer) is not supported and will cause bugs. Did you mean to call useContext(Context) instead?"
|
|
1167
|
-
), n.useContext(e);
|
|
1168
|
-
}, r.useDebugValue = function(e, n) {
|
|
1169
|
-
return C().useDebugValue(e, n);
|
|
1170
|
-
}, r.useDeferredValue = function(e, n) {
|
|
1171
|
-
return C().useDeferredValue(e, n);
|
|
1172
|
-
}, r.useEffect = function(e, n, s) {
|
|
1173
|
-
e == null && console.warn(
|
|
1174
|
-
"React Hook useEffect requires an effect callback. Did you forget to pass a callback to the hook?"
|
|
1175
|
-
);
|
|
1176
|
-
var u = C();
|
|
1177
|
-
if (typeof s == "function")
|
|
1178
|
-
throw Error(
|
|
1179
|
-
"useEffect CRUD overload is not enabled in this build of React."
|
|
1180
|
-
);
|
|
1181
|
-
return u.useEffect(e, n);
|
|
1182
|
-
}, r.useId = function() {
|
|
1183
|
-
return C().useId();
|
|
1184
|
-
}, r.useImperativeHandle = function(e, n, s) {
|
|
1185
|
-
return C().useImperativeHandle(e, n, s);
|
|
1186
|
-
}, r.useInsertionEffect = function(e, n) {
|
|
1187
|
-
return e == null && console.warn(
|
|
1188
|
-
"React Hook useInsertionEffect requires an effect callback. Did you forget to pass a callback to the hook?"
|
|
1189
|
-
), C().useInsertionEffect(e, n);
|
|
1190
|
-
}, r.useLayoutEffect = function(e, n) {
|
|
1191
|
-
return e == null && console.warn(
|
|
1192
|
-
"React Hook useLayoutEffect requires an effect callback. Did you forget to pass a callback to the hook?"
|
|
1193
|
-
), C().useLayoutEffect(e, n);
|
|
1194
|
-
}, r.useMemo = function(e, n) {
|
|
1195
|
-
return C().useMemo(e, n);
|
|
1196
|
-
}, r.useOptimistic = function(e, n) {
|
|
1197
|
-
return C().useOptimistic(e, n);
|
|
1198
|
-
}, r.useReducer = function(e, n, s) {
|
|
1199
|
-
return C().useReducer(e, n, s);
|
|
1200
|
-
}, r.useRef = function(e) {
|
|
1201
|
-
return C().useRef(e);
|
|
1202
|
-
}, r.useState = function(e) {
|
|
1203
|
-
return C().useState(e);
|
|
1204
|
-
}, r.useSyncExternalStore = function(e, n, s) {
|
|
1205
|
-
return C().useSyncExternalStore(
|
|
1206
|
-
e,
|
|
1207
|
-
n,
|
|
1208
|
-
s
|
|
1209
|
-
);
|
|
1210
|
-
}, r.useTransition = function() {
|
|
1211
|
-
return C().useTransition();
|
|
1212
|
-
}, r.version = "19.1.1", typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
1213
|
-
})();
|
|
1214
|
-
})(ce, ce.exports)), ce.exports;
|
|
1215
|
-
}
|
|
1216
|
-
var $e;
|
|
1217
|
-
function Xe() {
|
|
1218
|
-
return $e || ($e = 1, process.env.NODE_ENV === "production" ? Ee.exports = Qe() : Ee.exports = Ke()), Ee.exports;
|
|
1219
|
-
}
|
|
1220
|
-
var S = Xe();
|
|
1221
|
-
function Me(_) {
|
|
1222
|
-
const [r, h] = S.useState(H.DISCONNECTED), [w, A] = S.useState(null), [P, Y] = S.useState(0), T = S.useRef(null), N = S.useRef(!1), I = S.useRef(_);
|
|
1223
|
-
S.useEffect(() => {
|
|
1224
|
-
I.current = _;
|
|
1225
|
-
}, [_]);
|
|
1226
|
-
const L = S.useCallback(() => {
|
|
1227
|
-
if (!T.current)
|
|
1228
|
-
try {
|
|
1229
|
-
T.current = ge.getInstance(I.current);
|
|
1230
|
-
} catch (l) {
|
|
1231
|
-
throw console.error("Failed to create socket instance:", l), l;
|
|
1232
|
-
}
|
|
1233
|
-
return T.current;
|
|
1234
|
-
}, []), $ = S.useCallback(async () => {
|
|
1235
|
-
try {
|
|
1236
|
-
A(null), await L().connect();
|
|
1237
|
-
} catch (l) {
|
|
1238
|
-
throw A(l), l;
|
|
1239
249
|
}
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
const O = T.current;
|
|
1248
|
-
return O ? O.sendJSON(l) : !1;
|
|
1249
|
-
}, []), ee = S.useCallback((l, O) => {
|
|
1250
|
-
const g = T.current;
|
|
1251
|
-
g && g.on(l, O);
|
|
1252
|
-
}, []), U = S.useCallback((l) => {
|
|
1253
|
-
const O = T.current;
|
|
1254
|
-
O && O.off(l);
|
|
1255
|
-
}, []), G = S.useCallback(async () => {
|
|
1256
|
-
z(), await new Promise((l) => setTimeout(l, 1e3)), await $();
|
|
1257
|
-
}, [z, $]);
|
|
1258
|
-
S.useEffect(() => {
|
|
1259
|
-
if (!N.current)
|
|
1260
|
-
try {
|
|
1261
|
-
const l = L();
|
|
1262
|
-
l.on("statusChange", (O) => {
|
|
1263
|
-
h(O), O === H.RECONNECTING ? Y((g) => g + 1) : O === H.CONNECTED && Y(0);
|
|
1264
|
-
}), l.on("error", (O) => {
|
|
1265
|
-
A(O);
|
|
1266
|
-
}), l.on("close", () => {
|
|
1267
|
-
A(null);
|
|
1268
|
-
}), N.current = !0;
|
|
1269
|
-
} catch (l) {
|
|
1270
|
-
console.error("Failed to initialize socket:", l), A(l);
|
|
1271
|
-
}
|
|
1272
|
-
}, [L]), S.useEffect(() => {
|
|
1273
|
-
_.autoConnect !== !1 && !N.current && $().catch(console.error);
|
|
1274
|
-
}, [_.autoConnect, $]), S.useEffect(() => () => {
|
|
1275
|
-
const l = T.current;
|
|
1276
|
-
l && _.autoConnect !== !1 && l.disconnect();
|
|
1277
|
-
}, [_.autoConnect]);
|
|
1278
|
-
const Z = r === H.CONNECTED;
|
|
1279
|
-
return {
|
|
1280
|
-
status: r,
|
|
1281
|
-
isConnected: Z,
|
|
1282
|
-
connect: $,
|
|
1283
|
-
disconnect: z,
|
|
1284
|
-
send: F,
|
|
1285
|
-
sendJSON: V,
|
|
1286
|
-
on: ee,
|
|
1287
|
-
off: U,
|
|
1288
|
-
error: w,
|
|
1289
|
-
reconnectAttempts: P,
|
|
1290
|
-
reconnect: G
|
|
1291
|
-
};
|
|
1292
|
-
}
|
|
1293
|
-
function Ve(_, r) {
|
|
1294
|
-
const h = Me(_);
|
|
1295
|
-
return S.useEffect(() => (h.on("message", (w) => {
|
|
1296
|
-
try {
|
|
1297
|
-
const A = typeof w == "string" ? JSON.parse(w) : w;
|
|
1298
|
-
r(A);
|
|
1299
|
-
} catch (A) {
|
|
1300
|
-
console.error("Failed to parse message:", A);
|
|
250
|
+
/**
|
|
251
|
+
* 销毁实例
|
|
252
|
+
*/
|
|
253
|
+
destroy() {
|
|
254
|
+
this.disconnect();
|
|
255
|
+
this.eventListeners = {};
|
|
256
|
+
SocketConnection.instance = null;
|
|
1301
257
|
}
|
|
1302
|
-
}), () => {
|
|
1303
|
-
h.off("message");
|
|
1304
|
-
}), [h, r]), h;
|
|
1305
258
|
}
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
w.off("statusChange");
|
|
1310
|
-
}), [w]), {
|
|
1311
|
-
status: r,
|
|
1312
|
-
isConnected: r === H.CONNECTED,
|
|
1313
|
-
isConnecting: r === H.CONNECTING,
|
|
1314
|
-
isReconnecting: r === H.RECONNECTING,
|
|
1315
|
-
isDisconnected: r === H.DISCONNECTED,
|
|
1316
|
-
hasError: r === H.ERROR
|
|
1317
|
-
};
|
|
1318
|
-
}
|
|
1319
|
-
var H = /* @__PURE__ */ ((_) => (_.CONNECTING = "connecting", _.CONNECTED = "connected", _.DISCONNECTED = "disconnected", _.RECONNECTING = "reconnecting", _.ERROR = "error", _))(H || {});
|
|
1320
|
-
const j = class j {
|
|
1321
|
-
constructor(r) {
|
|
1322
|
-
q(this, "socket", null);
|
|
1323
|
-
q(this, "config");
|
|
1324
|
-
q(this, "status", "disconnected");
|
|
1325
|
-
q(this, "reconnectAttempts", 0);
|
|
1326
|
-
q(this, "reconnectTimer", null);
|
|
1327
|
-
q(this, "heartbeatTimer", null);
|
|
1328
|
-
q(this, "eventListeners", {});
|
|
1329
|
-
this.config = {
|
|
1330
|
-
reconnectInterval: 3e3,
|
|
1331
|
-
maxReconnectAttempts: 5,
|
|
1332
|
-
heartbeatInterval: 3e4,
|
|
1333
|
-
debug: !1,
|
|
1334
|
-
...r
|
|
1335
|
-
};
|
|
1336
|
-
}
|
|
1337
|
-
/**
|
|
1338
|
-
* 获取单例实例
|
|
1339
|
-
*/
|
|
1340
|
-
static getInstance(r) {
|
|
1341
|
-
if (j.instance)
|
|
1342
|
-
r && (JSON.stringify(j.instance.config) !== JSON.stringify(r) && (j.instance = new j(r)), r && (j.instance.config = {
|
|
1343
|
-
...j.instance.config,
|
|
1344
|
-
...r
|
|
1345
|
-
}));
|
|
1346
|
-
else {
|
|
1347
|
-
if (!r)
|
|
1348
|
-
throw new Error("首次创建SocketConnection实例时必须提供配置");
|
|
1349
|
-
j.instance = new j(r);
|
|
1350
|
-
}
|
|
1351
|
-
return j.instance;
|
|
1352
|
-
}
|
|
1353
|
-
/**
|
|
1354
|
-
* 连接WebSocket
|
|
1355
|
-
*/
|
|
1356
|
-
connect(r) {
|
|
1357
|
-
return this.config = {
|
|
1358
|
-
...this.config,
|
|
1359
|
-
...r
|
|
1360
|
-
}, new Promise((h, w) => {
|
|
1361
|
-
var P, Y;
|
|
1362
|
-
if (((P = this.socket) == null ? void 0 : P.readyState) === WebSocket.OPEN) {
|
|
1363
|
-
h();
|
|
1364
|
-
return;
|
|
1365
|
-
}
|
|
1366
|
-
const A = this.config.url + ((Y = this.config) != null && Y.params ? `?${Object.entries(this.config.params).map(([T, N]) => `${T}=${N}`).join("&")}` : "");
|
|
1367
|
-
if (A) {
|
|
1368
|
-
this.setStatus(
|
|
1369
|
-
"connecting"
|
|
1370
|
-
/* CONNECTING */
|
|
1371
|
-
), this.log("正在连接WebSocket...", A);
|
|
1372
|
-
try {
|
|
1373
|
-
this.socket = new WebSocket(A, this.config.protocols), this.setupEventListeners(), this.socket.onopen = () => {
|
|
1374
|
-
var T, N;
|
|
1375
|
-
this.log("WebSocket连接成功"), this.setStatus(
|
|
1376
|
-
"connected"
|
|
1377
|
-
/* CONNECTED */
|
|
1378
|
-
), this.reconnectAttempts = 0, this.startHeartbeat(), (N = (T = this.eventListeners).open) == null || N.call(T), h();
|
|
1379
|
-
}, this.socket.onerror = (T) => {
|
|
1380
|
-
var N, I;
|
|
1381
|
-
this.log("WebSocket连接错误:", T), this.setStatus(
|
|
1382
|
-
"error"
|
|
1383
|
-
/* ERROR */
|
|
1384
|
-
), (I = (N = this.eventListeners).error) == null || I.call(N, T), w(T);
|
|
1385
|
-
};
|
|
1386
|
-
} catch (T) {
|
|
1387
|
-
this.log("创建WebSocket连接失败:", T), this.setStatus(
|
|
1388
|
-
"error"
|
|
1389
|
-
/* ERROR */
|
|
1390
|
-
), w(T);
|
|
1391
|
-
}
|
|
1392
|
-
}
|
|
1393
|
-
});
|
|
1394
|
-
}
|
|
1395
|
-
/**
|
|
1396
|
-
* 断开连接
|
|
1397
|
-
*/
|
|
1398
|
-
disconnect() {
|
|
1399
|
-
this.log("正在断开WebSocket连接..."), this.stopHeartbeat(), this.clearReconnectTimer(), this.socket && (this.socket.close(1e3, "主动断开连接"), this.socket = null), this.setStatus(
|
|
1400
|
-
"disconnected"
|
|
1401
|
-
/* DISCONNECTED */
|
|
1402
|
-
);
|
|
1403
|
-
}
|
|
1404
|
-
/**
|
|
1405
|
-
* 发送消息
|
|
1406
|
-
*/
|
|
1407
|
-
send(r) {
|
|
1408
|
-
var h;
|
|
1409
|
-
return ((h = this.socket) == null ? void 0 : h.readyState) === WebSocket.OPEN ? (this.socket.send(r), this.log("发送消息:", r), !0) : (this.log("WebSocket未连接,无法发送消息"), !1);
|
|
1410
|
-
}
|
|
1411
|
-
/**
|
|
1412
|
-
* 发送JSON消息
|
|
1413
|
-
*/
|
|
1414
|
-
sendJSON(r) {
|
|
1415
|
-
return this.send(JSON.stringify(r));
|
|
1416
|
-
}
|
|
1417
|
-
/**
|
|
1418
|
-
* 添加事件监听器
|
|
1419
|
-
*/
|
|
1420
|
-
on(r, h) {
|
|
1421
|
-
this.eventListeners[r] = h;
|
|
1422
|
-
}
|
|
1423
|
-
/**
|
|
1424
|
-
* 移除事件监听器
|
|
1425
|
-
*/
|
|
1426
|
-
off(r) {
|
|
1427
|
-
delete this.eventListeners[r];
|
|
1428
|
-
}
|
|
1429
|
-
/**
|
|
1430
|
-
* 获取连接状态
|
|
1431
|
-
*/
|
|
1432
|
-
getStatus() {
|
|
1433
|
-
return this.status;
|
|
1434
|
-
}
|
|
1435
|
-
/**
|
|
1436
|
-
* 检查是否已连接
|
|
1437
|
-
*/
|
|
1438
|
-
isConnected() {
|
|
1439
|
-
var r;
|
|
1440
|
-
return this.status === "connected" && ((r = this.socket) == null ? void 0 : r.readyState) === WebSocket.OPEN;
|
|
1441
|
-
}
|
|
1442
|
-
/**
|
|
1443
|
-
* 设置事件监听器
|
|
1444
|
-
*/
|
|
1445
|
-
setupEventListeners() {
|
|
1446
|
-
this.socket && (this.socket.onmessage = (r) => {
|
|
1447
|
-
var h, w;
|
|
1448
|
-
this.log("收到消息:", r.data), r.data !== "pong" && ((w = (h = this.eventListeners).message) == null || w.call(h, r.data));
|
|
1449
|
-
}, this.socket.onclose = (r) => {
|
|
1450
|
-
var h, w;
|
|
1451
|
-
this.log("WebSocket连接关闭:", r.code, r.reason), this.setStatus(
|
|
1452
|
-
"disconnected"
|
|
1453
|
-
/* DISCONNECTED */
|
|
1454
|
-
), this.stopHeartbeat(), (w = (h = this.eventListeners).close) == null || w.call(h, r), r.code !== 1e3 && this.reconnectAttempts < (this.config.maxReconnectAttempts || 5) && this.scheduleReconnect();
|
|
1455
|
-
}, this.socket.onerror = (r) => {
|
|
1456
|
-
var h, w;
|
|
1457
|
-
this.log("WebSocket错误:", r), this.setStatus(
|
|
1458
|
-
"error"
|
|
1459
|
-
/* ERROR */
|
|
1460
|
-
), (w = (h = this.eventListeners).error) == null || w.call(h, r);
|
|
1461
|
-
});
|
|
1462
|
-
}
|
|
1463
|
-
/**
|
|
1464
|
-
* 设置连接状态
|
|
1465
|
-
*/
|
|
1466
|
-
setStatus(r) {
|
|
1467
|
-
var h, w;
|
|
1468
|
-
this.status !== r && (this.status = r, this.log("连接状态变更:", r), (w = (h = this.eventListeners).statusChange) == null || w.call(h, r));
|
|
1469
|
-
}
|
|
1470
|
-
/**
|
|
1471
|
-
* 安排重连
|
|
1472
|
-
*/
|
|
1473
|
-
scheduleReconnect() {
|
|
1474
|
-
this.reconnectTimer || (this.reconnectAttempts++, this.setStatus(
|
|
1475
|
-
"reconnecting"
|
|
1476
|
-
/* RECONNECTING */
|
|
1477
|
-
), this.log(`准备重连 (第${this.reconnectAttempts}次)...`), this.reconnectTimer = setTimeout(() => {
|
|
1478
|
-
this.reconnectTimer = null, this.connect().catch(() => {
|
|
1479
|
-
});
|
|
1480
|
-
}, this.config.reconnectInterval || 3e3));
|
|
1481
|
-
}
|
|
1482
|
-
/**
|
|
1483
|
-
* 清除重连定时器
|
|
1484
|
-
*/
|
|
1485
|
-
clearReconnectTimer() {
|
|
1486
|
-
this.reconnectTimer && (clearTimeout(this.reconnectTimer), this.reconnectTimer = null);
|
|
1487
|
-
}
|
|
1488
|
-
/**
|
|
1489
|
-
* 开始心跳检测
|
|
1490
|
-
*/
|
|
1491
|
-
startHeartbeat() {
|
|
1492
|
-
this.stopHeartbeat(), this.config.heartbeatInterval && this.config.heartbeatInterval > 0 && (this.heartbeatTimer = setInterval(() => {
|
|
1493
|
-
this.isConnected() && this.send("ping");
|
|
1494
|
-
}, this.config.heartbeatInterval));
|
|
1495
|
-
}
|
|
1496
|
-
/**
|
|
1497
|
-
* 停止心跳检测
|
|
1498
|
-
*/
|
|
1499
|
-
stopHeartbeat() {
|
|
1500
|
-
this.heartbeatTimer && (clearInterval(this.heartbeatTimer), this.heartbeatTimer = null);
|
|
1501
|
-
}
|
|
1502
|
-
/**
|
|
1503
|
-
* 日志输出
|
|
1504
|
-
*/
|
|
1505
|
-
log(...r) {
|
|
1506
|
-
this.config.debug && console.log("[SocketConnection]", ...r);
|
|
1507
|
-
}
|
|
1508
|
-
/**
|
|
1509
|
-
* 销毁实例
|
|
1510
|
-
*/
|
|
1511
|
-
destroy() {
|
|
1512
|
-
this.disconnect(), this.eventListeners = {}, j.instance = null;
|
|
1513
|
-
}
|
|
1514
|
-
};
|
|
1515
|
-
q(j, "instance", null);
|
|
1516
|
-
let ge = j;
|
|
1517
|
-
export {
|
|
1518
|
-
H as ConnectionStatus,
|
|
1519
|
-
ge as default,
|
|
1520
|
-
Me as useSocket,
|
|
1521
|
-
Ve as useSocketMessage,
|
|
1522
|
-
Ze as useSocketStatus
|
|
1523
|
-
};
|
|
259
|
+
export default SocketConnection;
|
|
260
|
+
// 导出React Hooks
|
|
261
|
+
export { useSocket, useSocketMessage, useSocketStatus } from './useSocket.js';
|