vue-streaming 2.0.1 → 2.0.2

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.
Files changed (28) hide show
  1. package/dist/WebSocketStream.vue_vue_type_script_setup_true_lang-D5IiGqMS.cjs +2 -0
  2. package/dist/WebSocketStream.vue_vue_type_script_setup_true_lang-D5IiGqMS.cjs.map +1 -0
  3. package/dist/WebSocketStream.vue_vue_type_script_setup_true_lang-D5yjtuTd.js +1240 -0
  4. package/dist/WebSocketStream.vue_vue_type_script_setup_true_lang-D5yjtuTd.js.map +1 -0
  5. package/dist/components/index.cjs +1 -1
  6. package/dist/components/index.js +3 -2
  7. package/dist/composables/index.cjs +1 -1
  8. package/dist/composables/index.js +1 -1
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.js +53 -51
  11. package/dist/useWebSocket--HDylHpA.cjs +4 -0
  12. package/dist/useWebSocket--HDylHpA.cjs.map +1 -0
  13. package/dist/useWebSocket-C3JPFBmy.js +1328 -0
  14. package/dist/useWebSocket-C3JPFBmy.js.map +1 -0
  15. package/dist/utils/index.cjs +1 -1
  16. package/dist/utils/index.cjs.map +1 -1
  17. package/dist/utils/index.js +48 -38
  18. package/dist/utils/index.js.map +1 -1
  19. package/dist/vue-streaming.css +1 -1
  20. package/package.json +9 -2
  21. package/dist/WebSocketStream.vue_vue_type_script_setup_true_lang-BzBWoH8H.js +0 -1083
  22. package/dist/WebSocketStream.vue_vue_type_script_setup_true_lang-BzBWoH8H.js.map +0 -1
  23. package/dist/WebSocketStream.vue_vue_type_script_setup_true_lang-C7Kci1ME.cjs +0 -2
  24. package/dist/WebSocketStream.vue_vue_type_script_setup_true_lang-C7Kci1ME.cjs.map +0 -1
  25. package/dist/useWebSocket-8VThnC_J.cjs +0 -4
  26. package/dist/useWebSocket-8VThnC_J.cjs.map +0 -1
  27. package/dist/useWebSocket-D1Rqm0H7.js +0 -1278
  28. package/dist/useWebSocket-D1Rqm0H7.js.map +0 -1
@@ -0,0 +1,1328 @@
1
+ import { ref as v, onUnmounted as U } from "vue";
2
+ import { parseArrayBboxFormat as K, normalizeBboxes as V, bboxesToDetectionFrame as q, parsePointCloudJSON as J, parsePointCloudBinary as Q, createReconnectManager as G } from "./utils/index.js";
3
+ const X = {
4
+ autoPlay: !0,
5
+ startLevel: -1,
6
+ lowLatencyMode: !1,
7
+ maxBufferLength: 30,
8
+ maxMaxBufferLength: 600,
9
+ enableWorker: !0,
10
+ startPosition: -1,
11
+ hlsConfig: {}
12
+ };
13
+ function se(N, e = {}) {
14
+ const n = { ...X, ...N }, d = v("idle"), a = v(!1), m = v(!1), y = v([]), A = v(-1), T = v(!0), f = v(0), i = v(0), w = v(0), S = v(1), R = v(!1), L = v({
15
+ bandwidth: 0,
16
+ buffered: 0,
17
+ dropped: 0,
18
+ loaded: 0,
19
+ currentLevel: -1,
20
+ bufferedDuration: 0,
21
+ droppedFrames: 0,
22
+ latency: 0
23
+ }), I = v(null), F = v(!1);
24
+ let E = null, O = null, p = null, D = null;
25
+ async function u() {
26
+ if (O) return O;
27
+ try {
28
+ const l = await import("hls.js");
29
+ return O = l.default || l, F.value = O.isSupported(), O;
30
+ } catch {
31
+ return console.error("[useHLS] hls.js not installed. Run: npm install hls.js"), null;
32
+ }
33
+ }
34
+ function h() {
35
+ if (p && (f.value = p.currentTime, i.value = p.duration || 0, p.buffered.length > 0)) {
36
+ const l = p.buffered.end(
37
+ p.buffered.length - 1
38
+ );
39
+ w.value = i.value > 0 ? l / i.value * 100 : 0, L.value.bufferedDuration = l - p.currentTime;
40
+ }
41
+ }
42
+ function t(l) {
43
+ l.onplay = () => {
44
+ var g;
45
+ a.value = !0, d.value = "playing", (g = e.onPlaybackStarted) == null || g.call(e);
46
+ }, l.onpause = () => {
47
+ a.value = !1, d.value = "paused";
48
+ }, l.onended = () => {
49
+ var g;
50
+ a.value = !1, d.value = "ended", (g = e.onPlaybackEnded) == null || g.call(e);
51
+ }, l.onwaiting = () => {
52
+ var g;
53
+ m.value = !0, d.value = "buffering", (g = e.onBuffering) == null || g.call(e);
54
+ }, l.onplaying = () => {
55
+ var g;
56
+ m.value = !1, d.value === "buffering" && (d.value = "playing"), (g = e.onBuffered) == null || g.call(e);
57
+ }, l.onseeking = () => {
58
+ d.value = "seeking";
59
+ }, l.onseeked = () => {
60
+ d.value = a.value ? "playing" : "paused";
61
+ }, l.onvolumechange = () => {
62
+ S.value = l.volume, R.value = l.muted;
63
+ }, l.onerror = () => {
64
+ var _, H;
65
+ const g = new Error(((_ = l.error) == null ? void 0 : _.message) || "Video playback error");
66
+ I.value = g, d.value = "error", (H = e.onError) == null || H.call(e, g, !0);
67
+ }, D = setInterval(h, 250);
68
+ }
69
+ function s() {
70
+ !E || !O || (E.on(
71
+ O.Events.MANIFEST_PARSED,
72
+ (l, g) => {
73
+ var _;
74
+ y.value = g.levels.map((H, z) => ({
75
+ index: z,
76
+ bitrate: H.bitrate,
77
+ width: H.width,
78
+ height: H.height,
79
+ codec: H.codec,
80
+ name: `${H.height}p`
81
+ })), d.value = "loaded", (_ = e.onManifestLoaded) == null || _.call(e, y.value);
82
+ }
83
+ ), E.on(
84
+ O.Events.LEVEL_SWITCHED,
85
+ (l, g) => {
86
+ var _;
87
+ A.value = g.level, L.value.currentLevel = g.level, (_ = e.onLevelSwitched) == null || _.call(e, g.level);
88
+ }
89
+ ), E.on(
90
+ O.Events.FRAG_LOADED,
91
+ (l, g) => {
92
+ L.value.bandwidth = g.frag.duration * 8 * 1e6 / (g.stats.loading.end - g.stats.loading.start);
93
+ }
94
+ ), E.on(
95
+ O.Events.ERROR,
96
+ (l, g) => {
97
+ var H;
98
+ const _ = new Error(`HLS Error: ${g.type} - ${g.details}`);
99
+ g.fatal && (I.value = _, d.value = "error", g.type === O.ErrorTypes.MEDIA_ERROR && (E == null || E.recoverMediaError())), (H = e.onError) == null || H.call(e, _, g.fatal);
100
+ }
101
+ ));
102
+ }
103
+ async function r(l) {
104
+ const g = await u();
105
+ if (!g)
106
+ throw new Error("HLS.js is not available");
107
+ if (!g.isSupported()) {
108
+ if (l.canPlayType("application/vnd.apple.mpegurl")) {
109
+ l.src = n.url, p = l, t(l), d.value = "loaded", n.autoPlay && await M();
110
+ return;
111
+ }
112
+ throw new Error("HLS is not supported in this browser");
113
+ }
114
+ p = l, d.value = "loading", E = new g({
115
+ startLevel: n.startLevel,
116
+ lowLatencyMode: n.lowLatencyMode,
117
+ maxBufferLength: n.maxBufferLength,
118
+ enableWorker: n.enableWorker,
119
+ startPosition: n.startPosition
120
+ }), s(), t(l), E.loadSource(n.url), E.attachMedia(l), n.autoPlay && E.on(g.Events.MANIFEST_PARSED, () => {
121
+ M();
122
+ });
123
+ }
124
+ function o() {
125
+ E && E.detachMedia(), D && (clearInterval(D), D = null), p = null;
126
+ }
127
+ function c(l) {
128
+ const g = l || n.url;
129
+ E ? E.loadSource(g) : p && (p.src = g), d.value = "loading";
130
+ }
131
+ async function M() {
132
+ if (!p)
133
+ throw new Error("No video element attached");
134
+ try {
135
+ await p.play();
136
+ } catch (l) {
137
+ if (l.name === "NotAllowedError")
138
+ R.value = !0, p.muted = !0, await p.play();
139
+ else
140
+ throw l;
141
+ }
142
+ }
143
+ function C() {
144
+ p == null || p.pause();
145
+ }
146
+ function P() {
147
+ E && E.stopLoad(), p && (p.pause(), p.currentTime = 0), a.value = !1, d.value = "idle";
148
+ }
149
+ function x(l) {
150
+ p && (p.currentTime = l);
151
+ }
152
+ function $(l) {
153
+ E && (E.currentLevel = l, T.value = l === -1);
154
+ }
155
+ function j(l) {
156
+ p && (p.volume = Math.max(0, Math.min(1, l)));
157
+ }
158
+ function W() {
159
+ p && (p.muted = !p.muted);
160
+ }
161
+ function B() {
162
+ D && (clearInterval(D), D = null), E && (E.destroy(), E = null), p = null, d.value = "idle", y.value = [], A.value = -1;
163
+ }
164
+ return U(() => {
165
+ B();
166
+ }), {
167
+ state: d,
168
+ isPlaying: a,
169
+ isBuffering: m,
170
+ levels: y,
171
+ currentLevel: A,
172
+ autoLevelEnabled: T,
173
+ currentTime: f,
174
+ duration: i,
175
+ buffered: w,
176
+ volume: S,
177
+ muted: R,
178
+ stats: L,
179
+ error: I,
180
+ isSupported: F,
181
+ attach: r,
182
+ detach: o,
183
+ load: c,
184
+ play: M,
185
+ pause: C,
186
+ stop: P,
187
+ seek: x,
188
+ setLevel: $,
189
+ setVolume: j,
190
+ toggleMute: W,
191
+ destroy: B
192
+ };
193
+ }
194
+ const Y = {
195
+ iceServers: [{ urls: "stun:stun.l.google.com:19302" }],
196
+ iceGatheringTimeout: 2e3,
197
+ enablePointCloud: !0,
198
+ enableDetections: !0,
199
+ autoReconnect: !0,
200
+ maxReconnectAttempts: 5,
201
+ reconnectDelay: 3e3
202
+ };
203
+ function Z(N, e) {
204
+ return new Promise((n) => {
205
+ if (N.iceGatheringState === "complete") {
206
+ n();
207
+ return;
208
+ }
209
+ const d = setTimeout(() => {
210
+ n();
211
+ }, e);
212
+ N.onicegatheringstatechange = () => {
213
+ N.iceGatheringState === "complete" && (clearTimeout(d), n());
214
+ };
215
+ });
216
+ }
217
+ function fe(N, e = {}) {
218
+ const n = { ...Y, ...N }, d = v(!1), a = v("idle"), m = v(/* @__PURE__ */ new Map()), y = v(null), A = v(null), T = v([]), f = v(null);
219
+ let i = null, w = null, S = null, R = null, L = 0, I = null;
220
+ function F(r, o) {
221
+ if (!w || w.readyState !== "open") return;
222
+ const c = { type: "control", stream: r, enabled: o };
223
+ w.send(JSON.stringify(c));
224
+ }
225
+ function E(r, o) {
226
+ const c = m.value.get(r);
227
+ if (!c || c.readyState !== "open")
228
+ return console.warn(`[useWebRTC] Channel ${r} not available`), !1;
229
+ try {
230
+ return c.send(o), !0;
231
+ } catch (M) {
232
+ return console.error(`[useWebRTC] Send error on ${r}:`, M), !1;
233
+ }
234
+ }
235
+ function O(r) {
236
+ var o;
237
+ switch (m.value.set(r.label, r), (o = e.onDataChannel) == null || o.call(e, r), r.label) {
238
+ case "pointcloud":
239
+ p(r);
240
+ break;
241
+ case "pointcloud_b":
242
+ case "bbox":
243
+ case "bounding_boxes":
244
+ case "detections":
245
+ D(r);
246
+ break;
247
+ }
248
+ }
249
+ function p(r) {
250
+ S = r, S.binaryType = "arraybuffer", S.onopen = () => {
251
+ var o;
252
+ (o = e.onStatus) == null || o.call(e, "Pointcloud channel open"), n.enablePointCloud && F("pointcloud", !0);
253
+ }, S.onmessage = (o) => {
254
+ var c, M;
255
+ try {
256
+ let C = [];
257
+ if (o.data instanceof ArrayBuffer && o.data.byteLength > 0) {
258
+ const P = o.data;
259
+ (c = e.onPointCloudData) == null || c.call(e, P);
260
+ try {
261
+ const x = new TextDecoder().decode(P);
262
+ if (x.startsWith("[") || x.startsWith("{")) {
263
+ const $ = J(x);
264
+ $ && $.length > 0 && (C = $);
265
+ }
266
+ } catch {
267
+ }
268
+ C.length === 0 && (C = Q(P));
269
+ } else if (typeof o.data == "string") {
270
+ const P = J(o.data);
271
+ P && (C = P);
272
+ }
273
+ if (C.length > 0) {
274
+ const P = {
275
+ points: C,
276
+ timestamp: Date.now(),
277
+ format: "parsed"
278
+ };
279
+ y.value = P, (M = e.onPointCloudFrame) == null || M.call(e, P);
280
+ }
281
+ } catch (C) {
282
+ console.error("[useWebRTC] Error parsing pointcloud data:", C);
283
+ }
284
+ }, S.onerror = (o) => {
285
+ var c;
286
+ console.error("[useWebRTC] Pointcloud channel error:", o), (c = e.onStatus) == null || c.call(e, "Pointcloud channel error");
287
+ }, S.onclose = () => {
288
+ var o;
289
+ (o = e.onStatus) == null || o.call(e, "Pointcloud channel closed");
290
+ };
291
+ }
292
+ function D(r) {
293
+ R = r, R.binaryType = "arraybuffer", R.onopen = () => {
294
+ var o;
295
+ (o = e.onStatus) == null || o.call(e, "BBox channel open"), n.enableDetections && F("bbox", !0);
296
+ }, R.onmessage = (o) => {
297
+ var c, M;
298
+ try {
299
+ let C;
300
+ if (typeof o.data == "string")
301
+ C = JSON.parse(o.data);
302
+ else if (o.data instanceof ArrayBuffer) {
303
+ const P = new TextDecoder().decode(o.data);
304
+ try {
305
+ C = JSON.parse(P);
306
+ } catch {
307
+ return;
308
+ }
309
+ } else
310
+ return;
311
+ if (Array.isArray(C)) {
312
+ let P;
313
+ if (C.length > 0 && Array.isArray(C[0]) && typeof C[0][0] == "number" ? P = K(C) : P = V(C), P.length > 0) {
314
+ T.value = P, (c = e.onBoundingBoxData) == null || c.call(e, P);
315
+ const x = q(P);
316
+ A.value = x, (M = e.onDetectionFrame) == null || M.call(e, x);
317
+ }
318
+ }
319
+ } catch (C) {
320
+ console.error("[useWebRTC] Error parsing bbox data:", C);
321
+ }
322
+ }, R.onerror = (o) => {
323
+ console.error("[useWebRTC] BBox channel error:", o);
324
+ }, R.onclose = () => {
325
+ var o;
326
+ (o = e.onStatus) == null || o.call(e, "BBox channel closed");
327
+ };
328
+ }
329
+ async function u() {
330
+ var r, o, c, M, C, P;
331
+ if (!d.value) {
332
+ (r = e.onStatus) == null || r.call(e, "Creating WebRTC connection..."), a.value = "connecting", f.value = null;
333
+ try {
334
+ i && (i.close(), i = null), i = new RTCPeerConnection({
335
+ iceServers: n.iceServers
336
+ }), i.onconnectionstatechange = () => {
337
+ var l, g;
338
+ const B = (i == null ? void 0 : i.connectionState) ?? "closed";
339
+ if (a.value = B, (l = e.onConnectionState) == null || l.call(e, B), B === "failed" || B === "disconnected") {
340
+ const _ = new Error(`Connection ${B}`);
341
+ f.value = _, (g = e.onError) == null || g.call(e, _), n.autoReconnect && L < n.maxReconnectAttempts && t();
342
+ }
343
+ B === "connected" && (L = 0);
344
+ }, i.ondatachannel = (B) => {
345
+ O(B.channel);
346
+ }, w = i.createDataChannel("control"), w.onopen = () => {
347
+ var B;
348
+ (B = e.onStatus) == null || B.call(e, "Control channel open"), m.value.set("control", w);
349
+ };
350
+ const x = await i.createOffer();
351
+ await i.setLocalDescription(x), await Z(i, n.iceGatheringTimeout);
352
+ const $ = ((o = i.localDescription) == null ? void 0 : o.sdp) ?? "";
353
+ if (!$) throw new Error("Empty SDP offer");
354
+ const j = await fetch(n.signalingUrl, {
355
+ method: "POST",
356
+ headers: { "Content-Type": "application/json" },
357
+ body: JSON.stringify({ offer: $ })
358
+ });
359
+ if (!j.ok)
360
+ throw new Error(`Signaling failed: HTTP ${j.status}`);
361
+ const W = await j.json();
362
+ if (!W.answer)
363
+ throw new Error("No answer SDP in response");
364
+ await i.setRemoteDescription({ type: "answer", sdp: W.answer }), d.value = !0, (c = e.onStatus) == null || c.call(e, "Connected, waiting for data..."), (M = e.onConnectionState) == null || M.call(e, i.connectionState);
365
+ } catch (x) {
366
+ const $ = x instanceof Error ? x : new Error(String(x));
367
+ f.value = $, a.value = "error", (C = e.onStatus) == null || C.call(e, `Error: ${$.message}`), (P = e.onError) == null || P.call(e, $), h(), n.autoReconnect && L < n.maxReconnectAttempts && t();
368
+ }
369
+ }
370
+ }
371
+ function h() {
372
+ var r, o;
373
+ d.value = !1, a.value = "closed", (r = e.onStatus) == null || r.call(e, "Stopped"), (o = e.onConnectionState) == null || o.call(e, "closed"), I && (clearTimeout(I), I = null), m.value.forEach((c) => c.close()), m.value.clear(), w = null, S = null, R = null, i && (i.close(), i = null);
374
+ }
375
+ function t() {
376
+ var r;
377
+ I || (L++, (r = e.onStatus) == null || r.call(
378
+ e,
379
+ `Reconnecting in ${n.reconnectDelay / 1e3}s (attempt ${L}/${n.maxReconnectAttempts})...`
380
+ ), I = setTimeout(() => {
381
+ I = null, u();
382
+ }, n.reconnectDelay));
383
+ }
384
+ function s() {
385
+ return i;
386
+ }
387
+ return U(() => {
388
+ h();
389
+ }), {
390
+ isRunning: d,
391
+ connectionState: a,
392
+ dataChannels: m,
393
+ lastPointCloudFrame: y,
394
+ lastDetectionFrame: A,
395
+ lastBoundingBoxes: T,
396
+ error: f,
397
+ start: u,
398
+ stop: h,
399
+ sendControl: F,
400
+ sendOnChannel: E,
401
+ getPeerConnection: s
402
+ };
403
+ }
404
+ const b = {
405
+ transform: (N) => N,
406
+ filter: () => !0,
407
+ bufferSize: 100,
408
+ throttleMs: 0,
409
+ flushInterval: 0,
410
+ deduplicate: !1,
411
+ dedupeKey: null,
412
+ deduplicateKey: null,
413
+ batchSize: 0,
414
+ batchTimeoutMs: 0
415
+ };
416
+ function ae(N = {}, e = {}) {
417
+ const n = { ...b, ...N }, d = v(null), a = v([]), m = v(n.bufferSize), y = v(!1), A = v(0), T = v(0), f = v(null), i = /* @__PURE__ */ new Set(), w = /* @__PURE__ */ new Set();
418
+ let S = 0, R = null, L = null, I = [];
419
+ function F() {
420
+ R || (R = setInterval(() => {
421
+ A.value = S, S = 0;
422
+ }, 1e3));
423
+ }
424
+ function E() {
425
+ R && (clearInterval(R), R = null), A.value = 0;
426
+ }
427
+ function O() {
428
+ !n.flushInterval || n.flushInterval <= 0 || L || (L = setInterval(() => {
429
+ var o;
430
+ I.length > 0 && ((o = e.onBatch) == null || o.call(e, I), I = []);
431
+ }, n.flushInterval));
432
+ }
433
+ function p() {
434
+ var o;
435
+ L && (clearInterval(L), L = null), I.length > 0 && ((o = e.onBatch) == null || o.call(e, I), I = []);
436
+ }
437
+ function D() {
438
+ y.value || (y.value = !0, F(), O());
439
+ }
440
+ function u() {
441
+ y.value = !1, E(), p();
442
+ }
443
+ function h(o) {
444
+ var c, M, C;
445
+ if (y.value)
446
+ try {
447
+ const P = n.transform(o);
448
+ if (n.filter && !n.filter(P))
449
+ return;
450
+ if (n.deduplicate) {
451
+ let x;
452
+ const $ = n.dedupeKey || n.deduplicateKey;
453
+ if (typeof $ == "function" ? x = $(P) : typeof $ == "string" && (x = String(P[$])), x !== void 0 && w.has(x))
454
+ return;
455
+ x !== void 0 && (w.add(x), w.size > n.bufferSize * 2 && Array.from(w).slice(0, n.bufferSize).forEach((W) => w.delete(W)));
456
+ }
457
+ d.value = P, T.value++, S++, a.value = [...a.value, P].slice(-n.bufferSize), a.value.length >= n.bufferSize && ((c = e.onBufferFull) == null || c.call(e)), n.flushInterval && n.flushInterval > 0 && I.push(P), (M = e.onData) == null || M.call(e, P), i.forEach((x) => x(P));
458
+ } catch (P) {
459
+ const x = P instanceof Error ? P : new Error(String(P));
460
+ f.value = x, (C = e.onError) == null || C.call(e, x);
461
+ }
462
+ }
463
+ function t() {
464
+ d.value = null, a.value = [], w.clear(), T.value = 0, I = [];
465
+ }
466
+ function s() {
467
+ return [...a.value];
468
+ }
469
+ function r(o) {
470
+ return i.add(o), () => {
471
+ i.delete(o);
472
+ };
473
+ }
474
+ return U(() => {
475
+ u(), i.clear(), t();
476
+ }), {
477
+ data: d,
478
+ buffer: a,
479
+ bufferSize: m,
480
+ isStreaming: y,
481
+ itemsPerSecond: A,
482
+ totalItems: T,
483
+ error: f,
484
+ start: D,
485
+ stop: u,
486
+ push: h,
487
+ clear: t,
488
+ getBuffer: s,
489
+ subscribe: r
490
+ };
491
+ }
492
+ const k = {
493
+ method: "GET",
494
+ headers: {},
495
+ credentials: "same-origin",
496
+ autoConnect: !0,
497
+ autoReconnect: !0,
498
+ maxReconnectAttempts: 5,
499
+ reconnectDelay: 1e3,
500
+ maxReconnectDelay: 3e4,
501
+ ndjson: !0
502
+ };
503
+ function de(N, e = {}) {
504
+ const n = { ...k, ...N }, d = v(!1), a = v(!1), m = v("disconnected"), y = v(null), A = v([]), T = v(0), f = v(null), i = v(0);
505
+ let w = null, S = !1;
506
+ const R = G({
507
+ maxAttempts: n.maxReconnectAttempts,
508
+ delay: n.reconnectDelay,
509
+ delayMax: n.maxReconnectDelay,
510
+ onAttempt: (p, D) => {
511
+ var u;
512
+ i.value = p, m.value = "reconnecting", (u = e.onReconnecting) == null || u.call(e, p, D);
513
+ },
514
+ onSuccess: () => {
515
+ var p;
516
+ i.value = 0, (p = e.onReconnected) == null || p.call(e);
517
+ },
518
+ onFailure: () => {
519
+ var p;
520
+ m.value = "failed", (p = e.onReconnectFailed) == null || p.call(e);
521
+ }
522
+ });
523
+ function L(p) {
524
+ const D = p.trim();
525
+ if (!D) return null;
526
+ try {
527
+ return JSON.parse(D);
528
+ } catch {
529
+ return D;
530
+ }
531
+ }
532
+ function I(p) {
533
+ var u, h;
534
+ if (!p) return;
535
+ let D;
536
+ if (n.parseChunk)
537
+ D = n.parseChunk(p);
538
+ else if (n.ndjson) {
539
+ const t = p.split(`
540
+ `);
541
+ for (const s of t) {
542
+ const r = L(s);
543
+ r !== null && (y.value = r, A.value.push(r), (u = e.onChunk) == null || u.call(e, r, s));
544
+ }
545
+ return;
546
+ } else
547
+ D = p;
548
+ D != null && (y.value = D, A.value.push(D), (h = e.onChunk) == null || h.call(e, D, p));
549
+ }
550
+ async function F() {
551
+ var p, D, u, h;
552
+ if (!a.value) {
553
+ S = !1, m.value = "connecting", f.value = null, w = new AbortController();
554
+ try {
555
+ const t = {
556
+ method: n.method,
557
+ headers: {
558
+ Accept: "text/event-stream, application/x-ndjson, application/json, text/plain",
559
+ ...n.headers
560
+ },
561
+ credentials: n.credentials,
562
+ signal: w.signal
563
+ };
564
+ n.body && ["POST", "PUT", "PATCH"].includes(n.method) && (t.body = typeof n.body == "string" ? n.body : JSON.stringify(n.body));
565
+ const s = await fetch(n.url, t);
566
+ if (!s.ok)
567
+ throw new Error(`HTTP ${s.status}: ${s.statusText}`);
568
+ if (!s.body)
569
+ throw new Error("Response body is not readable");
570
+ d.value = !0, a.value = !0, m.value = "connected", (p = e.onOpen) == null || p.call(e);
571
+ const r = s.body.getReader(), o = new TextDecoder();
572
+ let c = "";
573
+ for (; ; ) {
574
+ const { done: M, value: C } = await r.read();
575
+ if (M) {
576
+ c && I(c);
577
+ break;
578
+ }
579
+ const P = o.decode(C, { stream: !0 });
580
+ T.value += C.length, (D = e.onProgress) == null || D.call(e, T.value), c += P;
581
+ const x = c.lastIndexOf(`
582
+ `);
583
+ if (x !== -1) {
584
+ const $ = c.slice(0, x);
585
+ c = c.slice(x + 1), I($);
586
+ }
587
+ }
588
+ a.value = !1, m.value = "disconnected", (u = e.onComplete) == null || u.call(e);
589
+ } catch (t) {
590
+ if (t.name === "AbortError")
591
+ return;
592
+ f.value = t, d.value = !1, a.value = !1, m.value = "error", (h = e.onError) == null || h.call(e, t), !S && n.autoReconnect && R.scheduleReconnect(async () => {
593
+ try {
594
+ return await F(), !0;
595
+ } catch {
596
+ return !1;
597
+ }
598
+ });
599
+ }
600
+ }
601
+ }
602
+ function E() {
603
+ S = !0, R.cancel(), w && (w.abort(), w = null), d.value = !1, a.value = !1, m.value = "disconnected";
604
+ }
605
+ function O() {
606
+ A.value = [], y.value = null, T.value = 0;
607
+ }
608
+ return n.autoConnect && F(), U(() => {
609
+ E();
610
+ }), {
611
+ isConnected: d,
612
+ isStreaming: a,
613
+ connectionState: m,
614
+ lastChunk: y,
615
+ chunks: A,
616
+ bytesReceived: T,
617
+ error: f,
618
+ reconnectAttempts: i,
619
+ connect: F,
620
+ disconnect: E,
621
+ clearChunks: O
622
+ };
623
+ }
624
+ const ee = {
625
+ broadcaster: "pusher",
626
+ wsPort: 6001,
627
+ wssPort: 6001,
628
+ forceTLS: !1,
629
+ disableStats: !1,
630
+ cluster: "mt1",
631
+ authEndpoint: "/broadcasting/auth",
632
+ authHeaders: {},
633
+ auth: { headers: {} },
634
+ enabledTransports: ["ws", "wss"],
635
+ options: {}
636
+ };
637
+ function ve(N = {}, e = {}, n) {
638
+ const d = { ...ee, ...N }, a = v(!1), m = v("idle"), y = v(null), A = v([]), T = v(null);
639
+ let f = n || null;
640
+ const i = !!n;
641
+ async function w() {
642
+ if (f) return f;
643
+ try {
644
+ const [{ default: t }, { default: s }] = await Promise.all([
645
+ import("laravel-echo"),
646
+ import("pusher-js")
647
+ ]);
648
+ return window.Pusher = s, f = new t({
649
+ broadcaster: d.broadcaster || "pusher",
650
+ key: d.key,
651
+ wsHost: d.wsHost,
652
+ wsPort: d.wsPort,
653
+ wssPort: d.wssPort,
654
+ forceTLS: d.forceTLS,
655
+ cluster: d.cluster,
656
+ authEndpoint: d.authEndpoint,
657
+ auth: {
658
+ headers: d.authHeaders
659
+ },
660
+ enabledTransports: d.enabledTransports,
661
+ disableStats: !0,
662
+ ...d.options
663
+ }), f;
664
+ } catch {
665
+ throw new Error(
666
+ "laravel-echo and/or pusher-js not installed. Run: npm install laravel-echo pusher-js"
667
+ );
668
+ }
669
+ }
670
+ function S(t, s) {
671
+ var o;
672
+ A.value.find((c) => c.name === t) || (A.value = [
673
+ ...A.value,
674
+ { name: t, type: s, subscribedAt: /* @__PURE__ */ new Date() }
675
+ ], (o = e.onSubscribed) == null || o.call(e, t));
676
+ }
677
+ function R(t) {
678
+ A.value = A.value.filter((s) => s.name !== t);
679
+ }
680
+ async function L() {
681
+ var t;
682
+ m.value = "connecting", T.value = null;
683
+ try {
684
+ const s = await w(), r = s.connector, o = (r == null ? void 0 : r.pusher) ?? (r == null ? void 0 : r.socket) ?? s.client;
685
+ if (!o || !o.connection) {
686
+ a.value = !0, m.value = "connected", (t = e.onConnected) == null || t.call(e, "");
687
+ return;
688
+ }
689
+ return new Promise((c, M) => {
690
+ var j;
691
+ let C = !1;
692
+ const x = setTimeout(() => {
693
+ var W;
694
+ C || (C = !0, o.connection.state === "connected" && (a.value = !0, m.value = "connected", y.value = o.connection.socket_id || null, (W = e.onConnected) == null || W.call(e, y.value || "")), c());
695
+ }, 15e3);
696
+ o.connection.bind(
697
+ "state_change",
698
+ (W) => {
699
+ var B, l, g;
700
+ if (W.current === "connected")
701
+ a.value = !0, m.value = "connected", y.value = o.connection.socket_id || null, (B = e.onConnected) == null || B.call(e, y.value || ""), C || (C = !0, clearTimeout(x), c());
702
+ else if (W.current === "disconnected" || W.current === "unavailable")
703
+ a.value = !1, m.value = "disconnected", y.value = null, (l = e.onDisconnected) == null || l.call(e), C || (C = !0, clearTimeout(x), c());
704
+ else if (W.current === "failed") {
705
+ a.value = !1, m.value = "error";
706
+ const _ = new Error("Pusher connection failed");
707
+ T.value = _, (g = e.onError) == null || g.call(e, _), C || (C = !0, clearTimeout(x), c());
708
+ }
709
+ }
710
+ ), o.connection.bind("error", (W) => {
711
+ var l, g;
712
+ const B = W instanceof Error ? W : new Error(
713
+ typeof W == "object" && W !== null ? ((l = W.message) == null ? void 0 : l.toString()) || JSON.stringify(W) : String(W)
714
+ );
715
+ T.value = B, m.value = "error", (g = e.onError) == null || g.call(e, B);
716
+ }), o.connection.state === "connected" && (a.value = !0, m.value = "connected", y.value = o.connection.socket_id || null, (j = e.onConnected) == null || j.call(e, y.value || ""), C || (C = !0, clearTimeout(x), c()));
717
+ });
718
+ } catch (s) {
719
+ const r = s instanceof Error ? s : new Error(String(s));
720
+ throw T.value = r, m.value = "error", r;
721
+ }
722
+ }
723
+ function I() {
724
+ f && !i && (f.disconnect(), f = null), a.value = !1, m.value = "closed", y.value = null, A.value = [];
725
+ }
726
+ function F(t, s) {
727
+ return {
728
+ listen(r, o) {
729
+ return t.listen(r, o), this;
730
+ },
731
+ stopListening(r, o) {
732
+ return t.stopListening(r, o), this;
733
+ },
734
+ listenForWhisper(r, o) {
735
+ return t.listenForWhisper(r, o), this;
736
+ },
737
+ whisper(r, o) {
738
+ return t.whisper(r, o), this;
739
+ }
740
+ };
741
+ }
742
+ function E(t, s) {
743
+ return {
744
+ ...F(t),
745
+ here(o) {
746
+ return t.here(o), this;
747
+ },
748
+ joining(o) {
749
+ return t.joining((c) => {
750
+ var M;
751
+ (M = e.onMemberJoined) == null || M.call(e, s, c), o(c);
752
+ }), this;
753
+ },
754
+ leaving(o) {
755
+ return t.leaving((c) => {
756
+ var M;
757
+ (M = e.onMemberLeft) == null || M.call(e, s, c), o(c);
758
+ }), this;
759
+ }
760
+ };
761
+ }
762
+ function O(t) {
763
+ if (!f)
764
+ throw new Error("Echo not connected. Call connect() first.");
765
+ const s = f.channel(t);
766
+ return S(t, "public"), F(s);
767
+ }
768
+ function p(t) {
769
+ if (!f)
770
+ throw new Error("Echo not connected. Call connect() first.");
771
+ const s = f.private(t);
772
+ return S(`private-${t}`, "private"), F(s);
773
+ }
774
+ function D(t) {
775
+ if (!f)
776
+ throw new Error("Echo not connected. Call connect() first.");
777
+ const s = f.join(t);
778
+ return S(`presence-${t}`, "presence"), E(s, t);
779
+ }
780
+ function u(t) {
781
+ f && (f.leaveChannel(t), R(t), R(`private-${t}`), R(`presence-${t}`));
782
+ }
783
+ function h() {
784
+ [...A.value.map((s) => s.name)].forEach((s) => u(s));
785
+ }
786
+ return U(() => {
787
+ I();
788
+ }), {
789
+ isConnected: a,
790
+ connectionState: m,
791
+ socketId: y,
792
+ channels: A,
793
+ error: T,
794
+ connect: L,
795
+ disconnect: I,
796
+ channel: O,
797
+ privateChannel: p,
798
+ presenceChannel: D,
799
+ leave: u,
800
+ leaveAll: h
801
+ };
802
+ }
803
+ const ne = {
804
+ method: "GET",
805
+ headers: {},
806
+ credentials: "same-origin",
807
+ interval: 0,
808
+ timeout: 3e4,
809
+ autoStart: !0,
810
+ autoRestart: !0,
811
+ maxRestartAttempts: 5,
812
+ restartDelay: 1e3,
813
+ maxRestartDelay: 3e4,
814
+ includeTimestamp: !1,
815
+ timestampParam: "since"
816
+ };
817
+ function pe(N, e = {}) {
818
+ const n = { ...ne, ...N }, d = v(!1), a = v("disconnected"), m = v(null), y = v([]), A = v(0), T = v(null), f = v(0);
819
+ let i = null, w = null, S = !1, R = null;
820
+ const L = G({
821
+ maxAttempts: n.maxRestartAttempts,
822
+ delay: n.restartDelay,
823
+ delayMax: n.maxRestartDelay,
824
+ onAttempt: (t, s) => {
825
+ var r;
826
+ f.value = t, a.value = "reconnecting", (r = e.onRestarting) == null || r.call(e, t, s);
827
+ },
828
+ onSuccess: () => {
829
+ var t;
830
+ f.value = 0, (t = e.onRestarted) == null || t.call(e);
831
+ },
832
+ onFailure: () => {
833
+ var t;
834
+ a.value = "failed", (t = e.onRestartFailed) == null || t.call(e);
835
+ }
836
+ });
837
+ function I() {
838
+ if (!n.includeTimestamp || !R)
839
+ return n.url;
840
+ const t = new URL(n.url);
841
+ return t.searchParams.set(n.timestampParam, R.toString()), t.toString();
842
+ }
843
+ async function F() {
844
+ i = new AbortController();
845
+ const t = setTimeout(() => {
846
+ i == null || i.abort();
847
+ }, n.timeout);
848
+ try {
849
+ const s = {
850
+ method: n.method,
851
+ headers: {
852
+ Accept: "application/json",
853
+ ...n.headers
854
+ },
855
+ credentials: n.credentials,
856
+ signal: i.signal
857
+ };
858
+ n.body && n.method === "POST" && (s.body = typeof n.body == "string" ? n.body : JSON.stringify(n.body), s.headers = {
859
+ ...s.headers,
860
+ "Content-Type": "application/json"
861
+ });
862
+ const r = await fetch(I(), s);
863
+ if (clearTimeout(t), !r.ok)
864
+ throw new Error(`HTTP ${r.status}: ${r.statusText}`);
865
+ return await r.json();
866
+ } catch (s) {
867
+ throw clearTimeout(t), s;
868
+ }
869
+ }
870
+ async function E() {
871
+ var t, s;
872
+ for (; d.value && !S; )
873
+ try {
874
+ A.value++;
875
+ const r = await F();
876
+ R = Date.now(), m.value = r, y.value.push(r), T.value = null, (t = e.onData) == null || t.call(e, r), n.interval > 0 && d.value && !S && await new Promise((o) => {
877
+ w = setTimeout(o, n.interval);
878
+ });
879
+ } catch (r) {
880
+ if (r.name === "AbortError") {
881
+ if (S)
882
+ break;
883
+ continue;
884
+ }
885
+ if (T.value = r, (s = e.onError) == null || s.call(e, r), !S && n.autoRestart) {
886
+ d.value = !1, a.value = "error", L.scheduleReconnect(async () => {
887
+ try {
888
+ return await O(), !0;
889
+ } catch {
890
+ return !1;
891
+ }
892
+ });
893
+ return;
894
+ }
895
+ break;
896
+ }
897
+ S || (d.value = !1, a.value = "disconnected");
898
+ }
899
+ async function O() {
900
+ var t;
901
+ d.value || (S = !1, d.value = !0, a.value = "connected", T.value = null, (t = e.onStart) == null || t.call(e), E());
902
+ }
903
+ function p() {
904
+ O();
905
+ }
906
+ function D() {
907
+ var t;
908
+ S = !0, L.cancel(), w && (clearTimeout(w), w = null), i && (i.abort(), i = null), d.value = !1, a.value = "disconnected", (t = e.onStop) == null || t.call(e);
909
+ }
910
+ async function u() {
911
+ var s, r;
912
+ const t = d.value;
913
+ w && (clearTimeout(w), w = null);
914
+ try {
915
+ const o = await F();
916
+ R = Date.now(), m.value = o, y.value.push(o), (s = e.onData) == null || s.call(e, o);
917
+ } catch (o) {
918
+ o.name !== "AbortError" && (T.value = o, (r = e.onError) == null || r.call(e, o));
919
+ }
920
+ t && !S && E();
921
+ }
922
+ function h() {
923
+ y.value = [], m.value = null, A.value = 0;
924
+ }
925
+ return n.autoStart && p(), U(() => {
926
+ D();
927
+ }), {
928
+ isPolling: d,
929
+ connectionState: a,
930
+ lastData: m,
931
+ dataHistory: y,
932
+ requestCount: A,
933
+ error: T,
934
+ restartAttempts: f,
935
+ start: p,
936
+ stop: D,
937
+ poll: u,
938
+ clearHistory: h
939
+ };
940
+ }
941
+ const te = {
942
+ path: "/socket.io",
943
+ namespace: "/",
944
+ reconnection: !0,
945
+ reconnectionAttempts: 5,
946
+ reconnectionDelay: 1e3,
947
+ transports: ["websocket", "polling"],
948
+ extraHeaders: {},
949
+ options: {},
950
+ autoConnect: !0,
951
+ autoReconnect: !0,
952
+ maxReconnectAttempts: 5,
953
+ reconnectDelay: 1e3
954
+ };
955
+ function he(N, e = {}) {
956
+ const n = { ...te, ...N }, d = v(!1), a = v("idle"), m = v(null), y = v([]), A = v(0), T = v(null);
957
+ let f = null, i = null;
958
+ async function w() {
959
+ if (i) return i;
960
+ try {
961
+ const u = await import("socket.io-client");
962
+ return i = u.io || u.default, i;
963
+ } catch {
964
+ throw new Error(
965
+ "socket.io-client is not installed. Run: npm install socket.io-client"
966
+ );
967
+ }
968
+ }
969
+ async function S() {
970
+ if (!(f != null && f.connected)) {
971
+ a.value = "connecting", T.value = null;
972
+ try {
973
+ const u = await w();
974
+ if (!u)
975
+ throw new Error("Socket.IO client not available");
976
+ const h = n.namespace === "/" ? n.url : `${n.url}${n.namespace}`;
977
+ f = u(h, {
978
+ path: n.path,
979
+ auth: n.auth,
980
+ reconnection: n.reconnection,
981
+ reconnectionAttempts: n.reconnectionAttempts,
982
+ reconnectionDelay: n.reconnectionDelay,
983
+ transports: n.transports,
984
+ extraHeaders: n.extraHeaders
985
+ }), await new Promise((t, s) => {
986
+ f.on("connect", () => {
987
+ var r;
988
+ d.value = !0, a.value = "connected", m.value = (f == null ? void 0 : f.id) || null, A.value = 0, (r = e.onConnect) == null || r.call(e, m.value || ""), t();
989
+ }), f.on("disconnect", (r) => {
990
+ var o;
991
+ d.value = !1, a.value = "disconnected", m.value = null, (o = e.onDisconnect) == null || o.call(e, r);
992
+ }), f.on("connect_error", (r) => {
993
+ var o;
994
+ T.value = r, a.value = "error", (o = e.onError) == null || o.call(e, r), s(r);
995
+ }), f.io.on("reconnect_attempt", (r) => {
996
+ var o;
997
+ A.value = r, a.value = "reconnecting", (o = e.onReconnecting) == null || o.call(e, r);
998
+ }), f.io.on("reconnect_failed", () => {
999
+ var r;
1000
+ a.value = "error", (r = e.onReconnectFailed) == null || r.call(e);
1001
+ }), f.connect();
1002
+ });
1003
+ } catch (u) {
1004
+ const h = u instanceof Error ? u : new Error(String(u));
1005
+ throw T.value = h, a.value = "error", h;
1006
+ }
1007
+ }
1008
+ }
1009
+ function R() {
1010
+ f && (f.disconnect(), f = null), d.value = !1, a.value = "closed", m.value = null, y.value = [];
1011
+ }
1012
+ function L(u, h) {
1013
+ if (!(f != null && f.connected)) {
1014
+ console.warn("[useSocketIO] Cannot emit: Socket is not connected");
1015
+ return;
1016
+ }
1017
+ f.emit(u, h);
1018
+ }
1019
+ function I(u, h, t = 5e3) {
1020
+ return new Promise((s, r) => {
1021
+ if (!(f != null && f.connected)) {
1022
+ r(new Error("Socket is not connected"));
1023
+ return;
1024
+ }
1025
+ const o = setTimeout(() => {
1026
+ r(new Error(`Emit timeout for event: ${u}`));
1027
+ }, t);
1028
+ f.emit(u, h, (c) => {
1029
+ clearTimeout(o), s(c);
1030
+ });
1031
+ });
1032
+ }
1033
+ function F(u, h) {
1034
+ if (!f) {
1035
+ console.warn("[useSocketIO] Cannot listen: Socket not initialized");
1036
+ return;
1037
+ }
1038
+ f.on(u, h);
1039
+ }
1040
+ function E(u, h) {
1041
+ f && f.off(u, h);
1042
+ }
1043
+ async function O(u) {
1044
+ if (!(f != null && f.connected))
1045
+ throw new Error("Socket is not connected");
1046
+ return new Promise((h, t) => {
1047
+ let s = !1;
1048
+ f.emit("join", u, (r) => {
1049
+ if (!s)
1050
+ if (s = !0, r != null && r.error)
1051
+ t(new Error(r.error));
1052
+ else {
1053
+ const o = {
1054
+ name: u,
1055
+ joinedAt: /* @__PURE__ */ new Date()
1056
+ };
1057
+ y.value = [...y.value, o], h();
1058
+ }
1059
+ }), setTimeout(() => {
1060
+ if (s) return;
1061
+ s = !0;
1062
+ const r = {
1063
+ name: u,
1064
+ joinedAt: /* @__PURE__ */ new Date()
1065
+ };
1066
+ y.value = [...y.value, r], h();
1067
+ }, 1e3);
1068
+ });
1069
+ }
1070
+ async function p(u) {
1071
+ if (f != null && f.connected)
1072
+ return new Promise((h) => {
1073
+ let t = !1;
1074
+ f.emit("leave", u, () => {
1075
+ t || (t = !0, y.value = y.value.filter((s) => s.name !== u), h());
1076
+ }), setTimeout(() => {
1077
+ t || (t = !0, y.value = y.value.filter((s) => s.name !== u), h());
1078
+ }, 1e3);
1079
+ });
1080
+ }
1081
+ function D() {
1082
+ return f;
1083
+ }
1084
+ return U(() => {
1085
+ R();
1086
+ }), {
1087
+ isConnected: d,
1088
+ connectionState: a,
1089
+ socketId: m,
1090
+ rooms: y,
1091
+ reconnectAttempts: A,
1092
+ error: T,
1093
+ connect: S,
1094
+ disconnect: R,
1095
+ emit: L,
1096
+ emitWithAck: I,
1097
+ on: F,
1098
+ off: E,
1099
+ join: O,
1100
+ leave: p,
1101
+ getSocket: D
1102
+ };
1103
+ }
1104
+ const oe = {
1105
+ withCredentials: !1,
1106
+ autoConnect: !0,
1107
+ autoReconnect: !0,
1108
+ maxReconnectAttempts: 5,
1109
+ reconnectDelay: 1e3,
1110
+ maxReconnectDelay: 3e4,
1111
+ eventTypes: ["message"]
1112
+ };
1113
+ function me(N, e = {}) {
1114
+ const n = { ...oe, ...N }, d = v(!1), a = v("disconnected"), m = v(null), y = v(""), A = v(null), T = v(null), f = v(0);
1115
+ let i = null, w = !1;
1116
+ const S = /* @__PURE__ */ new Map(), R = G({
1117
+ maxAttempts: n.maxReconnectAttempts,
1118
+ delay: n.reconnectDelay,
1119
+ delayMax: n.maxReconnectDelay,
1120
+ onAttempt: (u, h) => {
1121
+ var t;
1122
+ f.value = u, a.value = "reconnecting", (t = e.onReconnecting) == null || t.call(e, u, h);
1123
+ },
1124
+ onSuccess: () => {
1125
+ var u;
1126
+ f.value = 0, (u = e.onReconnected) == null || u.call(e);
1127
+ },
1128
+ onFailure: () => {
1129
+ var u;
1130
+ a.value = "failed", (u = e.onReconnectFailed) == null || u.call(e);
1131
+ }
1132
+ });
1133
+ function L(u) {
1134
+ var h, t;
1135
+ try {
1136
+ let s;
1137
+ try {
1138
+ s = JSON.parse(u.data);
1139
+ } catch {
1140
+ s = u.data;
1141
+ }
1142
+ m.value = s, y.value = u.type || "message", A.value = u.lastEventId || null, (h = e.onMessage) == null || h.call(e, s, u), (t = e.onEvent) == null || t.call(e, u.type || "message", s, u);
1143
+ const r = S.get(u.type || "message");
1144
+ r && r.forEach((o) => o(s));
1145
+ } catch (s) {
1146
+ console.error("[useSSE] Error processing message:", s);
1147
+ }
1148
+ }
1149
+ function I() {
1150
+ var u;
1151
+ d.value = !0, a.value = "connected", T.value = null, R.reset(), (u = e.onOpen) == null || u.call(e);
1152
+ }
1153
+ function F(u) {
1154
+ var h;
1155
+ T.value = u, (h = e.onError) == null || h.call(e, u), (i == null ? void 0 : i.readyState) === EventSource.CLOSED && (d.value = !1, a.value = "error", !w && n.autoReconnect && R.scheduleReconnect(async () => {
1156
+ try {
1157
+ return E(), !0;
1158
+ } catch {
1159
+ return !1;
1160
+ }
1161
+ }));
1162
+ }
1163
+ function E() {
1164
+ var u;
1165
+ if (!(i && i.readyState !== EventSource.CLOSED)) {
1166
+ w = !1, a.value = "connecting";
1167
+ try {
1168
+ i = new EventSource(n.url, {
1169
+ withCredentials: n.withCredentials
1170
+ }), i.onmessage = L, i.onopen = I, i.onerror = F, n.eventTypes.forEach((h) => {
1171
+ h !== "message" && i && i.addEventListener(
1172
+ h,
1173
+ L
1174
+ );
1175
+ });
1176
+ } catch (h) {
1177
+ a.value = "error", T.value = h, (u = e.onError) == null || u.call(e, h);
1178
+ }
1179
+ }
1180
+ }
1181
+ function O() {
1182
+ w = !0, R.cancel(), i && (i.close(), i = null), d.value = !1, a.value = "disconnected";
1183
+ }
1184
+ function p(u, h) {
1185
+ S.has(u) || (S.set(u, /* @__PURE__ */ new Set()), i && u !== "message" && i.addEventListener(u, L)), S.get(u).add(h);
1186
+ }
1187
+ function D(u, h) {
1188
+ const t = S.get(u);
1189
+ t && (t.delete(h), t.size === 0 && S.delete(u));
1190
+ }
1191
+ return n.autoConnect && E(), U(() => {
1192
+ O(), S.clear();
1193
+ }), {
1194
+ isConnected: d,
1195
+ connectionState: a,
1196
+ lastMessage: m,
1197
+ lastEventType: y,
1198
+ lastEventId: A,
1199
+ error: T,
1200
+ reconnectAttempts: f,
1201
+ connect: E,
1202
+ disconnect: O,
1203
+ addEventListener: p,
1204
+ removeEventListener: D
1205
+ };
1206
+ }
1207
+ const re = {
1208
+ autoConnect: !0,
1209
+ autoReconnect: !0,
1210
+ maxReconnectAttempts: 5,
1211
+ reconnectDelay: 1e3,
1212
+ maxReconnectDelay: 3e4,
1213
+ heartbeatInterval: 0,
1214
+ heartbeatMessage: "",
1215
+ binaryType: "arraybuffer"
1216
+ };
1217
+ function le(N, e = {}) {
1218
+ const n = { ...re, ...N }, d = v(!1), a = v("idle"), m = v(WebSocket.CLOSED), y = v(0), A = v(null), T = v(null), f = v(0);
1219
+ let i = null, w = null, S = !1;
1220
+ const R = G({
1221
+ maxAttempts: n.maxReconnectAttempts,
1222
+ delay: n.reconnectDelay,
1223
+ delayMax: n.maxReconnectDelay,
1224
+ onAttempt: (u, h) => {
1225
+ var t;
1226
+ f.value = u, a.value = "reconnecting", (t = e.onReconnecting) == null || t.call(e, u, h);
1227
+ },
1228
+ onSuccess: () => {
1229
+ var u;
1230
+ f.value = 0, (u = e.onReconnected) == null || u.call(e);
1231
+ },
1232
+ onFailure: () => {
1233
+ var u;
1234
+ a.value = "error", (u = e.onReconnectFailed) == null || u.call(e);
1235
+ }
1236
+ });
1237
+ function L() {
1238
+ !n.heartbeatInterval || n.heartbeatInterval <= 0 || (w = setInterval(() => {
1239
+ if (i && i.readyState === WebSocket.OPEN) {
1240
+ const u = typeof n.heartbeatMessage == "function" ? n.heartbeatMessage() : n.heartbeatMessage || JSON.stringify({ type: "ping", timestamp: Date.now() });
1241
+ i.send(u);
1242
+ }
1243
+ }, n.heartbeatInterval));
1244
+ }
1245
+ function I() {
1246
+ w && (clearInterval(w), w = null);
1247
+ }
1248
+ function F() {
1249
+ i && (y.value = i.bufferedAmount);
1250
+ }
1251
+ async function E() {
1252
+ if (!(i && i.readyState === WebSocket.OPEN))
1253
+ return S = !1, a.value = "connecting", T.value = null, new Promise((u, h) => {
1254
+ try {
1255
+ i = new WebSocket(n.url, n.protocols), i.binaryType = n.binaryType, i.onopen = () => {
1256
+ var t;
1257
+ d.value = !0, a.value = "connected", m.value = WebSocket.OPEN, R.reset(), f.value = 0, L(), (t = e.onOpen) == null || t.call(e), u();
1258
+ }, i.onclose = (t) => {
1259
+ var s;
1260
+ d.value = !1, a.value = "disconnected", m.value = WebSocket.CLOSED, I(), (s = e.onClose) == null || s.call(e, t.code, t.reason), !S && n.autoReconnect && R.scheduleReconnect(async () => {
1261
+ try {
1262
+ return await E(), !0;
1263
+ } catch {
1264
+ return !1;
1265
+ }
1266
+ });
1267
+ }, i.onerror = (t) => {
1268
+ var s;
1269
+ T.value = t, a.value = "error", (s = e.onError) == null || s.call(e, t), h(t);
1270
+ }, i.onmessage = (t) => {
1271
+ var r;
1272
+ A.value = t.data, F();
1273
+ let s = t.data;
1274
+ if (typeof t.data == "string")
1275
+ try {
1276
+ s = JSON.parse(t.data);
1277
+ } catch {
1278
+ }
1279
+ (r = e.onMessage) == null || r.call(e, s, t);
1280
+ }, m.value = i.readyState;
1281
+ } catch (t) {
1282
+ a.value = "error", h(t);
1283
+ }
1284
+ });
1285
+ }
1286
+ function O() {
1287
+ S = !0, R.cancel(), I(), i && (i.close(1e3, "Client disconnect"), i = null), d.value = !1, a.value = "closed", m.value = WebSocket.CLOSED;
1288
+ }
1289
+ function p(u) {
1290
+ if (!i || i.readyState !== WebSocket.OPEN)
1291
+ return console.warn("[useWebSocket] Cannot send: WebSocket is not connected"), !1;
1292
+ try {
1293
+ return i.send(u), F(), !0;
1294
+ } catch (h) {
1295
+ return console.error("[useWebSocket] Send error:", h), !1;
1296
+ }
1297
+ }
1298
+ function D(u) {
1299
+ return p(JSON.stringify(u));
1300
+ }
1301
+ return U(() => {
1302
+ O();
1303
+ }), {
1304
+ isConnected: d,
1305
+ connectionState: a,
1306
+ readyState: m,
1307
+ bufferedAmount: y,
1308
+ lastMessage: A,
1309
+ error: T,
1310
+ reconnectAttempts: f,
1311
+ connect: E,
1312
+ disconnect: O,
1313
+ send: p,
1314
+ sendJSON: D
1315
+ };
1316
+ }
1317
+ export {
1318
+ se as a,
1319
+ de as b,
1320
+ ve as c,
1321
+ pe as d,
1322
+ me as e,
1323
+ he as f,
1324
+ fe as g,
1325
+ le as h,
1326
+ ae as u
1327
+ };
1328
+ //# sourceMappingURL=useWebSocket-C3JPFBmy.js.map