@sendity/client 0.1.0

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.
@@ -0,0 +1,4459 @@
1
+ const pt = `<template id="sendity-tpl">
2
+ <div class="sendity flex items-center">
3
+ <slot id="prompt">
4
+ <div class="prompt" aria-live="polite" aria-atomic="true" hidden></div>
5
+ </slot>
6
+
7
+ <div class="code" aria-live="polite" aria-atomic="true">
8
+ <span class="spinner" aria-hidden="true"></span>
9
+ <span class="formatted-code" data-placeholder="••••" hidden>&nbsp;</span>
10
+ </div>
11
+
12
+ <div class="success" aria-live="polite" aria-atomic="true" hidden></div>
13
+
14
+ <div class="verifiers">
15
+ <!-- Links will be inserted here -->
16
+ </div>
17
+
18
+ <footer class="sendity-footer" aria-live="polite" aria-atomic="true">
19
+ <span class="footer-brand">Secure passwordless authentication by <span class="footer-logo">sendity.io</span></span>
20
+ <span class="footer-status" hidden>
21
+ <span class="footer-spinner" aria-hidden="true"></span>
22
+ <span class="footer-message"></span>
23
+ </span>
24
+ </footer>
25
+ </div>
26
+ </template>
27
+ `, Ni = `:host {
28
+ /* Theme variables (override these on the host page or on the Sendity Client host element) */
29
+ --sendity-color: #111827; /* text-gray-900 */
30
+ --sendity-primary-color: #14b8a6; /* teal-500 */
31
+ --sendity-success-color: #14b8a6; /* teal-500 */
32
+ --sendity-error-color: #b91c1c; /* red-700 */
33
+
34
+ --sendity-font-size: 1rem; /* text-base */
35
+ --sendity-font-size-sm: 0.875rem; /* text-sm */
36
+ --sendity-font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
37
+
38
+ --sendity-code-font-size: 1.5rem; /* text-lg */
39
+ --sendity-code-font-weight: 600;
40
+ --sendity-code-font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
41
+ --sendity-code-bg: #f3f4f6; /* gray-100 */
42
+ --sendity-code-padding: 0.5rem 0.75rem; /* px-3 py-2 */
43
+ --sendity-code-color: var(--sendity-color);
44
+ --sendity-code-border-size: 0px;
45
+ --sendity-code-border-color: transparent;
46
+ --sendity-code-border-radius: 0.375rem; /* rounded-md */
47
+ --sendity-code-validity-duration: 600s;
48
+
49
+ --sendity-btn-font-size: var(--sendity-font-size);
50
+ --sendity-btn-border-size: 0px;
51
+ --sendity-btn-border-color: transparent;
52
+ --sendity-btn-border-radius: 0.375rem;
53
+ --sendity-btn-padding: 0.5rem 0.75rem;
54
+ --sendity-btn-bg: var(--sendity-primary-color);
55
+ --sendity-btn-color: #fff;
56
+ --sendity-success-check-bg: var(--sendity-success-color);
57
+ --sendity-success-check-color: #ffffff;
58
+ }
59
+
60
+ .sendity {
61
+ display: inline-flex;
62
+ flex-direction: column;
63
+ align-items: center;
64
+ justify-content: center;
65
+ gap: 0.5rem;
66
+ font-family: var(--sendity-font-family);
67
+ font-size: var(--sendity-font-size);
68
+ color: var(--sendity-color);
69
+ text-align: center;
70
+ }
71
+
72
+ .sendity .branding {
73
+ font-weight: 600;
74
+ }
75
+
76
+ .sendity .code {
77
+ position: relative;
78
+ font-variant-numeric: tabular-nums; /* keep digits aligned */
79
+ font-feature-settings: "tnum";
80
+ padding: var(--sendity-code-padding);
81
+ border-radius: var(--sendity-code-border-radius);
82
+ background: var(--sendity-code-bg);
83
+ color: var(--sendity-code-color);
84
+ border: var(--sendity-code-border-size) solid var(--sendity-code-border-color);
85
+ min-height: 2rem;
86
+ max-height: 4rem;
87
+ display: inline-grid;
88
+ place-items: center;
89
+ text-align: center;
90
+ gap: 0.5rem;
91
+ overflow: hidden;
92
+ transition: opacity 160ms ease, transform 160ms ease, max-height 180ms ease, min-height 180ms ease, padding 180ms ease, margin 180ms ease;
93
+ }
94
+
95
+ .sendity .code--active::after {
96
+ content: '';
97
+ position: absolute;
98
+ left: 0;
99
+ right: 0;
100
+ bottom: 0;
101
+ height: 3px;
102
+ border-radius: 0 0 var(--sendity-code-border-radius) var(--sendity-code-border-radius);
103
+ background: var(--sendity-primary-color);
104
+ transform-origin: left center;
105
+ animation: sendity-code-validity var(--sendity-code-validity-duration) linear forwards;
106
+ }
107
+
108
+ .sendity .code--verified {
109
+ opacity: 0;
110
+ transform: translateY(-0.125rem) scale(0.98);
111
+ max-height: 0;
112
+ min-height: 0;
113
+ padding-top: 0;
114
+ padding-bottom: 0;
115
+ margin: 0;
116
+ pointer-events: none;
117
+ }
118
+
119
+ .sendity .spinner {
120
+ width: 1rem;
121
+ height: 1rem;
122
+ border: 2px solid rgba(0, 0, 0, 0.15);
123
+ border-top-color: var(--sendity-primary-color);
124
+ border-radius: 50%;
125
+ animation: sendity-spin 0.8s linear infinite;
126
+ }
127
+
128
+ @keyframes sendity-spin {
129
+ to {
130
+ transform: rotate(360deg);
131
+ }
132
+ }
133
+
134
+ .sendity .formatted-code {
135
+ letter-spacing: 0.05em;
136
+ line-height: 1;
137
+ font-size: var(--sendity-code-font-size);
138
+ font-weight: var(--sendity-code-font-weight);
139
+ font-family: var(--sendity-code-font-family);
140
+ }
141
+
142
+ .sendity .prompt {
143
+ color: #374151; /* gray-700 */
144
+ }
145
+
146
+ .sendity .success {
147
+ display: inline-flex;
148
+ flex-direction: column;
149
+ align-items: center;
150
+ justify-content: center;
151
+ gap: 0.5rem;
152
+ color: var(--sendity-success-color);
153
+ font-weight: 700;
154
+ text-align: center;
155
+ }
156
+
157
+ .sendity .success[hidden] {
158
+ display: none !important;
159
+ }
160
+
161
+ .sendity .success-check {
162
+ display: inline-grid;
163
+ place-items: center;
164
+ width: 2.75rem;
165
+ height: 2.75rem;
166
+ border-radius: 999px;
167
+ background: var(--sendity-success-check-bg);
168
+ color: var(--sendity-success-check-color);
169
+ box-shadow: 0 10px 30px rgba(20, 184, 166, 0.28);
170
+ animation: sendity-success-bounce 260ms cubic-bezier(0.17, 1.2, 0.28, 1) both;
171
+ }
172
+
173
+ .sendity .success-check svg {
174
+ width: 1.55rem;
175
+ height: 1.55rem;
176
+ stroke: currentColor;
177
+ stroke-width: 3;
178
+ fill: none;
179
+ stroke-linecap: round;
180
+ stroke-linejoin: round;
181
+ }
182
+
183
+ .sendity .success-message {
184
+ color: var(--sendity-color);
185
+ }
186
+
187
+ @keyframes sendity-success-bounce {
188
+ 0% {
189
+ opacity: 0;
190
+ transform: scale(0.72);
191
+ }
192
+ 70% {
193
+ opacity: 1;
194
+ transform: scale(1.08);
195
+ }
196
+ 100% {
197
+ opacity: 1;
198
+ transform: scale(1);
199
+ }
200
+ }
201
+
202
+ @keyframes sendity-code-validity {
203
+ from {
204
+ transform: scaleX(1);
205
+ }
206
+ to {
207
+ transform: scaleX(0);
208
+ }
209
+ }
210
+
211
+ .sendity .verifiers {
212
+ display: flex;
213
+ align-self: center;
214
+ flex-wrap: wrap;
215
+ gap: 0.5rem;
216
+ }
217
+
218
+ .sendity .verifiers a {
219
+ display: inline-flex;
220
+ align-items: center;
221
+ gap: 0.375rem; /* ~6px */
222
+ text-decoration: none;
223
+ color: var(--sendity-btn-color);
224
+ background: var(--sendity-btn-bg);
225
+ padding: var(--sendity-btn-padding);
226
+ border-radius: var(--sendity-btn-border-radius);
227
+ border: var(--sendity-btn-border-size) solid var(--sendity-btn-border-color);
228
+ font-size: var(--sendity-btn-font-size);
229
+ }
230
+
231
+ .sendity .verifiers a .icon {
232
+ width: 1em;
233
+ height: 1em;
234
+ display: inline-flex;
235
+ }
236
+
237
+ .sendity .verifiers a .icon svg {
238
+ width: 1em;
239
+ height: 1em;
240
+ display: block;
241
+ }
242
+
243
+ .sendity .verifiers a:hover {
244
+ text-decoration: none;
245
+ }
246
+
247
+ .sendity .sendity-footer {
248
+ display: inline-flex;
249
+ align-items: center;
250
+ justify-content: center;
251
+ min-height: 1.125rem;
252
+ color: rgba(17, 24, 39, 0.55);
253
+ font-size: 0.6875rem;
254
+ line-height: 1rem;
255
+ letter-spacing: 0.01em;
256
+ text-align: center;
257
+ user-select: none;
258
+ }
259
+
260
+ .sendity .sendity-footer[hidden],
261
+ .sendity .sendity-footer [hidden] {
262
+ display: none !important;
263
+ }
264
+
265
+ .sendity .footer-logo {
266
+ font-weight: 700;
267
+ color: rgba(17, 24, 39, 0.72);
268
+ }
269
+
270
+ .sendity .footer-status {
271
+ display: inline-flex;
272
+ align-items: center;
273
+ justify-content: center;
274
+ gap: 0.375rem;
275
+ }
276
+
277
+ .sendity .footer-spinner {
278
+ width: 0.75rem;
279
+ height: 0.75rem;
280
+ border: 1.5px solid rgba(17, 24, 39, 0.16);
281
+ border-top-color: var(--sendity-primary-color);
282
+ border-radius: 50%;
283
+ animation: sendity-spin 0.8s linear infinite;
284
+ }
285
+ `;
286
+ class Oe {
287
+ constructor() {
288
+ this.notificationCreatedEvent = ".Illuminate\\Notifications\\Events\\BroadcastNotificationCreated";
289
+ }
290
+ /**
291
+ * Listen for a whisper event on the channel instance.
292
+ */
293
+ listenForWhisper(i, o) {
294
+ return this.listen(".client-" + i, o);
295
+ }
296
+ /**
297
+ * Listen for an event on the channel instance.
298
+ */
299
+ notification(i) {
300
+ return this.listen(this.notificationCreatedEvent, i);
301
+ }
302
+ /**
303
+ * Stop listening for notification events on the channel instance.
304
+ */
305
+ stopListeningForNotification(i) {
306
+ return this.stopListening(this.notificationCreatedEvent, i);
307
+ }
308
+ /**
309
+ * Stop listening for a whisper event on the channel instance.
310
+ */
311
+ stopListeningForWhisper(i, o) {
312
+ return this.stopListening(".client-" + i, o);
313
+ }
314
+ }
315
+ class wt {
316
+ /**
317
+ * Create a new class instance.
318
+ */
319
+ constructor(i) {
320
+ this.namespace = i;
321
+ }
322
+ /**
323
+ * Format the given event name.
324
+ */
325
+ format(i) {
326
+ return [".", "\\"].includes(i.charAt(0)) ? i.substring(1) : (this.namespace && (i = this.namespace + "." + i), i.replace(/\./g, "\\"));
327
+ }
328
+ /**
329
+ * Set the event namespace.
330
+ */
331
+ setNamespace(i) {
332
+ this.namespace = i;
333
+ }
334
+ }
335
+ function Mi(g) {
336
+ try {
337
+ return Reflect.construct(String, [], g), !0;
338
+ } catch {
339
+ return !1;
340
+ }
341
+ }
342
+ class qe extends Oe {
343
+ /**
344
+ * Create a new class instance.
345
+ */
346
+ constructor(i, o, c) {
347
+ super(), this.name = o, this.pusher = i, this.options = c, this.eventFormatter = new wt(this.options.namespace), this.subscribe();
348
+ }
349
+ /**
350
+ * Subscribe to a Pusher channel.
351
+ */
352
+ subscribe() {
353
+ this.subscription = this.pusher.subscribe(this.name);
354
+ }
355
+ /**
356
+ * Unsubscribe from a Pusher channel.
357
+ */
358
+ unsubscribe() {
359
+ this.pusher.unsubscribe(this.name);
360
+ }
361
+ /**
362
+ * Listen for an event on the channel instance.
363
+ */
364
+ listen(i, o) {
365
+ return this.on(this.eventFormatter.format(i), o), this;
366
+ }
367
+ /**
368
+ * Listen for all events on the channel instance.
369
+ */
370
+ listenToAll(i) {
371
+ return this.subscription.bind_global((o, c) => {
372
+ if (o.startsWith("pusher:"))
373
+ return;
374
+ let h = String(this.options.namespace ?? "").replace(
375
+ /\./g,
376
+ "\\"
377
+ ), C = o.startsWith(h) ? o.substring(h.length + 1) : "." + o;
378
+ i(C, c);
379
+ }), this;
380
+ }
381
+ /**
382
+ * Stop listening for an event on the channel instance.
383
+ */
384
+ stopListening(i, o) {
385
+ return o ? this.subscription.unbind(
386
+ this.eventFormatter.format(i),
387
+ o
388
+ ) : this.subscription.unbind(this.eventFormatter.format(i)), this;
389
+ }
390
+ /**
391
+ * Stop listening for all events on the channel instance.
392
+ */
393
+ stopListeningToAll(i) {
394
+ return i ? this.subscription.unbind_global(i) : this.subscription.unbind_global(), this;
395
+ }
396
+ /**
397
+ * Register a callback to be called anytime a subscription succeeds.
398
+ */
399
+ subscribed(i) {
400
+ return this.on("pusher:subscription_succeeded", () => {
401
+ i();
402
+ }), this;
403
+ }
404
+ /**
405
+ * Register a callback to be called anytime a subscription error occurs.
406
+ */
407
+ error(i) {
408
+ return this.on("pusher:subscription_error", (o) => {
409
+ i(o);
410
+ }), this;
411
+ }
412
+ /**
413
+ * Bind a channel to an event.
414
+ */
415
+ on(i, o) {
416
+ return this.subscription.bind(i, o), this;
417
+ }
418
+ }
419
+ class Ct extends qe {
420
+ /**
421
+ * Send a whisper event to other clients in the channel.
422
+ */
423
+ whisper(i, o) {
424
+ return this.pusher.channels.channels[this.name].trigger(
425
+ `client-${i}`,
426
+ o
427
+ ), this;
428
+ }
429
+ }
430
+ class zi extends qe {
431
+ /**
432
+ * Send a whisper event to other clients in the channel.
433
+ */
434
+ whisper(i, o) {
435
+ return this.pusher.channels.channels[this.name].trigger(
436
+ `client-${i}`,
437
+ o
438
+ ), this;
439
+ }
440
+ }
441
+ class Hi extends Ct {
442
+ /**
443
+ * Register a callback to be called anytime the member list changes.
444
+ */
445
+ here(i) {
446
+ return this.on("pusher:subscription_succeeded", (o) => {
447
+ i(Object.keys(o.members).map((c) => o.members[c]));
448
+ }), this;
449
+ }
450
+ /**
451
+ * Listen for someone joining the channel.
452
+ */
453
+ joining(i) {
454
+ return this.on("pusher:member_added", (o) => {
455
+ i(o.info);
456
+ }), this;
457
+ }
458
+ /**
459
+ * Send a whisper event to other clients in the channel.
460
+ */
461
+ whisper(i, o) {
462
+ return this.pusher.channels.channels[this.name].trigger(
463
+ `client-${i}`,
464
+ o
465
+ ), this;
466
+ }
467
+ /**
468
+ * Listen for someone leaving the channel.
469
+ */
470
+ leaving(i) {
471
+ return this.on("pusher:member_removed", (o) => {
472
+ i(o.info);
473
+ }), this;
474
+ }
475
+ }
476
+ class St extends Oe {
477
+ /**
478
+ * Create a new class instance.
479
+ */
480
+ constructor(i, o, c) {
481
+ super(), this.events = {}, this.listeners = {}, this.name = o, this.socket = i, this.options = c, this.eventFormatter = new wt(this.options.namespace), this.subscribe();
482
+ }
483
+ /**
484
+ * Subscribe to a Socket.io channel.
485
+ */
486
+ subscribe() {
487
+ this.socket.emit("subscribe", {
488
+ channel: this.name,
489
+ auth: this.options.auth || {}
490
+ });
491
+ }
492
+ /**
493
+ * Unsubscribe from channel and ubind event callbacks.
494
+ */
495
+ unsubscribe() {
496
+ this.unbind(), this.socket.emit("unsubscribe", {
497
+ channel: this.name,
498
+ auth: this.options.auth || {}
499
+ });
500
+ }
501
+ /**
502
+ * Listen for an event on the channel instance.
503
+ */
504
+ listen(i, o) {
505
+ return this.on(this.eventFormatter.format(i), o), this;
506
+ }
507
+ /**
508
+ * Stop listening for an event on the channel instance.
509
+ */
510
+ stopListening(i, o) {
511
+ return this.unbindEvent(this.eventFormatter.format(i), o), this;
512
+ }
513
+ /**
514
+ * Register a callback to be called anytime a subscription succeeds.
515
+ */
516
+ subscribed(i) {
517
+ return this.on("connect", (o) => {
518
+ i(o);
519
+ }), this;
520
+ }
521
+ /**
522
+ * Register a callback to be called anytime an error occurs.
523
+ */
524
+ error(i) {
525
+ return this;
526
+ }
527
+ /**
528
+ * Bind the channel's socket to an event and store the callback.
529
+ */
530
+ on(i, o) {
531
+ return this.listeners[i] = this.listeners[i] || [], this.events[i] || (this.events[i] = (c, h) => {
532
+ this.name === c && this.listeners[i] && this.listeners[i].forEach((C) => C(h));
533
+ }, this.socket.on(i, this.events[i])), this.listeners[i].push(o), this;
534
+ }
535
+ /**
536
+ * Unbind the channel's socket from all stored event callbacks.
537
+ */
538
+ unbind() {
539
+ Object.keys(this.events).forEach((i) => {
540
+ this.unbindEvent(i);
541
+ });
542
+ }
543
+ /**
544
+ * Unbind the listeners for the given event.
545
+ */
546
+ unbindEvent(i, o) {
547
+ this.listeners[i] = this.listeners[i] || [], o && (this.listeners[i] = this.listeners[i].filter(
548
+ (c) => c !== o
549
+ )), (!o || this.listeners[i].length === 0) && (this.events[i] && (this.socket.removeListener(i, this.events[i]), delete this.events[i]), delete this.listeners[i]);
550
+ }
551
+ }
552
+ class _t extends St {
553
+ /**
554
+ * Send a whisper event to other clients in the channel.
555
+ */
556
+ whisper(i, o) {
557
+ return this.socket.emit("client event", {
558
+ channel: this.name,
559
+ event: `client-${i}`,
560
+ data: o
561
+ }), this;
562
+ }
563
+ }
564
+ class Di extends _t {
565
+ /**
566
+ * Register a callback to be called anytime the member list changes.
567
+ */
568
+ here(i) {
569
+ return this.on("presence:subscribed", (o) => {
570
+ i(o.map((c) => c.user_info));
571
+ }), this;
572
+ }
573
+ /**
574
+ * Listen for someone joining the channel.
575
+ */
576
+ joining(i) {
577
+ return this.on(
578
+ "presence:joining",
579
+ (o) => i(o.user_info)
580
+ ), this;
581
+ }
582
+ /**
583
+ * Send a whisper event to other clients in the channel.
584
+ */
585
+ whisper(i, o) {
586
+ return this.socket.emit("client event", {
587
+ channel: this.name,
588
+ event: `client-${i}`,
589
+ data: o
590
+ }), this;
591
+ }
592
+ /**
593
+ * Listen for someone leaving the channel.
594
+ */
595
+ leaving(i) {
596
+ return this.on(
597
+ "presence:leaving",
598
+ (o) => i(o.user_info)
599
+ ), this;
600
+ }
601
+ }
602
+ class fe extends Oe {
603
+ /**
604
+ * Subscribe to a channel.
605
+ */
606
+ subscribe() {
607
+ }
608
+ /**
609
+ * Unsubscribe from a channel.
610
+ */
611
+ unsubscribe() {
612
+ }
613
+ /**
614
+ * Listen for an event on the channel instance.
615
+ */
616
+ listen(i, o) {
617
+ return this;
618
+ }
619
+ /**
620
+ * Listen for all events on the channel instance.
621
+ */
622
+ listenToAll(i) {
623
+ return this;
624
+ }
625
+ /**
626
+ * Stop listening for an event on the channel instance.
627
+ */
628
+ stopListening(i, o) {
629
+ return this;
630
+ }
631
+ /**
632
+ * Register a callback to be called anytime a subscription succeeds.
633
+ */
634
+ subscribed(i) {
635
+ return this;
636
+ }
637
+ /**
638
+ * Register a callback to be called anytime an error occurs.
639
+ */
640
+ error(i) {
641
+ return this;
642
+ }
643
+ /**
644
+ * Bind a channel to an event.
645
+ */
646
+ on(i, o) {
647
+ return this;
648
+ }
649
+ }
650
+ class Tt extends fe {
651
+ /**
652
+ * Send a whisper event to other clients in the channel.
653
+ */
654
+ whisper(i, o) {
655
+ return this;
656
+ }
657
+ }
658
+ class Wi extends fe {
659
+ /**
660
+ * Send a whisper event to other clients in the channel.
661
+ */
662
+ whisper(i, o) {
663
+ return this;
664
+ }
665
+ }
666
+ class Fi extends Tt {
667
+ /**
668
+ * Register a callback to be called anytime the member list changes.
669
+ */
670
+ here(i) {
671
+ return this;
672
+ }
673
+ /**
674
+ * Listen for someone joining the channel.
675
+ */
676
+ joining(i) {
677
+ return this;
678
+ }
679
+ /**
680
+ * Send a whisper event to other clients in the channel.
681
+ */
682
+ whisper(i, o) {
683
+ return this;
684
+ }
685
+ /**
686
+ * Listen for someone leaving the channel.
687
+ */
688
+ leaving(i) {
689
+ return this;
690
+ }
691
+ }
692
+ const kt = class Et {
693
+ /**
694
+ * Create a new class instance.
695
+ */
696
+ constructor(i) {
697
+ this.setOptions(i), this.connect();
698
+ }
699
+ /**
700
+ * Merge the custom options with the defaults.
701
+ */
702
+ setOptions(i) {
703
+ this.options = {
704
+ ...Et._defaultOptions,
705
+ ...i,
706
+ broadcaster: i.broadcaster
707
+ };
708
+ let o = this.csrfToken();
709
+ o && (this.options.auth.headers["X-CSRF-TOKEN"] = o, this.options.userAuthentication.headers["X-CSRF-TOKEN"] = o), o = this.options.bearerToken, o && (this.options.auth.headers.Authorization = "Bearer " + o, this.options.userAuthentication.headers.Authorization = "Bearer " + o);
710
+ }
711
+ /**
712
+ * Extract the CSRF token from the page.
713
+ */
714
+ csrfToken() {
715
+ var i, o;
716
+ return typeof window < "u" && (i = window.Laravel) != null && i.csrfToken ? window.Laravel.csrfToken : this.options.csrfToken ? this.options.csrfToken : typeof document < "u" && typeof document.querySelector == "function" ? ((o = document.querySelector('meta[name="csrf-token"]')) == null ? void 0 : o.getAttribute("content")) ?? null : null;
717
+ }
718
+ };
719
+ kt._defaultOptions = {
720
+ auth: {
721
+ headers: {}
722
+ },
723
+ authEndpoint: "/broadcasting/auth",
724
+ userAuthentication: {
725
+ endpoint: "/broadcasting/user-auth",
726
+ headers: {}
727
+ },
728
+ csrfToken: null,
729
+ bearerToken: null,
730
+ host: null,
731
+ key: null,
732
+ namespace: "App.Events"
733
+ };
734
+ let Ue = kt;
735
+ class pe extends Ue {
736
+ constructor() {
737
+ super(...arguments), this.channels = {};
738
+ }
739
+ /**
740
+ * Create a fresh Pusher connection.
741
+ */
742
+ connect() {
743
+ if (typeof this.options.client < "u")
744
+ this.pusher = this.options.client;
745
+ else if (this.options.Pusher)
746
+ this.pusher = new this.options.Pusher(
747
+ this.options.key,
748
+ this.options
749
+ );
750
+ else if (typeof window < "u" && typeof window.Pusher < "u")
751
+ this.pusher = new window.Pusher(this.options.key, this.options);
752
+ else
753
+ throw new Error(
754
+ "Pusher client not found. Should be globally available or passed via options.client"
755
+ );
756
+ }
757
+ /**
758
+ * Sign in the user via Pusher user authentication (https://pusher.com/docs/channels/using_channels/user-authentication/).
759
+ */
760
+ signin() {
761
+ this.pusher.signin();
762
+ }
763
+ /**
764
+ * Listen for an event on a channel instance.
765
+ */
766
+ listen(i, o, c) {
767
+ return this.channel(i).listen(o, c);
768
+ }
769
+ /**
770
+ * Get a channel instance by name.
771
+ */
772
+ channel(i) {
773
+ return this.channels[i] || (this.channels[i] = new qe(
774
+ this.pusher,
775
+ i,
776
+ this.options
777
+ )), this.channels[i];
778
+ }
779
+ /**
780
+ * Get a private channel instance by name.
781
+ */
782
+ privateChannel(i) {
783
+ return this.channels["private-" + i] || (this.channels["private-" + i] = new Ct(
784
+ this.pusher,
785
+ "private-" + i,
786
+ this.options
787
+ )), this.channels["private-" + i];
788
+ }
789
+ /**
790
+ * Get a private encrypted channel instance by name.
791
+ */
792
+ encryptedPrivateChannel(i) {
793
+ return this.channels["private-encrypted-" + i] || (this.channels["private-encrypted-" + i] = new zi(
794
+ this.pusher,
795
+ "private-encrypted-" + i,
796
+ this.options
797
+ )), this.channels["private-encrypted-" + i];
798
+ }
799
+ /**
800
+ * Get a presence channel instance by name.
801
+ */
802
+ presenceChannel(i) {
803
+ return this.channels["presence-" + i] || (this.channels["presence-" + i] = new Hi(
804
+ this.pusher,
805
+ "presence-" + i,
806
+ this.options
807
+ )), this.channels["presence-" + i];
808
+ }
809
+ /**
810
+ * Leave the given channel, as well as its private and presence variants.
811
+ */
812
+ leave(i) {
813
+ [
814
+ i,
815
+ "private-" + i,
816
+ "private-encrypted-" + i,
817
+ "presence-" + i
818
+ ].forEach((o) => {
819
+ this.leaveChannel(o);
820
+ });
821
+ }
822
+ /**
823
+ * Leave the given channel.
824
+ */
825
+ leaveChannel(i) {
826
+ this.channels[i] && (this.channels[i].unsubscribe(), delete this.channels[i]);
827
+ }
828
+ /**
829
+ * Get the socket ID for the connection.
830
+ */
831
+ socketId() {
832
+ return this.pusher.connection.socket_id;
833
+ }
834
+ /**
835
+ * Get the current connection status.
836
+ */
837
+ connectionStatus() {
838
+ const i = this.pusher.connection.state;
839
+ switch (i) {
840
+ case "connected":
841
+ case "connecting":
842
+ return i;
843
+ case "failed":
844
+ case "unavailable":
845
+ return "failed";
846
+ default:
847
+ return "disconnected";
848
+ }
849
+ }
850
+ /**
851
+ * Subscribe to connection status changes.
852
+ */
853
+ onConnectionChange(i) {
854
+ const o = () => {
855
+ i(this.connectionStatus());
856
+ }, c = ["state_change", "connected", "disconnected"];
857
+ return c.forEach((h) => {
858
+ this.pusher.connection.bind(h, o);
859
+ }), () => {
860
+ c.forEach((h) => {
861
+ this.pusher.connection.unbind(h, o);
862
+ });
863
+ };
864
+ }
865
+ /**
866
+ * Disconnect Pusher connection.
867
+ */
868
+ disconnect() {
869
+ this.pusher.disconnect();
870
+ }
871
+ }
872
+ class Bi extends Ue {
873
+ constructor() {
874
+ super(...arguments), this.channels = {};
875
+ }
876
+ /**
877
+ * Create a fresh Socket.io connection.
878
+ */
879
+ connect() {
880
+ let i = this.getSocketIO();
881
+ this.socket = i(
882
+ this.options.host ?? void 0,
883
+ this.options
884
+ ), this.socket.io.on("reconnect", () => {
885
+ Object.values(this.channels).forEach((o) => {
886
+ o.subscribe();
887
+ });
888
+ });
889
+ }
890
+ /**
891
+ * Get socket.io module from global scope or options.
892
+ */
893
+ getSocketIO() {
894
+ if (typeof this.options.client < "u")
895
+ return this.options.client;
896
+ if (typeof window < "u" && typeof window.io < "u")
897
+ return window.io;
898
+ throw new Error(
899
+ "Socket.io client not found. Should be globally available or passed via options.client"
900
+ );
901
+ }
902
+ /**
903
+ * Listen for an event on a channel instance.
904
+ */
905
+ listen(i, o, c) {
906
+ return this.channel(i).listen(o, c);
907
+ }
908
+ /**
909
+ * Get a channel instance by name.
910
+ */
911
+ channel(i) {
912
+ return this.channels[i] || (this.channels[i] = new St(
913
+ this.socket,
914
+ i,
915
+ this.options
916
+ )), this.channels[i];
917
+ }
918
+ /**
919
+ * Get a private channel instance by name.
920
+ */
921
+ privateChannel(i) {
922
+ return this.channels["private-" + i] || (this.channels["private-" + i] = new _t(
923
+ this.socket,
924
+ "private-" + i,
925
+ this.options
926
+ )), this.channels["private-" + i];
927
+ }
928
+ /**
929
+ * Get a presence channel instance by name.
930
+ */
931
+ presenceChannel(i) {
932
+ return this.channels["presence-" + i] || (this.channels["presence-" + i] = new Di(
933
+ this.socket,
934
+ "presence-" + i,
935
+ this.options
936
+ )), this.channels["presence-" + i];
937
+ }
938
+ /**
939
+ * Leave the given channel, as well as its private and presence variants.
940
+ */
941
+ leave(i) {
942
+ [i, "private-" + i, "presence-" + i].forEach((o) => {
943
+ this.leaveChannel(o);
944
+ });
945
+ }
946
+ /**
947
+ * Leave the given channel.
948
+ */
949
+ leaveChannel(i) {
950
+ this.channels[i] && (this.channels[i].unsubscribe(), delete this.channels[i]);
951
+ }
952
+ /**
953
+ * Get the socket ID for the connection.
954
+ */
955
+ socketId() {
956
+ return this.socket.id;
957
+ }
958
+ /**
959
+ * Get the current connection status.
960
+ */
961
+ connectionStatus() {
962
+ return this.socket.connected ? "connected" : this.socket.io._reconnecting ? "reconnecting" : this.socket.id !== void 0 ? "disconnected" : "connecting";
963
+ }
964
+ /**
965
+ * Subscribe to connection status changes.
966
+ */
967
+ onConnectionChange(i) {
968
+ const o = () => {
969
+ i(this.connectionStatus());
970
+ }, c = [
971
+ "connect",
972
+ "disconnect",
973
+ "connect_error",
974
+ "reconnect_attempt",
975
+ "reconnect",
976
+ "reconnect_error",
977
+ "reconnect_failed"
978
+ ];
979
+ return c.forEach((h) => {
980
+ this.socket.on(h, o);
981
+ }), () => {
982
+ c.forEach((h) => {
983
+ this.socket.off(h, o);
984
+ });
985
+ };
986
+ }
987
+ /**
988
+ * Disconnect Socketio connection.
989
+ */
990
+ disconnect() {
991
+ this.socket.disconnect();
992
+ }
993
+ }
994
+ class ft extends Ue {
995
+ constructor() {
996
+ super(...arguments), this.channels = {};
997
+ }
998
+ /**
999
+ * Create a fresh connection.
1000
+ */
1001
+ connect() {
1002
+ }
1003
+ /**
1004
+ * Listen for an event on a channel instance.
1005
+ */
1006
+ listen(i, o, c) {
1007
+ return new fe();
1008
+ }
1009
+ /**
1010
+ * Get a channel instance by name.
1011
+ */
1012
+ channel(i) {
1013
+ return new fe();
1014
+ }
1015
+ /**
1016
+ * Get a private channel instance by name.
1017
+ */
1018
+ privateChannel(i) {
1019
+ return new Tt();
1020
+ }
1021
+ /**
1022
+ * Get a private encrypted channel instance by name.
1023
+ */
1024
+ encryptedPrivateChannel(i) {
1025
+ return new Wi();
1026
+ }
1027
+ /**
1028
+ * Get a presence channel instance by name.
1029
+ */
1030
+ presenceChannel(i) {
1031
+ return new Fi();
1032
+ }
1033
+ /**
1034
+ * Leave the given channel, as well as its private and presence variants.
1035
+ */
1036
+ leave(i) {
1037
+ }
1038
+ /**
1039
+ * Leave the given channel.
1040
+ */
1041
+ leaveChannel(i) {
1042
+ }
1043
+ /**
1044
+ * Get the socket ID for the connection.
1045
+ */
1046
+ socketId() {
1047
+ return "fake-socket-id";
1048
+ }
1049
+ /**
1050
+ * Get the current connection status.
1051
+ */
1052
+ connectionStatus() {
1053
+ return "connected";
1054
+ }
1055
+ /**
1056
+ * Subscribe to connection status changes.
1057
+ */
1058
+ onConnectionChange(i) {
1059
+ return () => {
1060
+ };
1061
+ }
1062
+ /**
1063
+ * Disconnect the connection.
1064
+ */
1065
+ disconnect() {
1066
+ }
1067
+ }
1068
+ class $i {
1069
+ /**
1070
+ * Create a new class instance.
1071
+ */
1072
+ constructor(i) {
1073
+ this.options = i, this.connect(), this.options.withoutInterceptors || this.registerInterceptors();
1074
+ }
1075
+ /**
1076
+ * Get a channel instance by name.
1077
+ */
1078
+ channel(i) {
1079
+ return this.connector.channel(i);
1080
+ }
1081
+ /**
1082
+ * Create a new connection.
1083
+ */
1084
+ connect() {
1085
+ if (this.options.broadcaster === "reverb")
1086
+ this.connector = new pe({
1087
+ ...this.options,
1088
+ cluster: ""
1089
+ });
1090
+ else if (this.options.broadcaster === "pusher")
1091
+ this.connector = new pe(this.options);
1092
+ else if (this.options.broadcaster === "ably")
1093
+ this.connector = new pe({
1094
+ ...this.options,
1095
+ cluster: "",
1096
+ broadcaster: "pusher"
1097
+ });
1098
+ else if (this.options.broadcaster === "socket.io")
1099
+ this.connector = new Bi(this.options);
1100
+ else if (this.options.broadcaster === "null")
1101
+ this.connector = new ft(this.options);
1102
+ else if (typeof this.options.broadcaster == "function" && Mi(this.options.broadcaster))
1103
+ this.connector = new this.options.broadcaster(this.options);
1104
+ else
1105
+ throw new Error(
1106
+ `Broadcaster ${typeof this.options.broadcaster} ${String(this.options.broadcaster)} is not supported.`
1107
+ );
1108
+ }
1109
+ /**
1110
+ * Disconnect from the Echo server.
1111
+ */
1112
+ disconnect() {
1113
+ this.connector.disconnect();
1114
+ }
1115
+ /**
1116
+ * Get a presence channel instance by name.
1117
+ */
1118
+ join(i) {
1119
+ return this.connector.presenceChannel(i);
1120
+ }
1121
+ /**
1122
+ * Leave the given channel, as well as its private and presence variants.
1123
+ */
1124
+ leave(i) {
1125
+ this.connector.leave(i);
1126
+ }
1127
+ /**
1128
+ * Leave the given channel.
1129
+ */
1130
+ leaveChannel(i) {
1131
+ this.connector.leaveChannel(i);
1132
+ }
1133
+ /**
1134
+ * Leave all channels.
1135
+ */
1136
+ leaveAllChannels() {
1137
+ for (const i in this.connector.channels)
1138
+ this.leaveChannel(i);
1139
+ }
1140
+ /**
1141
+ * Listen for an event on a channel instance.
1142
+ */
1143
+ listen(i, o, c) {
1144
+ return this.connector.listen(i, o, c);
1145
+ }
1146
+ /**
1147
+ * Get a private channel instance by name.
1148
+ */
1149
+ private(i) {
1150
+ return this.connector.privateChannel(i);
1151
+ }
1152
+ /**
1153
+ * Get a private encrypted channel instance by name.
1154
+ */
1155
+ encryptedPrivate(i) {
1156
+ if (this.connectorSupportsEncryptedPrivateChannels(this.connector))
1157
+ return this.connector.encryptedPrivateChannel(i);
1158
+ throw new Error(
1159
+ `Broadcaster ${typeof this.options.broadcaster} ${String(
1160
+ this.options.broadcaster
1161
+ )} does not support encrypted private channels.`
1162
+ );
1163
+ }
1164
+ connectorSupportsEncryptedPrivateChannels(i) {
1165
+ return i instanceof pe || i instanceof ft;
1166
+ }
1167
+ /**
1168
+ * Get the Socket ID for the connection.
1169
+ */
1170
+ socketId() {
1171
+ return this.connector.socketId();
1172
+ }
1173
+ /**
1174
+ * Get the current connection status.
1175
+ */
1176
+ connectionStatus() {
1177
+ return this.connector.connectionStatus();
1178
+ }
1179
+ /**
1180
+ * Register 3rd party request interceptors. These are used to automatically
1181
+ * send a connections socket id to a Laravel app with a X-Socket-Id header.
1182
+ */
1183
+ registerInterceptors() {
1184
+ typeof Vue < "u" && Vue != null && Vue.http && this.registerVueRequestInterceptor(), typeof axios == "function" && this.registerAxiosRequestInterceptor(), typeof jQuery == "function" && this.registerjQueryAjaxSetup(), typeof Turbo == "object" && this.registerTurboRequestInterceptor();
1185
+ }
1186
+ /**
1187
+ * Register a Vue HTTP interceptor to add the X-Socket-ID header.
1188
+ */
1189
+ registerVueRequestInterceptor() {
1190
+ Vue.http.interceptors.push(
1191
+ (i, o) => {
1192
+ this.socketId() && i.headers.set("X-Socket-ID", this.socketId()), o();
1193
+ }
1194
+ );
1195
+ }
1196
+ /**
1197
+ * Register an Axios HTTP interceptor to add the X-Socket-ID header.
1198
+ */
1199
+ registerAxiosRequestInterceptor() {
1200
+ axios.interceptors.request.use(
1201
+ (i) => (this.socketId() && (i.headers["X-Socket-Id"] = this.socketId()), i)
1202
+ );
1203
+ }
1204
+ /**
1205
+ * Register jQuery AjaxPrefilter to add the X-Socket-ID header.
1206
+ */
1207
+ registerjQueryAjaxSetup() {
1208
+ typeof jQuery.ajax < "u" && jQuery.ajaxPrefilter(
1209
+ (i, o, c) => {
1210
+ this.socketId() && c.setRequestHeader("X-Socket-Id", this.socketId());
1211
+ }
1212
+ );
1213
+ }
1214
+ /**
1215
+ * Register the Turbo Request interceptor to add the X-Socket-ID header.
1216
+ */
1217
+ registerTurboRequestInterceptor() {
1218
+ document.addEventListener(
1219
+ "turbo:before-fetch-request",
1220
+ (i) => {
1221
+ i.detail.fetchOptions.headers["X-Socket-Id"] = this.socketId();
1222
+ }
1223
+ );
1224
+ }
1225
+ }
1226
+ function Xi(g) {
1227
+ return g && g.__esModule && Object.prototype.hasOwnProperty.call(g, "default") ? g.default : g;
1228
+ }
1229
+ var Ae = { exports: {} };
1230
+ var gt;
1231
+ function Vi() {
1232
+ return gt || (gt = 1, (function(g, i) {
1233
+ (function(c, h) {
1234
+ g.exports = h();
1235
+ })(self, () => (
1236
+ /******/
1237
+ (() => {
1238
+ var o = {
1239
+ /***/
1240
+ 594(y, f) {
1241
+ var m = this && this.__extends || /* @__PURE__ */ (function() {
1242
+ var T = function(l, d) {
1243
+ return T = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(w, P) {
1244
+ w.__proto__ = P;
1245
+ } || function(w, P) {
1246
+ for (var q in P) P.hasOwnProperty(q) && (w[q] = P[q]);
1247
+ }, T(l, d);
1248
+ };
1249
+ return function(l, d) {
1250
+ T(l, d);
1251
+ function w() {
1252
+ this.constructor = l;
1253
+ }
1254
+ l.prototype = d === null ? Object.create(d) : (w.prototype = d.prototype, new w());
1255
+ };
1256
+ })();
1257
+ Object.defineProperty(f, "__esModule", { value: !0 });
1258
+ var k = 256, S = (
1259
+ /** @class */
1260
+ (function() {
1261
+ function T(l) {
1262
+ l === void 0 && (l = "="), this._paddingCharacter = l;
1263
+ }
1264
+ return T.prototype.encodedLength = function(l) {
1265
+ return this._paddingCharacter ? (l + 2) / 3 * 4 | 0 : (l * 8 + 5) / 6 | 0;
1266
+ }, T.prototype.encode = function(l) {
1267
+ for (var d = "", w = 0; w < l.length - 2; w += 3) {
1268
+ var P = l[w] << 16 | l[w + 1] << 8 | l[w + 2];
1269
+ d += this._encodeByte(P >>> 18 & 63), d += this._encodeByte(P >>> 12 & 63), d += this._encodeByte(P >>> 6 & 63), d += this._encodeByte(P >>> 0 & 63);
1270
+ }
1271
+ var q = l.length - w;
1272
+ if (q > 0) {
1273
+ var P = l[w] << 16 | (q === 2 ? l[w + 1] << 8 : 0);
1274
+ d += this._encodeByte(P >>> 18 & 63), d += this._encodeByte(P >>> 12 & 63), q === 2 ? d += this._encodeByte(P >>> 6 & 63) : d += this._paddingCharacter || "", d += this._paddingCharacter || "";
1275
+ }
1276
+ return d;
1277
+ }, T.prototype.maxDecodedLength = function(l) {
1278
+ return this._paddingCharacter ? l / 4 * 3 | 0 : (l * 6 + 7) / 8 | 0;
1279
+ }, T.prototype.decodedLength = function(l) {
1280
+ return this.maxDecodedLength(l.length - this._getPaddingLength(l));
1281
+ }, T.prototype.decode = function(l) {
1282
+ if (l.length === 0)
1283
+ return new Uint8Array(0);
1284
+ for (var d = this._getPaddingLength(l), w = l.length - d, P = new Uint8Array(this.maxDecodedLength(w)), q = 0, N = 0, z = 0, V = 0, D = 0, H = 0, J = 0; N < w - 4; N += 4)
1285
+ V = this._decodeChar(l.charCodeAt(N + 0)), D = this._decodeChar(l.charCodeAt(N + 1)), H = this._decodeChar(l.charCodeAt(N + 2)), J = this._decodeChar(l.charCodeAt(N + 3)), P[q++] = V << 2 | D >>> 4, P[q++] = D << 4 | H >>> 2, P[q++] = H << 6 | J, z |= V & k, z |= D & k, z |= H & k, z |= J & k;
1286
+ if (N < w - 1 && (V = this._decodeChar(l.charCodeAt(N)), D = this._decodeChar(l.charCodeAt(N + 1)), P[q++] = V << 2 | D >>> 4, z |= V & k, z |= D & k), N < w - 2 && (H = this._decodeChar(l.charCodeAt(N + 2)), P[q++] = D << 4 | H >>> 2, z |= H & k), N < w - 3 && (J = this._decodeChar(l.charCodeAt(N + 3)), P[q++] = H << 6 | J, z |= J & k), z !== 0)
1287
+ throw new Error("Base64Coder: incorrect characters for decoding");
1288
+ return P;
1289
+ }, T.prototype._encodeByte = function(l) {
1290
+ var d = l;
1291
+ return d += 65, d += 25 - l >>> 8 & 6, d += 51 - l >>> 8 & -75, d += 61 - l >>> 8 & -15, d += 62 - l >>> 8 & 3, String.fromCharCode(d);
1292
+ }, T.prototype._decodeChar = function(l) {
1293
+ var d = k;
1294
+ return d += (42 - l & l - 44) >>> 8 & -k + l - 43 + 62, d += (46 - l & l - 48) >>> 8 & -k + l - 47 + 63, d += (47 - l & l - 58) >>> 8 & -k + l - 48 + 52, d += (64 - l & l - 91) >>> 8 & -k + l - 65 + 0, d += (96 - l & l - 123) >>> 8 & -k + l - 97 + 26, d;
1295
+ }, T.prototype._getPaddingLength = function(l) {
1296
+ var d = 0;
1297
+ if (this._paddingCharacter) {
1298
+ for (var w = l.length - 1; w >= 0 && l[w] === this._paddingCharacter; w--)
1299
+ d++;
1300
+ if (l.length < 4 || d > 2)
1301
+ throw new Error("Base64Coder: incorrect padding");
1302
+ }
1303
+ return d;
1304
+ }, T;
1305
+ })()
1306
+ );
1307
+ f.Coder = S;
1308
+ var L = new S();
1309
+ function _(T) {
1310
+ return L.encode(T);
1311
+ }
1312
+ f.encode = _;
1313
+ function A(T) {
1314
+ return L.decode(T);
1315
+ }
1316
+ f.decode = A;
1317
+ var W = (
1318
+ /** @class */
1319
+ (function(T) {
1320
+ m(l, T);
1321
+ function l() {
1322
+ return T !== null && T.apply(this, arguments) || this;
1323
+ }
1324
+ return l.prototype._encodeByte = function(d) {
1325
+ var w = d;
1326
+ return w += 65, w += 25 - d >>> 8 & 6, w += 51 - d >>> 8 & -75, w += 61 - d >>> 8 & -13, w += 62 - d >>> 8 & 49, String.fromCharCode(w);
1327
+ }, l.prototype._decodeChar = function(d) {
1328
+ var w = k;
1329
+ return w += (44 - d & d - 46) >>> 8 & -k + d - 45 + 62, w += (94 - d & d - 96) >>> 8 & -k + d - 95 + 63, w += (47 - d & d - 58) >>> 8 & -k + d - 48 + 52, w += (64 - d & d - 91) >>> 8 & -k + d - 65 + 0, w += (96 - d & d - 123) >>> 8 & -k + d - 97 + 26, w;
1330
+ }, l;
1331
+ })(S)
1332
+ );
1333
+ f.URLSafeCoder = W;
1334
+ var j = new W();
1335
+ function F(T) {
1336
+ return j.encode(T);
1337
+ }
1338
+ f.encodeURLSafe = F;
1339
+ function ee(T) {
1340
+ return j.decode(T);
1341
+ }
1342
+ f.decodeURLSafe = ee, f.encodedLength = function(T) {
1343
+ return L.encodedLength(T);
1344
+ }, f.maxDecodedLength = function(T) {
1345
+ return L.maxDecodedLength(T);
1346
+ }, f.decodedLength = function(T) {
1347
+ return L.decodedLength(T);
1348
+ };
1349
+ },
1350
+ /***/
1351
+ 978(y, f) {
1352
+ var m = "utf8: invalid source encoding";
1353
+ function k(S) {
1354
+ for (var L = [], _ = 0; _ < S.length; _++) {
1355
+ var A = S[_];
1356
+ if (A & 128) {
1357
+ var W = void 0;
1358
+ if (A < 224) {
1359
+ if (_ >= S.length)
1360
+ throw new Error(m);
1361
+ var j = S[++_];
1362
+ if ((j & 192) !== 128)
1363
+ throw new Error(m);
1364
+ A = (A & 31) << 6 | j & 63, W = 128;
1365
+ } else if (A < 240) {
1366
+ if (_ >= S.length - 1)
1367
+ throw new Error(m);
1368
+ var j = S[++_], F = S[++_];
1369
+ if ((j & 192) !== 128 || (F & 192) !== 128)
1370
+ throw new Error(m);
1371
+ A = (A & 15) << 12 | (j & 63) << 6 | F & 63, W = 2048;
1372
+ } else if (A < 248) {
1373
+ if (_ >= S.length - 2)
1374
+ throw new Error(m);
1375
+ var j = S[++_], F = S[++_], ee = S[++_];
1376
+ if ((j & 192) !== 128 || (F & 192) !== 128 || (ee & 192) !== 128)
1377
+ throw new Error(m);
1378
+ A = (A & 15) << 18 | (j & 63) << 12 | (F & 63) << 6 | ee & 63, W = 65536;
1379
+ } else
1380
+ throw new Error(m);
1381
+ if (A < W || A >= 55296 && A <= 57343)
1382
+ throw new Error(m);
1383
+ if (A >= 65536) {
1384
+ if (A > 1114111)
1385
+ throw new Error(m);
1386
+ A -= 65536, L.push(String.fromCharCode(55296 | A >> 10)), A = 56320 | A & 1023;
1387
+ }
1388
+ }
1389
+ L.push(String.fromCharCode(A));
1390
+ }
1391
+ return L.join("");
1392
+ }
1393
+ f.D4 = k;
1394
+ },
1395
+ /***/
1396
+ 721(y, f, m) {
1397
+ y.exports = m(207).default;
1398
+ },
1399
+ /***/
1400
+ 207(y, f, m) {
1401
+ m.d(f, {
1402
+ default: () => (
1403
+ /* binding */
1404
+ le
1405
+ )
1406
+ });
1407
+ class k {
1408
+ constructor(e, t) {
1409
+ this.lastId = 0, this.prefix = e, this.name = t;
1410
+ }
1411
+ create(e) {
1412
+ this.lastId++;
1413
+ var t = this.lastId, r = this.prefix + t, s = this.name + "[" + t + "]", a = !1, u = function() {
1414
+ a || (e.apply(null, arguments), a = !0);
1415
+ };
1416
+ return this[t] = u, { number: t, id: r, name: s, callback: u };
1417
+ }
1418
+ remove(e) {
1419
+ delete this[e.number];
1420
+ }
1421
+ }
1422
+ var S = new k("_pusher_script_", "Pusher.ScriptReceivers"), L = {
1423
+ VERSION: "8.5.0",
1424
+ PROTOCOL: 7,
1425
+ wsPort: 80,
1426
+ wssPort: 443,
1427
+ wsPath: "",
1428
+ httpHost: "sockjs.pusher.com",
1429
+ httpPort: 80,
1430
+ httpsPort: 443,
1431
+ httpPath: "/pusher",
1432
+ stats_host: "stats.pusher.com",
1433
+ authEndpoint: "/pusher/auth",
1434
+ authTransport: "ajax",
1435
+ activityTimeout: 12e4,
1436
+ pongTimeout: 3e4,
1437
+ unavailableTimeout: 1e4,
1438
+ userAuthentication: {
1439
+ endpoint: "/pusher/user-auth",
1440
+ transport: "ajax"
1441
+ },
1442
+ channelAuthorization: {
1443
+ endpoint: "/pusher/auth",
1444
+ transport: "ajax"
1445
+ },
1446
+ cdn_http: "http://js.pusher.com",
1447
+ cdn_https: "https://js.pusher.com",
1448
+ dependency_suffix: ""
1449
+ };
1450
+ const _ = L;
1451
+ class A {
1452
+ constructor(e) {
1453
+ this.options = e, this.receivers = e.receivers || S, this.loading = {};
1454
+ }
1455
+ load(e, t, r) {
1456
+ var s = this;
1457
+ if (s.loading[e] && s.loading[e].length > 0)
1458
+ s.loading[e].push(r);
1459
+ else {
1460
+ s.loading[e] = [r];
1461
+ var a = b.createScriptRequest(s.getPath(e, t)), u = s.receivers.create(function(p) {
1462
+ if (s.receivers.remove(u), s.loading[e]) {
1463
+ var v = s.loading[e];
1464
+ delete s.loading[e];
1465
+ for (var E = function(I) {
1466
+ I || a.cleanup();
1467
+ }, x = 0; x < v.length; x++)
1468
+ v[x](p, E);
1469
+ }
1470
+ });
1471
+ a.send(u);
1472
+ }
1473
+ }
1474
+ getRoot(e) {
1475
+ var t, r = b.getDocument().location.protocol;
1476
+ return e && e.useTLS || r === "https:" ? t = this.options.cdn_https : t = this.options.cdn_http, t.replace(/\/*$/, "") + "/" + this.options.version;
1477
+ }
1478
+ getPath(e, t) {
1479
+ return this.getRoot(t) + "/" + e + this.options.suffix + ".js";
1480
+ }
1481
+ }
1482
+ var W = new k("_pusher_dependencies", "Pusher.DependenciesReceivers"), j = new A({
1483
+ cdn_http: _.cdn_http,
1484
+ cdn_https: _.cdn_https,
1485
+ version: _.VERSION,
1486
+ suffix: _.dependency_suffix,
1487
+ receivers: W
1488
+ });
1489
+ const F = {
1490
+ baseUrl: "https://pusher.com",
1491
+ urls: {
1492
+ authenticationEndpoint: {
1493
+ path: "/docs/channels/server_api/authenticating_users"
1494
+ },
1495
+ authorizationEndpoint: {
1496
+ path: "/docs/channels/server_api/authorizing-users/"
1497
+ },
1498
+ javascriptQuickStart: {
1499
+ path: "/docs/javascript_quick_start"
1500
+ },
1501
+ triggeringClientEvents: {
1502
+ path: "/docs/client_api_guide/client_events#trigger-events"
1503
+ },
1504
+ encryptedChannelSupport: {
1505
+ fullUrl: "https://github.com/pusher/pusher-js/tree/cc491015371a4bde5743d1c87a0fbac0feb53195#encrypted-channel-support"
1506
+ }
1507
+ }
1508
+ }, T = { buildLogSuffix: function(n) {
1509
+ const e = "See:", t = F.urls[n];
1510
+ if (!t)
1511
+ return "";
1512
+ let r;
1513
+ return t.fullUrl ? r = t.fullUrl : t.path && (r = F.baseUrl + t.path), r ? `${e} ${r}` : "";
1514
+ } };
1515
+ var l;
1516
+ (function(n) {
1517
+ n.UserAuthentication = "user-authentication", n.ChannelAuthorization = "channel-authorization";
1518
+ })(l || (l = {}));
1519
+ class d extends Error {
1520
+ constructor(e) {
1521
+ super(e), Object.setPrototypeOf(this, new.target.prototype);
1522
+ }
1523
+ }
1524
+ class w extends Error {
1525
+ constructor(e) {
1526
+ super(e), Object.setPrototypeOf(this, new.target.prototype);
1527
+ }
1528
+ }
1529
+ class P extends Error {
1530
+ constructor(e) {
1531
+ super(e), Object.setPrototypeOf(this, new.target.prototype);
1532
+ }
1533
+ }
1534
+ class q extends Error {
1535
+ constructor(e) {
1536
+ super(e), Object.setPrototypeOf(this, new.target.prototype);
1537
+ }
1538
+ }
1539
+ class N extends Error {
1540
+ constructor(e) {
1541
+ super(e), Object.setPrototypeOf(this, new.target.prototype);
1542
+ }
1543
+ }
1544
+ class z extends Error {
1545
+ constructor(e) {
1546
+ super(e), Object.setPrototypeOf(this, new.target.prototype);
1547
+ }
1548
+ }
1549
+ class V extends Error {
1550
+ constructor(e) {
1551
+ super(e), Object.setPrototypeOf(this, new.target.prototype);
1552
+ }
1553
+ }
1554
+ class D extends Error {
1555
+ constructor(e) {
1556
+ super(e), Object.setPrototypeOf(this, new.target.prototype);
1557
+ }
1558
+ }
1559
+ class H extends Error {
1560
+ constructor(e, t) {
1561
+ super(t), this.status = e, Object.setPrototypeOf(this, new.target.prototype);
1562
+ }
1563
+ }
1564
+ const xt = function(n, e, t, r, s) {
1565
+ const a = b.createXHR();
1566
+ a.open("POST", t.endpoint, !0), a.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
1567
+ for (var u in t.headers)
1568
+ a.setRequestHeader(u, t.headers[u]);
1569
+ if (t.headersProvider != null) {
1570
+ let p = t.headersProvider();
1571
+ for (var u in p)
1572
+ a.setRequestHeader(u, p[u]);
1573
+ }
1574
+ return a.onreadystatechange = function() {
1575
+ if (a.readyState === 4)
1576
+ if (a.status === 200) {
1577
+ let p, v = !1;
1578
+ try {
1579
+ p = JSON.parse(a.responseText), v = !0;
1580
+ } catch {
1581
+ s(new H(200, `JSON returned from ${r.toString()} endpoint was invalid, yet status code was 200. Data was: ${a.responseText}`), null);
1582
+ }
1583
+ v && s(null, p);
1584
+ } else {
1585
+ let p = "";
1586
+ switch (r) {
1587
+ case l.UserAuthentication:
1588
+ p = T.buildLogSuffix("authenticationEndpoint");
1589
+ break;
1590
+ case l.ChannelAuthorization:
1591
+ p = `Clients must be authorized to join private or presence channels. ${T.buildLogSuffix("authorizationEndpoint")}`;
1592
+ break;
1593
+ }
1594
+ s(new H(a.status, `Unable to retrieve auth string from ${r.toString()} endpoint - received status: ${a.status} from ${t.endpoint}. ${p}`), null);
1595
+ }
1596
+ }, a.send(e), a;
1597
+ };
1598
+ function At(n) {
1599
+ return It(Rt(n));
1600
+ }
1601
+ var te = String.fromCharCode, oe = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", Pt = function(n) {
1602
+ var e = n.charCodeAt(0);
1603
+ return e < 128 ? n : e < 2048 ? te(192 | e >>> 6) + te(128 | e & 63) : te(224 | e >>> 12 & 15) + te(128 | e >>> 6 & 63) + te(128 | e & 63);
1604
+ }, Rt = function(n) {
1605
+ return n.replace(/[^\x00-\x7F]/g, Pt);
1606
+ }, Lt = function(n) {
1607
+ var e = [0, 2, 1][n.length % 3], t = n.charCodeAt(0) << 16 | (n.length > 1 ? n.charCodeAt(1) : 0) << 8 | (n.length > 2 ? n.charCodeAt(2) : 0), r = [
1608
+ oe.charAt(t >>> 18),
1609
+ oe.charAt(t >>> 12 & 63),
1610
+ e >= 2 ? "=" : oe.charAt(t >>> 6 & 63),
1611
+ e >= 1 ? "=" : oe.charAt(t & 63)
1612
+ ];
1613
+ return r.join("");
1614
+ }, It = window.btoa || function(n) {
1615
+ return n.replace(/[\s\S]{1,3}/g, Lt);
1616
+ };
1617
+ class Ot {
1618
+ constructor(e, t, r, s) {
1619
+ this.clear = t, this.timer = e(() => {
1620
+ this.timer && (this.timer = s(this.timer));
1621
+ }, r);
1622
+ }
1623
+ isRunning() {
1624
+ return this.timer !== null;
1625
+ }
1626
+ ensureAborted() {
1627
+ this.timer && (this.clear(this.timer), this.timer = null);
1628
+ }
1629
+ }
1630
+ const Me = Ot;
1631
+ function qt(n) {
1632
+ window.clearTimeout(n);
1633
+ }
1634
+ function Ut(n) {
1635
+ window.clearInterval(n);
1636
+ }
1637
+ class G extends Me {
1638
+ constructor(e, t) {
1639
+ super(setTimeout, qt, e, function(r) {
1640
+ return t(), null;
1641
+ });
1642
+ }
1643
+ }
1644
+ class jt extends Me {
1645
+ constructor(e, t) {
1646
+ super(setInterval, Ut, e, function(r) {
1647
+ return t(), r;
1648
+ });
1649
+ }
1650
+ }
1651
+ var Nt = {
1652
+ now() {
1653
+ return Date.now ? Date.now() : (/* @__PURE__ */ new Date()).valueOf();
1654
+ },
1655
+ defer(n) {
1656
+ return new G(0, n);
1657
+ },
1658
+ method(n, ...e) {
1659
+ var t = Array.prototype.slice.call(arguments, 1);
1660
+ return function(r) {
1661
+ return r[n].apply(r, t.concat(arguments));
1662
+ };
1663
+ }
1664
+ };
1665
+ const U = Nt;
1666
+ function M(n, ...e) {
1667
+ for (var t = 0; t < e.length; t++) {
1668
+ var r = e[t];
1669
+ for (var s in r)
1670
+ r[s] && r[s].constructor && r[s].constructor === Object ? n[s] = M(n[s] || {}, r[s]) : n[s] = r[s];
1671
+ }
1672
+ return n;
1673
+ }
1674
+ function Mt() {
1675
+ for (var n = ["Pusher"], e = 0; e < arguments.length; e++)
1676
+ typeof arguments[e] == "string" ? n.push(arguments[e]) : n.push(ae(arguments[e]));
1677
+ return n.join(" : ");
1678
+ }
1679
+ function ze(n, e) {
1680
+ var t = Array.prototype.indexOf;
1681
+ if (n === null)
1682
+ return -1;
1683
+ if (t && n.indexOf === t)
1684
+ return n.indexOf(e);
1685
+ for (var r = 0, s = n.length; r < s; r++)
1686
+ if (n[r] === e)
1687
+ return r;
1688
+ return -1;
1689
+ }
1690
+ function B(n, e) {
1691
+ for (var t in n)
1692
+ Object.prototype.hasOwnProperty.call(n, t) && e(n[t], t, n);
1693
+ }
1694
+ function He(n) {
1695
+ var e = [];
1696
+ return B(n, function(t, r) {
1697
+ e.push(r);
1698
+ }), e;
1699
+ }
1700
+ function zt(n) {
1701
+ var e = [];
1702
+ return B(n, function(t) {
1703
+ e.push(t);
1704
+ }), e;
1705
+ }
1706
+ function ne(n, e, t) {
1707
+ for (var r = 0; r < n.length; r++)
1708
+ e.call(t || window, n[r], r, n);
1709
+ }
1710
+ function De(n, e) {
1711
+ for (var t = [], r = 0; r < n.length; r++)
1712
+ t.push(e(n[r], r, n, t));
1713
+ return t;
1714
+ }
1715
+ function Ht(n, e) {
1716
+ var t = {};
1717
+ return B(n, function(r, s) {
1718
+ t[s] = e(r);
1719
+ }), t;
1720
+ }
1721
+ function We(n, e) {
1722
+ e = e || function(s) {
1723
+ return !!s;
1724
+ };
1725
+ for (var t = [], r = 0; r < n.length; r++)
1726
+ e(n[r], r, n, t) && t.push(n[r]);
1727
+ return t;
1728
+ }
1729
+ function Fe(n, e) {
1730
+ var t = {};
1731
+ return B(n, function(r, s) {
1732
+ (e && e(r, s, n, t) || r) && (t[s] = r);
1733
+ }), t;
1734
+ }
1735
+ function Dt(n) {
1736
+ var e = [];
1737
+ return B(n, function(t, r) {
1738
+ e.push([r, t]);
1739
+ }), e;
1740
+ }
1741
+ function Be(n, e) {
1742
+ for (var t = 0; t < n.length; t++)
1743
+ if (e(n[t], t, n))
1744
+ return !0;
1745
+ return !1;
1746
+ }
1747
+ function Wt(n, e) {
1748
+ for (var t = 0; t < n.length; t++)
1749
+ if (!e(n[t], t, n))
1750
+ return !1;
1751
+ return !0;
1752
+ }
1753
+ function Ft(n) {
1754
+ return Ht(n, function(e) {
1755
+ return typeof e == "object" && (e = ae(e)), encodeURIComponent(At(e.toString()));
1756
+ });
1757
+ }
1758
+ function Bt(n) {
1759
+ var e = Fe(n, function(r) {
1760
+ return r !== void 0;
1761
+ }), t = De(Dt(Ft(e)), U.method("join", "=")).join("&");
1762
+ return t;
1763
+ }
1764
+ function $t(n) {
1765
+ var e = [], t = [];
1766
+ return (function r(s, a) {
1767
+ var u, p, v;
1768
+ switch (typeof s) {
1769
+ case "object":
1770
+ if (!s)
1771
+ return null;
1772
+ for (u = 0; u < e.length; u += 1)
1773
+ if (e[u] === s)
1774
+ return { $ref: t[u] };
1775
+ if (e.push(s), t.push(a), Object.prototype.toString.apply(s) === "[object Array]")
1776
+ for (v = [], u = 0; u < s.length; u += 1)
1777
+ v[u] = r(s[u], a + "[" + u + "]");
1778
+ else {
1779
+ v = {};
1780
+ for (p in s)
1781
+ Object.prototype.hasOwnProperty.call(s, p) && (v[p] = r(s[p], a + "[" + JSON.stringify(p) + "]"));
1782
+ }
1783
+ return v;
1784
+ case "number":
1785
+ case "string":
1786
+ case "boolean":
1787
+ return s;
1788
+ }
1789
+ })(n, "$");
1790
+ }
1791
+ function ae(n) {
1792
+ try {
1793
+ return JSON.stringify(n);
1794
+ } catch {
1795
+ return JSON.stringify($t(n));
1796
+ }
1797
+ }
1798
+ class Xt {
1799
+ constructor() {
1800
+ this.globalLog = (e) => {
1801
+ window.console && window.console.log && window.console.log(e);
1802
+ };
1803
+ }
1804
+ debug(...e) {
1805
+ this.log(this.globalLog, e);
1806
+ }
1807
+ warn(...e) {
1808
+ this.log(this.globalLogWarn, e);
1809
+ }
1810
+ error(...e) {
1811
+ this.log(this.globalLogError, e);
1812
+ }
1813
+ globalLogWarn(e) {
1814
+ window.console && window.console.warn ? window.console.warn(e) : this.globalLog(e);
1815
+ }
1816
+ globalLogError(e) {
1817
+ window.console && window.console.error ? window.console.error(e) : this.globalLogWarn(e);
1818
+ }
1819
+ log(e, ...t) {
1820
+ var r = Mt.apply(this, arguments);
1821
+ le.log ? le.log(r) : le.logToConsole && e.bind(this)(r);
1822
+ }
1823
+ }
1824
+ const R = new Xt();
1825
+ var Vt = function(n, e, t, r, s) {
1826
+ (t.headers !== void 0 || t.headersProvider != null) && R.warn(`To send headers with the ${r.toString()} request, you must use AJAX, rather than JSONP.`);
1827
+ var a = n.nextAuthCallbackID.toString();
1828
+ n.nextAuthCallbackID++;
1829
+ var u = n.getDocument(), p = u.createElement("script");
1830
+ n.auth_callbacks[a] = function(x) {
1831
+ s(null, x);
1832
+ };
1833
+ var v = "Pusher.auth_callbacks['" + a + "']";
1834
+ p.src = t.endpoint + "?callback=" + encodeURIComponent(v) + "&" + e;
1835
+ var E = u.getElementsByTagName("head")[0] || u.documentElement;
1836
+ E.insertBefore(p, E.firstChild);
1837
+ };
1838
+ const Jt = Vt;
1839
+ class Gt {
1840
+ constructor(e) {
1841
+ this.src = e;
1842
+ }
1843
+ send(e) {
1844
+ var t = this, r = "Error loading " + t.src;
1845
+ t.script = document.createElement("script"), t.script.id = e.id, t.script.src = t.src, t.script.type = "text/javascript", t.script.charset = "UTF-8", t.script.addEventListener ? (t.script.onerror = function() {
1846
+ e.callback(r);
1847
+ }, t.script.onload = function() {
1848
+ e.callback(null);
1849
+ }) : t.script.onreadystatechange = function() {
1850
+ (t.script.readyState === "loaded" || t.script.readyState === "complete") && e.callback(null);
1851
+ }, t.script.async === void 0 && document.attachEvent && /opera/i.test(navigator.userAgent) ? (t.errorScript = document.createElement("script"), t.errorScript.id = e.id + "_error", t.errorScript.text = e.name + "('" + r + "');", t.script.async = t.errorScript.async = !1) : t.script.async = !0;
1852
+ var s = document.getElementsByTagName("head")[0];
1853
+ s.insertBefore(t.script, s.firstChild), t.errorScript && s.insertBefore(t.errorScript, t.script.nextSibling);
1854
+ }
1855
+ cleanup() {
1856
+ this.script && (this.script.onload = this.script.onerror = null, this.script.onreadystatechange = null), this.script && this.script.parentNode && this.script.parentNode.removeChild(this.script), this.errorScript && this.errorScript.parentNode && this.errorScript.parentNode.removeChild(this.errorScript), this.script = null, this.errorScript = null;
1857
+ }
1858
+ }
1859
+ class Kt {
1860
+ constructor(e, t) {
1861
+ this.url = e, this.data = t;
1862
+ }
1863
+ send(e) {
1864
+ if (!this.request) {
1865
+ var t = Bt(this.data), r = this.url + "/" + e.number + "?" + t;
1866
+ this.request = b.createScriptRequest(r), this.request.send(e);
1867
+ }
1868
+ }
1869
+ cleanup() {
1870
+ this.request && this.request.cleanup();
1871
+ }
1872
+ }
1873
+ var Qt = function(n, e) {
1874
+ return function(t, r) {
1875
+ var s = "http" + (e ? "s" : "") + "://", a = s + (n.host || n.options.host) + n.options.path, u = b.createJSONPRequest(a, t), p = b.ScriptReceivers.create(function(v, E) {
1876
+ S.remove(p), u.cleanup(), E && E.host && (n.host = E.host), r && r(v, E);
1877
+ });
1878
+ u.send(p);
1879
+ };
1880
+ }, Yt = {
1881
+ name: "jsonp",
1882
+ getAgent: Qt
1883
+ };
1884
+ const Zt = Yt;
1885
+ function me(n, e, t) {
1886
+ var r = n + (e.useTLS ? "s" : ""), s = e.useTLS ? e.hostTLS : e.hostNonTLS;
1887
+ return r + "://" + s + t;
1888
+ }
1889
+ function ve(n, e) {
1890
+ var t = "/app/" + n, r = "?protocol=" + _.PROTOCOL + "&client=js&version=" + _.VERSION + (e ? "&" + e : "");
1891
+ return t + r;
1892
+ }
1893
+ var en = {
1894
+ getInitial: function(n, e) {
1895
+ var t = (e.httpPath || "") + ve(n, "flash=false");
1896
+ return me("ws", e, t);
1897
+ }
1898
+ }, tn = {
1899
+ getInitial: function(n, e) {
1900
+ var t = (e.httpPath || "/pusher") + ve(n);
1901
+ return me("http", e, t);
1902
+ }
1903
+ }, nn = {
1904
+ getInitial: function(n, e) {
1905
+ return me("http", e, e.httpPath || "/pusher");
1906
+ },
1907
+ getPath: function(n, e) {
1908
+ return ve(n);
1909
+ }
1910
+ };
1911
+ class rn {
1912
+ constructor() {
1913
+ this._callbacks = {};
1914
+ }
1915
+ get(e) {
1916
+ return this._callbacks[be(e)];
1917
+ }
1918
+ add(e, t, r) {
1919
+ var s = be(e);
1920
+ this._callbacks[s] = this._callbacks[s] || [], this._callbacks[s].push({
1921
+ fn: t,
1922
+ context: r
1923
+ });
1924
+ }
1925
+ remove(e, t, r) {
1926
+ if (!e && !t && !r) {
1927
+ this._callbacks = {};
1928
+ return;
1929
+ }
1930
+ var s = e ? [be(e)] : He(this._callbacks);
1931
+ t || r ? this.removeCallback(s, t, r) : this.removeAllCallbacks(s);
1932
+ }
1933
+ removeCallback(e, t, r) {
1934
+ ne(e, function(s) {
1935
+ this._callbacks[s] = We(this._callbacks[s] || [], function(a) {
1936
+ return t && t !== a.fn || r && r !== a.context;
1937
+ }), this._callbacks[s].length === 0 && delete this._callbacks[s];
1938
+ }, this);
1939
+ }
1940
+ removeAllCallbacks(e) {
1941
+ ne(e, function(t) {
1942
+ delete this._callbacks[t];
1943
+ }, this);
1944
+ }
1945
+ }
1946
+ function be(n) {
1947
+ return "_" + n;
1948
+ }
1949
+ class $ {
1950
+ constructor(e) {
1951
+ this.callbacks = new rn(), this.global_callbacks = [], this.failThrough = e;
1952
+ }
1953
+ bind(e, t, r) {
1954
+ return this.callbacks.add(e, t, r), this;
1955
+ }
1956
+ bind_global(e) {
1957
+ return this.global_callbacks.push(e), this;
1958
+ }
1959
+ unbind(e, t, r) {
1960
+ return this.callbacks.remove(e, t, r), this;
1961
+ }
1962
+ unbind_global(e) {
1963
+ return e ? (this.global_callbacks = We(this.global_callbacks || [], (t) => t !== e), this) : (this.global_callbacks = [], this);
1964
+ }
1965
+ unbind_all() {
1966
+ return this.unbind(), this.unbind_global(), this;
1967
+ }
1968
+ emit(e, t, r) {
1969
+ for (var s = 0; s < this.global_callbacks.length; s++)
1970
+ this.global_callbacks[s](e, t);
1971
+ var a = this.callbacks.get(e), u = [];
1972
+ if (r ? u.push(t, r) : t && u.push(t), a && a.length > 0)
1973
+ for (var s = 0; s < a.length; s++)
1974
+ a[s].fn.apply(a[s].context || window, u);
1975
+ else this.failThrough && this.failThrough(e, t);
1976
+ return this;
1977
+ }
1978
+ }
1979
+ class sn extends $ {
1980
+ constructor(e, t, r, s, a) {
1981
+ super(), this.initialize = b.transportConnectionInitializer, this.hooks = e, this.name = t, this.priority = r, this.key = s, this.options = a, this.state = "new", this.timeline = a.timeline, this.activityTimeout = a.activityTimeout, this.id = this.timeline.generateUniqueID();
1982
+ }
1983
+ handlesActivityChecks() {
1984
+ return !!this.hooks.handlesActivityChecks;
1985
+ }
1986
+ supportsPing() {
1987
+ return !!this.hooks.supportsPing;
1988
+ }
1989
+ connect() {
1990
+ if (this.socket || this.state !== "initialized")
1991
+ return !1;
1992
+ var e = this.hooks.urls.getInitial(this.key, this.options);
1993
+ try {
1994
+ this.socket = this.hooks.getSocket(e, this.options);
1995
+ } catch (t) {
1996
+ return U.defer(() => {
1997
+ this.onError(t), this.changeState("closed");
1998
+ }), !1;
1999
+ }
2000
+ return this.bindListeners(), R.debug("Connecting", { transport: this.name, url: e }), this.changeState("connecting"), !0;
2001
+ }
2002
+ close() {
2003
+ return this.socket ? (this.socket.close(), !0) : !1;
2004
+ }
2005
+ send(e) {
2006
+ return this.state === "open" ? (U.defer(() => {
2007
+ this.socket && this.socket.send(e);
2008
+ }), !0) : !1;
2009
+ }
2010
+ ping() {
2011
+ this.state === "open" && this.supportsPing() && this.socket.ping();
2012
+ }
2013
+ onOpen() {
2014
+ this.hooks.beforeOpen && this.hooks.beforeOpen(this.socket, this.hooks.urls.getPath(this.key, this.options)), this.changeState("open"), this.socket.onopen = void 0;
2015
+ }
2016
+ onError(e) {
2017
+ this.emit("error", { type: "WebSocketError", error: e }), this.timeline.error(this.buildTimelineMessage({ error: e.toString() }));
2018
+ }
2019
+ onClose(e) {
2020
+ e ? this.changeState("closed", {
2021
+ code: e.code,
2022
+ reason: e.reason,
2023
+ wasClean: e.wasClean
2024
+ }) : this.changeState("closed"), this.unbindListeners(), this.socket = void 0;
2025
+ }
2026
+ onMessage(e) {
2027
+ this.emit("message", e);
2028
+ }
2029
+ onActivity() {
2030
+ this.emit("activity");
2031
+ }
2032
+ bindListeners() {
2033
+ this.socket.onopen = () => {
2034
+ this.onOpen();
2035
+ }, this.socket.onerror = (e) => {
2036
+ this.onError(e);
2037
+ }, this.socket.onclose = (e) => {
2038
+ this.onClose(e);
2039
+ }, this.socket.onmessage = (e) => {
2040
+ this.onMessage(e);
2041
+ }, this.supportsPing() && (this.socket.onactivity = () => {
2042
+ this.onActivity();
2043
+ });
2044
+ }
2045
+ unbindListeners() {
2046
+ this.socket && (this.socket.onopen = void 0, this.socket.onerror = void 0, this.socket.onclose = void 0, this.socket.onmessage = void 0, this.supportsPing() && (this.socket.onactivity = void 0));
2047
+ }
2048
+ changeState(e, t) {
2049
+ this.state = e, this.timeline.info(this.buildTimelineMessage({
2050
+ state: e,
2051
+ params: t
2052
+ })), this.emit(e, t);
2053
+ }
2054
+ buildTimelineMessage(e) {
2055
+ return M({ cid: this.id }, e);
2056
+ }
2057
+ }
2058
+ class Z {
2059
+ constructor(e) {
2060
+ this.hooks = e;
2061
+ }
2062
+ isSupported(e) {
2063
+ return this.hooks.isSupported(e);
2064
+ }
2065
+ createConnection(e, t, r, s) {
2066
+ return new sn(this.hooks, e, t, r, s);
2067
+ }
2068
+ }
2069
+ var on = new Z({
2070
+ urls: en,
2071
+ handlesActivityChecks: !1,
2072
+ supportsPing: !1,
2073
+ isInitialized: function() {
2074
+ return !!b.getWebSocketAPI();
2075
+ },
2076
+ isSupported: function() {
2077
+ return !!b.getWebSocketAPI();
2078
+ },
2079
+ getSocket: function(n) {
2080
+ return b.createWebSocket(n);
2081
+ }
2082
+ }), $e = {
2083
+ urls: tn,
2084
+ handlesActivityChecks: !1,
2085
+ supportsPing: !0,
2086
+ isInitialized: function() {
2087
+ return !0;
2088
+ }
2089
+ }, Xe = M({
2090
+ getSocket: function(n) {
2091
+ return b.HTTPFactory.createStreamingSocket(n);
2092
+ }
2093
+ }, $e), Ve = M({
2094
+ getSocket: function(n) {
2095
+ return b.HTTPFactory.createPollingSocket(n);
2096
+ }
2097
+ }, $e), Je = {
2098
+ isSupported: function() {
2099
+ return b.isXHRSupported();
2100
+ }
2101
+ }, an = new Z(M({}, Xe, Je)), cn = new Z(M({}, Ve, Je)), hn = {
2102
+ ws: on,
2103
+ xhr_streaming: an,
2104
+ xhr_polling: cn
2105
+ };
2106
+ const ce = hn;
2107
+ var un = new Z({
2108
+ file: "sockjs",
2109
+ urls: nn,
2110
+ handlesActivityChecks: !0,
2111
+ supportsPing: !1,
2112
+ isSupported: function() {
2113
+ return !0;
2114
+ },
2115
+ isInitialized: function() {
2116
+ return window.SockJS !== void 0;
2117
+ },
2118
+ getSocket: function(n, e) {
2119
+ return new window.SockJS(n, null, {
2120
+ js_path: j.getPath("sockjs", {
2121
+ useTLS: e.useTLS
2122
+ }),
2123
+ ignore_null_origin: e.ignoreNullOrigin
2124
+ });
2125
+ },
2126
+ beforeOpen: function(n, e) {
2127
+ n.send(JSON.stringify({
2128
+ path: e
2129
+ }));
2130
+ }
2131
+ }), Ge = {
2132
+ isSupported: function(n) {
2133
+ var e = b.isXDRSupported(n.useTLS);
2134
+ return e;
2135
+ }
2136
+ }, ln = new Z(M({}, Xe, Ge)), dn = new Z(M({}, Ve, Ge));
2137
+ ce.xdr_streaming = ln, ce.xdr_polling = dn, ce.sockjs = un;
2138
+ const pn = ce;
2139
+ class fn extends $ {
2140
+ constructor() {
2141
+ super();
2142
+ var e = this;
2143
+ window.addEventListener !== void 0 && (window.addEventListener("online", function() {
2144
+ e.emit("online");
2145
+ }, !1), window.addEventListener("offline", function() {
2146
+ e.emit("offline");
2147
+ }, !1));
2148
+ }
2149
+ isOnline() {
2150
+ return window.navigator.onLine === void 0 ? !0 : window.navigator.onLine;
2151
+ }
2152
+ }
2153
+ var gn = new fn();
2154
+ class mn {
2155
+ constructor(e, t, r) {
2156
+ this.manager = e, this.transport = t, this.minPingDelay = r.minPingDelay, this.maxPingDelay = r.maxPingDelay, this.pingDelay = void 0;
2157
+ }
2158
+ createConnection(e, t, r, s) {
2159
+ s = M({}, s, {
2160
+ activityTimeout: this.pingDelay
2161
+ });
2162
+ var a = this.transport.createConnection(e, t, r, s), u = null, p = function() {
2163
+ a.unbind("open", p), a.bind("closed", v), u = U.now();
2164
+ }, v = (E) => {
2165
+ if (a.unbind("closed", v), E.code === 1002 || E.code === 1003)
2166
+ this.manager.reportDeath();
2167
+ else if (!E.wasClean && u) {
2168
+ var x = U.now() - u;
2169
+ x < 2 * this.maxPingDelay && (this.manager.reportDeath(), this.pingDelay = Math.max(x / 2, this.minPingDelay));
2170
+ }
2171
+ };
2172
+ return a.bind("open", p), a;
2173
+ }
2174
+ isSupported(e) {
2175
+ return this.manager.isAlive() && this.transport.isSupported(e);
2176
+ }
2177
+ }
2178
+ const Ke = {
2179
+ decodeMessage: function(n) {
2180
+ try {
2181
+ var e = JSON.parse(n.data), t = e.data;
2182
+ if (typeof t == "string")
2183
+ try {
2184
+ t = JSON.parse(e.data);
2185
+ } catch {
2186
+ }
2187
+ var r = {
2188
+ event: e.event,
2189
+ channel: e.channel,
2190
+ data: t
2191
+ };
2192
+ return e.user_id && (r.user_id = e.user_id), r;
2193
+ } catch (s) {
2194
+ throw { type: "MessageParseError", error: s, data: n.data };
2195
+ }
2196
+ },
2197
+ encodeMessage: function(n) {
2198
+ return JSON.stringify(n);
2199
+ },
2200
+ processHandshake: function(n) {
2201
+ var e = Ke.decodeMessage(n);
2202
+ if (e.event === "pusher:connection_established") {
2203
+ if (!e.data.activity_timeout)
2204
+ throw "No activity timeout specified in handshake";
2205
+ return {
2206
+ action: "connected",
2207
+ id: e.data.socket_id,
2208
+ activityTimeout: e.data.activity_timeout * 1e3
2209
+ };
2210
+ } else {
2211
+ if (e.event === "pusher:error")
2212
+ return {
2213
+ action: this.getCloseAction(e.data),
2214
+ error: this.getCloseError(e.data)
2215
+ };
2216
+ throw "Invalid handshake";
2217
+ }
2218
+ },
2219
+ getCloseAction: function(n) {
2220
+ return n.code < 4e3 ? n.code >= 1002 && n.code <= 1004 ? "backoff" : null : n.code === 4e3 ? "tls_only" : n.code < 4100 ? "refused" : n.code < 4200 ? "backoff" : n.code < 4300 ? "retry" : "refused";
2221
+ },
2222
+ getCloseError: function(n) {
2223
+ return n.code !== 1e3 && n.code !== 1001 ? {
2224
+ type: "PusherError",
2225
+ data: {
2226
+ code: n.code,
2227
+ message: n.reason || n.message
2228
+ }
2229
+ } : null;
2230
+ }
2231
+ }, K = Ke;
2232
+ class vn extends $ {
2233
+ constructor(e, t) {
2234
+ super(), this.id = e, this.transport = t, this.activityTimeout = t.activityTimeout, this.bindListeners();
2235
+ }
2236
+ handlesActivityChecks() {
2237
+ return this.transport.handlesActivityChecks();
2238
+ }
2239
+ send(e) {
2240
+ return this.transport.send(e);
2241
+ }
2242
+ send_event(e, t, r) {
2243
+ var s = { event: e, data: t };
2244
+ return r && (s.channel = r), R.debug("Event sent", s), this.send(K.encodeMessage(s));
2245
+ }
2246
+ ping() {
2247
+ this.transport.supportsPing() ? this.transport.ping() : this.send_event("pusher:ping", {});
2248
+ }
2249
+ close() {
2250
+ this.transport.close();
2251
+ }
2252
+ bindListeners() {
2253
+ var e = {
2254
+ message: (r) => {
2255
+ var s;
2256
+ try {
2257
+ s = K.decodeMessage(r);
2258
+ } catch (a) {
2259
+ this.emit("error", {
2260
+ type: "MessageParseError",
2261
+ error: a,
2262
+ data: r.data
2263
+ });
2264
+ }
2265
+ if (s !== void 0) {
2266
+ switch (R.debug("Event recd", s), s.event) {
2267
+ case "pusher:error":
2268
+ this.emit("error", {
2269
+ type: "PusherError",
2270
+ data: s.data
2271
+ });
2272
+ break;
2273
+ case "pusher:ping":
2274
+ this.emit("ping");
2275
+ break;
2276
+ case "pusher:pong":
2277
+ this.emit("pong");
2278
+ break;
2279
+ }
2280
+ this.emit("message", s);
2281
+ }
2282
+ },
2283
+ activity: () => {
2284
+ this.emit("activity");
2285
+ },
2286
+ error: (r) => {
2287
+ this.emit("error", r);
2288
+ },
2289
+ closed: (r) => {
2290
+ t(), r && r.code && this.handleCloseEvent(r), this.transport = null, this.emit("closed");
2291
+ }
2292
+ }, t = () => {
2293
+ B(e, (r, s) => {
2294
+ this.transport.unbind(s, r);
2295
+ });
2296
+ };
2297
+ B(e, (r, s) => {
2298
+ this.transport.bind(s, r);
2299
+ });
2300
+ }
2301
+ handleCloseEvent(e) {
2302
+ var t = K.getCloseAction(e), r = K.getCloseError(e);
2303
+ r && this.emit("error", r), t && this.emit(t, { action: t, error: r });
2304
+ }
2305
+ }
2306
+ class bn {
2307
+ constructor(e, t) {
2308
+ this.transport = e, this.callback = t, this.bindListeners();
2309
+ }
2310
+ close() {
2311
+ this.unbindListeners(), this.transport.close();
2312
+ }
2313
+ bindListeners() {
2314
+ this.onMessage = (e) => {
2315
+ this.unbindListeners();
2316
+ var t;
2317
+ try {
2318
+ t = K.processHandshake(e);
2319
+ } catch (r) {
2320
+ this.finish("error", { error: r }), this.transport.close();
2321
+ return;
2322
+ }
2323
+ t.action === "connected" ? this.finish("connected", {
2324
+ connection: new vn(t.id, this.transport),
2325
+ activityTimeout: t.activityTimeout
2326
+ }) : (this.finish(t.action, { error: t.error }), this.transport.close());
2327
+ }, this.onClosed = (e) => {
2328
+ this.unbindListeners();
2329
+ var t = K.getCloseAction(e) || "backoff", r = K.getCloseError(e);
2330
+ this.finish(t, { error: r });
2331
+ }, this.transport.bind("message", this.onMessage), this.transport.bind("closed", this.onClosed);
2332
+ }
2333
+ unbindListeners() {
2334
+ this.transport.unbind("message", this.onMessage), this.transport.unbind("closed", this.onClosed);
2335
+ }
2336
+ finish(e, t) {
2337
+ this.callback(M({ transport: this.transport, action: e }, t));
2338
+ }
2339
+ }
2340
+ class yn {
2341
+ constructor(e, t) {
2342
+ this.timeline = e, this.options = t || {};
2343
+ }
2344
+ send(e, t) {
2345
+ this.timeline.isEmpty() || this.timeline.send(b.TimelineTransport.getAgent(this, e), t);
2346
+ }
2347
+ }
2348
+ class ye extends $ {
2349
+ constructor(e, t) {
2350
+ super(function(r, s) {
2351
+ R.debug("No callbacks on " + e + " for " + r);
2352
+ }), this.name = e, this.pusher = t, this.subscribed = !1, this.subscriptionPending = !1, this.subscriptionCancelled = !1;
2353
+ }
2354
+ authorize(e, t) {
2355
+ return t(null, { auth: "" });
2356
+ }
2357
+ trigger(e, t) {
2358
+ if (e.indexOf("client-") !== 0)
2359
+ throw new d("Event '" + e + "' does not start with 'client-'");
2360
+ if (!this.subscribed) {
2361
+ var r = T.buildLogSuffix("triggeringClientEvents");
2362
+ R.warn(`Client event triggered before channel 'subscription_succeeded' event . ${r}`);
2363
+ }
2364
+ return this.pusher.send_event(e, t, this.name);
2365
+ }
2366
+ disconnect() {
2367
+ this.subscribed = !1, this.subscriptionPending = !1;
2368
+ }
2369
+ handleEvent(e) {
2370
+ var t = e.event, r = e.data;
2371
+ if (t === "pusher_internal:subscription_succeeded")
2372
+ this.handleSubscriptionSucceededEvent(e);
2373
+ else if (t === "pusher_internal:subscription_count")
2374
+ this.handleSubscriptionCountEvent(e);
2375
+ else if (t.indexOf("pusher_internal:") !== 0) {
2376
+ var s = {};
2377
+ this.emit(t, r, s);
2378
+ }
2379
+ }
2380
+ handleSubscriptionSucceededEvent(e) {
2381
+ this.subscriptionPending = !1, this.subscribed = !0, this.subscriptionCancelled ? this.pusher.unsubscribe(this.name) : this.emit("pusher:subscription_succeeded", e.data);
2382
+ }
2383
+ handleSubscriptionCountEvent(e) {
2384
+ e.data.subscription_count && (this.subscriptionCount = e.data.subscription_count), this.emit("pusher:subscription_count", e.data);
2385
+ }
2386
+ subscribe() {
2387
+ this.subscribed || (this.subscriptionPending = !0, this.subscriptionCancelled = !1, this.authorize(this.pusher.connection.socket_id, (e, t) => {
2388
+ e ? (this.subscriptionPending = !1, R.error(e.toString()), this.emit("pusher:subscription_error", Object.assign({}, {
2389
+ type: "AuthError",
2390
+ error: e.message
2391
+ }, e instanceof H ? { status: e.status } : {}))) : this.pusher.send_event("pusher:subscribe", {
2392
+ auth: t.auth,
2393
+ channel_data: t.channel_data,
2394
+ channel: this.name
2395
+ });
2396
+ }));
2397
+ }
2398
+ unsubscribe() {
2399
+ this.subscribed = !1, this.pusher.send_event("pusher:unsubscribe", {
2400
+ channel: this.name
2401
+ });
2402
+ }
2403
+ cancelSubscription() {
2404
+ this.subscriptionCancelled = !0;
2405
+ }
2406
+ reinstateSubscription() {
2407
+ this.subscriptionCancelled = !1;
2408
+ }
2409
+ }
2410
+ class we extends ye {
2411
+ authorize(e, t) {
2412
+ return this.pusher.config.channelAuthorizer({
2413
+ channelName: this.name,
2414
+ socketId: e
2415
+ }, t);
2416
+ }
2417
+ }
2418
+ class wn {
2419
+ constructor() {
2420
+ this.reset();
2421
+ }
2422
+ get(e) {
2423
+ return Object.prototype.hasOwnProperty.call(this.members, e) ? {
2424
+ id: e,
2425
+ info: this.members[e]
2426
+ } : null;
2427
+ }
2428
+ each(e) {
2429
+ B(this.members, (t, r) => {
2430
+ e(this.get(r));
2431
+ });
2432
+ }
2433
+ setMyID(e) {
2434
+ this.myID = e;
2435
+ }
2436
+ onSubscription(e) {
2437
+ this.members = e.presence.hash, this.count = e.presence.count, this.me = this.get(this.myID);
2438
+ }
2439
+ addMember(e) {
2440
+ return this.get(e.user_id) === null && this.count++, this.members[e.user_id] = e.user_info, this.get(e.user_id);
2441
+ }
2442
+ removeMember(e) {
2443
+ var t = this.get(e.user_id);
2444
+ return t && (delete this.members[e.user_id], this.count--), t;
2445
+ }
2446
+ reset() {
2447
+ this.members = {}, this.count = 0, this.myID = null, this.me = null;
2448
+ }
2449
+ }
2450
+ var Cn = function(n, e, t, r) {
2451
+ function s(a) {
2452
+ return a instanceof t ? a : new t(function(u) {
2453
+ u(a);
2454
+ });
2455
+ }
2456
+ return new (t || (t = Promise))(function(a, u) {
2457
+ function p(x) {
2458
+ try {
2459
+ E(r.next(x));
2460
+ } catch (I) {
2461
+ u(I);
2462
+ }
2463
+ }
2464
+ function v(x) {
2465
+ try {
2466
+ E(r.throw(x));
2467
+ } catch (I) {
2468
+ u(I);
2469
+ }
2470
+ }
2471
+ function E(x) {
2472
+ x.done ? a(x.value) : s(x.value).then(p, v);
2473
+ }
2474
+ E((r = r.apply(n, e || [])).next());
2475
+ });
2476
+ };
2477
+ class Sn extends we {
2478
+ constructor(e, t) {
2479
+ super(e, t), this.members = new wn();
2480
+ }
2481
+ authorize(e, t) {
2482
+ super.authorize(e, (r, s) => Cn(this, void 0, void 0, function* () {
2483
+ if (!r)
2484
+ if (s = s, s.channel_data != null) {
2485
+ var a = JSON.parse(s.channel_data);
2486
+ this.members.setMyID(a.user_id);
2487
+ } else if (yield this.pusher.user.signinDonePromise, this.pusher.user.user_data != null)
2488
+ this.members.setMyID(this.pusher.user.user_data.id);
2489
+ else {
2490
+ let u = T.buildLogSuffix("authorizationEndpoint");
2491
+ R.error(`Invalid auth response for channel '${this.name}', expected 'channel_data' field. ${u}, or the user should be signed in.`), t("Invalid auth response");
2492
+ return;
2493
+ }
2494
+ t(r, s);
2495
+ }));
2496
+ }
2497
+ handleEvent(e) {
2498
+ var t = e.event;
2499
+ if (t.indexOf("pusher_internal:") === 0)
2500
+ this.handleInternalEvent(e);
2501
+ else {
2502
+ var r = e.data, s = {};
2503
+ e.user_id && (s.user_id = e.user_id), this.emit(t, r, s);
2504
+ }
2505
+ }
2506
+ handleInternalEvent(e) {
2507
+ var t = e.event, r = e.data;
2508
+ switch (t) {
2509
+ case "pusher_internal:subscription_succeeded":
2510
+ this.handleSubscriptionSucceededEvent(e);
2511
+ break;
2512
+ case "pusher_internal:subscription_count":
2513
+ this.handleSubscriptionCountEvent(e);
2514
+ break;
2515
+ case "pusher_internal:member_added":
2516
+ var s = this.members.addMember(r);
2517
+ this.emit("pusher:member_added", s);
2518
+ break;
2519
+ case "pusher_internal:member_removed":
2520
+ var a = this.members.removeMember(r);
2521
+ a && this.emit("pusher:member_removed", a);
2522
+ break;
2523
+ }
2524
+ }
2525
+ handleSubscriptionSucceededEvent(e) {
2526
+ this.subscriptionPending = !1, this.subscribed = !0, this.subscriptionCancelled ? this.pusher.unsubscribe(this.name) : (this.members.onSubscription(e.data), this.emit("pusher:subscription_succeeded", this.members));
2527
+ }
2528
+ disconnect() {
2529
+ this.members.reset(), super.disconnect();
2530
+ }
2531
+ }
2532
+ var _n = m(978), Ce = m(594);
2533
+ class Tn extends we {
2534
+ constructor(e, t, r) {
2535
+ super(e, t), this.key = null, this.nacl = r;
2536
+ }
2537
+ authorize(e, t) {
2538
+ super.authorize(e, (r, s) => {
2539
+ if (r) {
2540
+ t(r, s);
2541
+ return;
2542
+ }
2543
+ let a = s.shared_secret;
2544
+ if (!a) {
2545
+ t(new Error(`No shared_secret key in auth payload for encrypted channel: ${this.name}`), null);
2546
+ return;
2547
+ }
2548
+ this.key = (0, Ce.decode)(a), delete s.shared_secret, t(null, s);
2549
+ });
2550
+ }
2551
+ trigger(e, t) {
2552
+ throw new z("Client events are not currently supported for encrypted channels");
2553
+ }
2554
+ handleEvent(e) {
2555
+ var t = e.event, r = e.data;
2556
+ if (t.indexOf("pusher_internal:") === 0 || t.indexOf("pusher:") === 0) {
2557
+ super.handleEvent(e);
2558
+ return;
2559
+ }
2560
+ this.handleEncryptedEvent(t, r);
2561
+ }
2562
+ handleEncryptedEvent(e, t) {
2563
+ if (!this.key) {
2564
+ R.debug("Received encrypted event before key has been retrieved from the authEndpoint");
2565
+ return;
2566
+ }
2567
+ if (!t.ciphertext || !t.nonce) {
2568
+ R.error("Unexpected format for encrypted event, expected object with `ciphertext` and `nonce` fields, got: " + t);
2569
+ return;
2570
+ }
2571
+ let r = (0, Ce.decode)(t.ciphertext);
2572
+ if (r.length < this.nacl.secretbox.overheadLength) {
2573
+ R.error(`Expected encrypted event ciphertext length to be ${this.nacl.secretbox.overheadLength}, got: ${r.length}`);
2574
+ return;
2575
+ }
2576
+ let s = (0, Ce.decode)(t.nonce);
2577
+ if (s.length < this.nacl.secretbox.nonceLength) {
2578
+ R.error(`Expected encrypted event nonce length to be ${this.nacl.secretbox.nonceLength}, got: ${s.length}`);
2579
+ return;
2580
+ }
2581
+ let a = this.nacl.secretbox.open(r, s, this.key);
2582
+ if (a === null) {
2583
+ R.debug("Failed to decrypt an event, probably because it was encrypted with a different key. Fetching a new key from the authEndpoint..."), this.authorize(this.pusher.connection.socket_id, (u, p) => {
2584
+ if (u) {
2585
+ R.error(`Failed to make a request to the authEndpoint: ${p}. Unable to fetch new key, so dropping encrypted event`);
2586
+ return;
2587
+ }
2588
+ if (a = this.nacl.secretbox.open(r, s, this.key), a === null) {
2589
+ R.error("Failed to decrypt event with new key. Dropping encrypted event");
2590
+ return;
2591
+ }
2592
+ this.emit(e, this.getDataToEmit(a));
2593
+ });
2594
+ return;
2595
+ }
2596
+ this.emit(e, this.getDataToEmit(a));
2597
+ }
2598
+ getDataToEmit(e) {
2599
+ let t = (0, _n.D4)(e);
2600
+ try {
2601
+ return JSON.parse(t);
2602
+ } catch {
2603
+ return t;
2604
+ }
2605
+ }
2606
+ }
2607
+ class kn extends $ {
2608
+ constructor(e, t) {
2609
+ super(), this.state = "initialized", this.connection = null, this.key = e, this.options = t, this.timeline = this.options.timeline, this.usingTLS = this.options.useTLS, this.errorCallbacks = this.buildErrorCallbacks(), this.connectionCallbacks = this.buildConnectionCallbacks(this.errorCallbacks), this.handshakeCallbacks = this.buildHandshakeCallbacks(this.errorCallbacks);
2610
+ var r = b.getNetwork();
2611
+ r.bind("online", () => {
2612
+ this.timeline.info({ netinfo: "online" }), (this.state === "connecting" || this.state === "unavailable") && this.retryIn(0);
2613
+ }), r.bind("offline", () => {
2614
+ this.timeline.info({ netinfo: "offline" }), this.connection && this.sendActivityCheck();
2615
+ }), this.updateStrategy();
2616
+ }
2617
+ switchCluster(e) {
2618
+ this.key = e, this.updateStrategy(), this.retryIn(0);
2619
+ }
2620
+ connect() {
2621
+ if (!(this.connection || this.runner)) {
2622
+ if (!this.strategy.isSupported()) {
2623
+ this.updateState("failed");
2624
+ return;
2625
+ }
2626
+ this.updateState("connecting"), this.startConnecting(), this.setUnavailableTimer();
2627
+ }
2628
+ }
2629
+ send(e) {
2630
+ return this.connection ? this.connection.send(e) : !1;
2631
+ }
2632
+ send_event(e, t, r) {
2633
+ return this.connection ? this.connection.send_event(e, t, r) : !1;
2634
+ }
2635
+ disconnect() {
2636
+ this.disconnectInternally(), this.updateState("disconnected");
2637
+ }
2638
+ isUsingTLS() {
2639
+ return this.usingTLS;
2640
+ }
2641
+ startConnecting() {
2642
+ var e = (t, r) => {
2643
+ t ? this.runner = this.strategy.connect(0, e) : r.action === "error" ? (this.emit("error", {
2644
+ type: "HandshakeError",
2645
+ error: r.error
2646
+ }), this.timeline.error({ handshakeError: r.error })) : (this.abortConnecting(), this.handshakeCallbacks[r.action](r));
2647
+ };
2648
+ this.runner = this.strategy.connect(0, e);
2649
+ }
2650
+ abortConnecting() {
2651
+ this.runner && (this.runner.abort(), this.runner = null);
2652
+ }
2653
+ disconnectInternally() {
2654
+ if (this.abortConnecting(), this.clearRetryTimer(), this.clearUnavailableTimer(), this.connection) {
2655
+ var e = this.abandonConnection();
2656
+ e.close();
2657
+ }
2658
+ }
2659
+ updateStrategy() {
2660
+ this.strategy = this.options.getStrategy({
2661
+ key: this.key,
2662
+ timeline: this.timeline,
2663
+ useTLS: this.usingTLS
2664
+ });
2665
+ }
2666
+ retryIn(e) {
2667
+ this.timeline.info({ action: "retry", delay: e }), e > 0 && this.emit("connecting_in", Math.round(e / 1e3)), this.retryTimer = new G(e || 0, () => {
2668
+ this.disconnectInternally(), this.connect();
2669
+ });
2670
+ }
2671
+ clearRetryTimer() {
2672
+ this.retryTimer && (this.retryTimer.ensureAborted(), this.retryTimer = null);
2673
+ }
2674
+ setUnavailableTimer() {
2675
+ this.unavailableTimer = new G(this.options.unavailableTimeout, () => {
2676
+ this.updateState("unavailable");
2677
+ });
2678
+ }
2679
+ clearUnavailableTimer() {
2680
+ this.unavailableTimer && this.unavailableTimer.ensureAborted();
2681
+ }
2682
+ sendActivityCheck() {
2683
+ this.stopActivityCheck(), this.connection.ping(), this.activityTimer = new G(this.options.pongTimeout, () => {
2684
+ this.timeline.error({ pong_timed_out: this.options.pongTimeout }), this.retryIn(0);
2685
+ });
2686
+ }
2687
+ resetActivityCheck() {
2688
+ this.stopActivityCheck(), this.connection && !this.connection.handlesActivityChecks() && (this.activityTimer = new G(this.activityTimeout, () => {
2689
+ this.sendActivityCheck();
2690
+ }));
2691
+ }
2692
+ stopActivityCheck() {
2693
+ this.activityTimer && this.activityTimer.ensureAborted();
2694
+ }
2695
+ buildConnectionCallbacks(e) {
2696
+ return M({}, e, {
2697
+ message: (t) => {
2698
+ this.resetActivityCheck(), this.emit("message", t);
2699
+ },
2700
+ ping: () => {
2701
+ this.send_event("pusher:pong", {});
2702
+ },
2703
+ activity: () => {
2704
+ this.resetActivityCheck();
2705
+ },
2706
+ error: (t) => {
2707
+ this.emit("error", t);
2708
+ },
2709
+ closed: () => {
2710
+ this.abandonConnection(), this.shouldRetry() && this.retryIn(1e3);
2711
+ }
2712
+ });
2713
+ }
2714
+ buildHandshakeCallbacks(e) {
2715
+ return M({}, e, {
2716
+ connected: (t) => {
2717
+ this.activityTimeout = Math.min(this.options.activityTimeout, t.activityTimeout, t.connection.activityTimeout || 1 / 0), this.clearUnavailableTimer(), this.setConnection(t.connection), this.socket_id = this.connection.id, this.updateState("connected", { socket_id: this.socket_id });
2718
+ }
2719
+ });
2720
+ }
2721
+ buildErrorCallbacks() {
2722
+ let e = (t) => (r) => {
2723
+ r.error && this.emit("error", { type: "WebSocketError", error: r.error }), t(r);
2724
+ };
2725
+ return {
2726
+ tls_only: e(() => {
2727
+ this.usingTLS = !0, this.updateStrategy(), this.retryIn(0);
2728
+ }),
2729
+ refused: e(() => {
2730
+ this.disconnect();
2731
+ }),
2732
+ backoff: e(() => {
2733
+ this.retryIn(1e3);
2734
+ }),
2735
+ retry: e(() => {
2736
+ this.retryIn(0);
2737
+ })
2738
+ };
2739
+ }
2740
+ setConnection(e) {
2741
+ this.connection = e;
2742
+ for (var t in this.connectionCallbacks)
2743
+ this.connection.bind(t, this.connectionCallbacks[t]);
2744
+ this.resetActivityCheck();
2745
+ }
2746
+ abandonConnection() {
2747
+ if (this.connection) {
2748
+ this.stopActivityCheck();
2749
+ for (var e in this.connectionCallbacks)
2750
+ this.connection.unbind(e, this.connectionCallbacks[e]);
2751
+ var t = this.connection;
2752
+ return this.connection = null, t;
2753
+ }
2754
+ }
2755
+ updateState(e, t) {
2756
+ var r = this.state;
2757
+ if (this.state = e, r !== e) {
2758
+ var s = e;
2759
+ s === "connected" && (s += " with new socket ID " + t.socket_id), R.debug("State changed", r + " -> " + s), this.timeline.info({ state: e, params: t }), this.emit("state_change", { previous: r, current: e }), this.emit(e, t);
2760
+ }
2761
+ }
2762
+ shouldRetry() {
2763
+ return this.state === "connecting" || this.state === "connected";
2764
+ }
2765
+ }
2766
+ class En {
2767
+ constructor() {
2768
+ this.channels = {};
2769
+ }
2770
+ add(e, t) {
2771
+ return this.channels[e] || (this.channels[e] = xn(e, t)), this.channels[e];
2772
+ }
2773
+ all() {
2774
+ return zt(this.channels);
2775
+ }
2776
+ find(e) {
2777
+ return this.channels[e];
2778
+ }
2779
+ remove(e) {
2780
+ var t = this.channels[e];
2781
+ return delete this.channels[e], t;
2782
+ }
2783
+ disconnect() {
2784
+ B(this.channels, function(e) {
2785
+ e.disconnect();
2786
+ });
2787
+ }
2788
+ }
2789
+ function xn(n, e) {
2790
+ if (n.indexOf("private-encrypted-") === 0) {
2791
+ if (e.config.nacl)
2792
+ return X.createEncryptedChannel(n, e, e.config.nacl);
2793
+ let t = "Tried to subscribe to a private-encrypted- channel but no nacl implementation available", r = T.buildLogSuffix("encryptedChannelSupport");
2794
+ throw new z(`${t}. ${r}`);
2795
+ } else {
2796
+ if (n.indexOf("private-") === 0)
2797
+ return X.createPrivateChannel(n, e);
2798
+ if (n.indexOf("presence-") === 0)
2799
+ return X.createPresenceChannel(n, e);
2800
+ if (n.indexOf("#") === 0)
2801
+ throw new w('Cannot create a channel with name "' + n + '".');
2802
+ return X.createChannel(n, e);
2803
+ }
2804
+ }
2805
+ var An = {
2806
+ createChannels() {
2807
+ return new En();
2808
+ },
2809
+ createConnectionManager(n, e) {
2810
+ return new kn(n, e);
2811
+ },
2812
+ createChannel(n, e) {
2813
+ return new ye(n, e);
2814
+ },
2815
+ createPrivateChannel(n, e) {
2816
+ return new we(n, e);
2817
+ },
2818
+ createPresenceChannel(n, e) {
2819
+ return new Sn(n, e);
2820
+ },
2821
+ createEncryptedChannel(n, e, t) {
2822
+ return new Tn(n, e, t);
2823
+ },
2824
+ createTimelineSender(n, e) {
2825
+ return new yn(n, e);
2826
+ },
2827
+ createHandshake(n, e) {
2828
+ return new bn(n, e);
2829
+ },
2830
+ createAssistantToTheTransportManager(n, e, t) {
2831
+ return new mn(n, e, t);
2832
+ }
2833
+ };
2834
+ const X = An;
2835
+ class Qe {
2836
+ constructor(e) {
2837
+ this.options = e || {}, this.livesLeft = this.options.lives || 1 / 0;
2838
+ }
2839
+ getAssistant(e) {
2840
+ return X.createAssistantToTheTransportManager(this, e, {
2841
+ minPingDelay: this.options.minPingDelay,
2842
+ maxPingDelay: this.options.maxPingDelay
2843
+ });
2844
+ }
2845
+ isAlive() {
2846
+ return this.livesLeft > 0;
2847
+ }
2848
+ reportDeath() {
2849
+ this.livesLeft -= 1;
2850
+ }
2851
+ }
2852
+ class Q {
2853
+ constructor(e, t) {
2854
+ this.strategies = e, this.loop = !!t.loop, this.failFast = !!t.failFast, this.timeout = t.timeout, this.timeoutLimit = t.timeoutLimit;
2855
+ }
2856
+ isSupported() {
2857
+ return Be(this.strategies, U.method("isSupported"));
2858
+ }
2859
+ connect(e, t) {
2860
+ var r = this.strategies, s = 0, a = this.timeout, u = null, p = (v, E) => {
2861
+ E ? t(null, E) : (s = s + 1, this.loop && (s = s % r.length), s < r.length ? (a && (a = a * 2, this.timeoutLimit && (a = Math.min(a, this.timeoutLimit))), u = this.tryStrategy(r[s], e, { timeout: a, failFast: this.failFast }, p)) : t(!0));
2862
+ };
2863
+ return u = this.tryStrategy(r[s], e, { timeout: a, failFast: this.failFast }, p), {
2864
+ abort: function() {
2865
+ u.abort();
2866
+ },
2867
+ forceMinPriority: function(v) {
2868
+ e = v, u && u.forceMinPriority(v);
2869
+ }
2870
+ };
2871
+ }
2872
+ tryStrategy(e, t, r, s) {
2873
+ var a = null, u = null;
2874
+ return r.timeout > 0 && (a = new G(r.timeout, function() {
2875
+ u.abort(), s(!0);
2876
+ })), u = e.connect(t, function(p, v) {
2877
+ p && a && a.isRunning() && !r.failFast || (a && a.ensureAborted(), s(p, v));
2878
+ }), {
2879
+ abort: function() {
2880
+ a && a.ensureAborted(), u.abort();
2881
+ },
2882
+ forceMinPriority: function(p) {
2883
+ u.forceMinPriority(p);
2884
+ }
2885
+ };
2886
+ }
2887
+ }
2888
+ class Se {
2889
+ constructor(e) {
2890
+ this.strategies = e;
2891
+ }
2892
+ isSupported() {
2893
+ return Be(this.strategies, U.method("isSupported"));
2894
+ }
2895
+ connect(e, t) {
2896
+ return Pn(this.strategies, e, function(r, s) {
2897
+ return function(a, u) {
2898
+ if (s[r].error = a, a) {
2899
+ Rn(s) && t(!0);
2900
+ return;
2901
+ }
2902
+ ne(s, function(p) {
2903
+ p.forceMinPriority(u.transport.priority);
2904
+ }), t(null, u);
2905
+ };
2906
+ });
2907
+ }
2908
+ }
2909
+ function Pn(n, e, t) {
2910
+ var r = De(n, function(s, a, u, p) {
2911
+ return s.connect(e, t(a, p));
2912
+ });
2913
+ return {
2914
+ abort: function() {
2915
+ ne(r, Ln);
2916
+ },
2917
+ forceMinPriority: function(s) {
2918
+ ne(r, function(a) {
2919
+ a.forceMinPriority(s);
2920
+ });
2921
+ }
2922
+ };
2923
+ }
2924
+ function Rn(n) {
2925
+ return Wt(n, function(e) {
2926
+ return !!e.error;
2927
+ });
2928
+ }
2929
+ function Ln(n) {
2930
+ !n.error && !n.aborted && (n.abort(), n.aborted = !0);
2931
+ }
2932
+ class In {
2933
+ constructor(e, t, r) {
2934
+ this.strategy = e, this.transports = t, this.ttl = r.ttl || 18e5, this.usingTLS = r.useTLS, this.timeline = r.timeline;
2935
+ }
2936
+ isSupported() {
2937
+ return this.strategy.isSupported();
2938
+ }
2939
+ connect(e, t) {
2940
+ var r = this.usingTLS, s = On(r), a = s && s.cacheSkipCount ? s.cacheSkipCount : 0, u = [this.strategy];
2941
+ if (s && s.timestamp + this.ttl >= U.now()) {
2942
+ var p = this.transports[s.transport];
2943
+ p && (["ws", "wss"].includes(s.transport) || a > 3 ? (this.timeline.info({
2944
+ cached: !0,
2945
+ transport: s.transport,
2946
+ latency: s.latency
2947
+ }), u.push(new Q([p], {
2948
+ timeout: s.latency * 2 + 1e3,
2949
+ failFast: !0
2950
+ }))) : a++);
2951
+ }
2952
+ var v = U.now(), E = u.pop().connect(e, function x(I, de) {
2953
+ I ? (Ye(r), u.length > 0 ? (v = U.now(), E = u.pop().connect(e, x)) : t(I)) : (qn(r, de.transport.name, U.now() - v, a), t(null, de));
2954
+ });
2955
+ return {
2956
+ abort: function() {
2957
+ E.abort();
2958
+ },
2959
+ forceMinPriority: function(x) {
2960
+ e = x, E && E.forceMinPriority(x);
2961
+ }
2962
+ };
2963
+ }
2964
+ }
2965
+ function _e(n) {
2966
+ return "pusherTransport" + (n ? "TLS" : "NonTLS");
2967
+ }
2968
+ function On(n) {
2969
+ var e = b.getLocalStorage();
2970
+ if (e)
2971
+ try {
2972
+ var t = e[_e(n)];
2973
+ if (t)
2974
+ return JSON.parse(t);
2975
+ } catch {
2976
+ Ye(n);
2977
+ }
2978
+ return null;
2979
+ }
2980
+ function qn(n, e, t, r) {
2981
+ var s = b.getLocalStorage();
2982
+ if (s)
2983
+ try {
2984
+ s[_e(n)] = ae({
2985
+ timestamp: U.now(),
2986
+ transport: e,
2987
+ latency: t,
2988
+ cacheSkipCount: r
2989
+ });
2990
+ } catch {
2991
+ }
2992
+ }
2993
+ function Ye(n) {
2994
+ var e = b.getLocalStorage();
2995
+ if (e)
2996
+ try {
2997
+ delete e[_e(n)];
2998
+ } catch {
2999
+ }
3000
+ }
3001
+ class he {
3002
+ constructor(e, { delay: t }) {
3003
+ this.strategy = e, this.options = { delay: t };
3004
+ }
3005
+ isSupported() {
3006
+ return this.strategy.isSupported();
3007
+ }
3008
+ connect(e, t) {
3009
+ var r = this.strategy, s, a = new G(this.options.delay, function() {
3010
+ s = r.connect(e, t);
3011
+ });
3012
+ return {
3013
+ abort: function() {
3014
+ a.ensureAborted(), s && s.abort();
3015
+ },
3016
+ forceMinPriority: function(u) {
3017
+ e = u, s && s.forceMinPriority(u);
3018
+ }
3019
+ };
3020
+ }
3021
+ }
3022
+ class ie {
3023
+ constructor(e, t, r) {
3024
+ this.test = e, this.trueBranch = t, this.falseBranch = r;
3025
+ }
3026
+ isSupported() {
3027
+ var e = this.test() ? this.trueBranch : this.falseBranch;
3028
+ return e.isSupported();
3029
+ }
3030
+ connect(e, t) {
3031
+ var r = this.test() ? this.trueBranch : this.falseBranch;
3032
+ return r.connect(e, t);
3033
+ }
3034
+ }
3035
+ class Un {
3036
+ constructor(e) {
3037
+ this.strategy = e;
3038
+ }
3039
+ isSupported() {
3040
+ return this.strategy.isSupported();
3041
+ }
3042
+ connect(e, t) {
3043
+ var r = this.strategy.connect(e, function(s, a) {
3044
+ a && r.abort(), t(s, a);
3045
+ });
3046
+ return r;
3047
+ }
3048
+ }
3049
+ function re(n) {
3050
+ return function() {
3051
+ return n.isSupported();
3052
+ };
3053
+ }
3054
+ var jn = function(n, e, t) {
3055
+ var r = {};
3056
+ function s(lt, Oi, qi, Ui, ji) {
3057
+ var dt = t(n, lt, Oi, qi, Ui, ji);
3058
+ return r[lt] = dt, dt;
3059
+ }
3060
+ var a = Object.assign({}, e, {
3061
+ hostNonTLS: n.wsHost + ":" + n.wsPort,
3062
+ hostTLS: n.wsHost + ":" + n.wssPort,
3063
+ httpPath: n.wsPath
3064
+ }), u = Object.assign({}, a, {
3065
+ useTLS: !0
3066
+ }), p = Object.assign({}, e, {
3067
+ hostNonTLS: n.httpHost + ":" + n.httpPort,
3068
+ hostTLS: n.httpHost + ":" + n.httpsPort,
3069
+ httpPath: n.httpPath
3070
+ }), v = {
3071
+ loop: !0,
3072
+ timeout: 15e3,
3073
+ timeoutLimit: 6e4
3074
+ }, E = new Qe({
3075
+ minPingDelay: 1e4,
3076
+ maxPingDelay: n.activityTimeout
3077
+ }), x = new Qe({
3078
+ lives: 2,
3079
+ minPingDelay: 1e4,
3080
+ maxPingDelay: n.activityTimeout
3081
+ }), I = s("ws", "ws", 3, a, E), de = s("wss", "ws", 3, u, E), Ai = s("sockjs", "sockjs", 1, p), st = s("xhr_streaming", "xhr_streaming", 1, p, x), Pi = s("xdr_streaming", "xdr_streaming", 1, p, x), ot = s("xhr_polling", "xhr_polling", 1, p), Ri = s("xdr_polling", "xdr_polling", 1, p), at = new Q([I], v), Li = new Q([de], v), Ii = new Q([Ai], v), ct = new Q([
3082
+ new ie(re(st), st, Pi)
3083
+ ], v), ht = new Q([
3084
+ new ie(re(ot), ot, Ri)
3085
+ ], v), ut = new Q([
3086
+ new ie(re(ct), new Se([
3087
+ ct,
3088
+ new he(ht, { delay: 4e3 })
3089
+ ]), ht)
3090
+ ], v), Ee = new ie(re(ut), ut, Ii), xe;
3091
+ return e.useTLS ? xe = new Se([
3092
+ at,
3093
+ new he(Ee, { delay: 2e3 })
3094
+ ]) : xe = new Se([
3095
+ at,
3096
+ new he(Li, { delay: 2e3 }),
3097
+ new he(Ee, { delay: 5e3 })
3098
+ ]), new In(new Un(new ie(re(I), xe, Ee)), r, {
3099
+ ttl: 18e5,
3100
+ timeline: e.timeline,
3101
+ useTLS: e.useTLS
3102
+ });
3103
+ };
3104
+ const Nn = jn;
3105
+ function Mn() {
3106
+ var n = this;
3107
+ n.timeline.info(n.buildTimelineMessage({
3108
+ transport: n.name + (n.options.useTLS ? "s" : "")
3109
+ })), n.hooks.isInitialized() ? n.changeState("initialized") : n.hooks.file ? (n.changeState("initializing"), j.load(n.hooks.file, { useTLS: n.options.useTLS }, function(e, t) {
3110
+ n.hooks.isInitialized() ? (n.changeState("initialized"), t(!0)) : (e && n.onError(e), n.onClose(), t(!1));
3111
+ })) : n.onClose();
3112
+ }
3113
+ var zn = {
3114
+ getRequest: function(n) {
3115
+ var e = new window.XDomainRequest();
3116
+ return e.ontimeout = function() {
3117
+ n.emit("error", new P()), n.close();
3118
+ }, e.onerror = function(t) {
3119
+ n.emit("error", t), n.close();
3120
+ }, e.onprogress = function() {
3121
+ e.responseText && e.responseText.length > 0 && n.onChunk(200, e.responseText);
3122
+ }, e.onload = function() {
3123
+ e.responseText && e.responseText.length > 0 && n.onChunk(200, e.responseText), n.emit("finished", 200), n.close();
3124
+ }, e;
3125
+ },
3126
+ abortRequest: function(n) {
3127
+ n.ontimeout = n.onerror = n.onprogress = n.onload = null, n.abort();
3128
+ }
3129
+ };
3130
+ const Hn = zn, Dn = 256 * 1024;
3131
+ class Wn extends $ {
3132
+ constructor(e, t, r) {
3133
+ super(), this.hooks = e, this.method = t, this.url = r;
3134
+ }
3135
+ start(e) {
3136
+ this.position = 0, this.xhr = this.hooks.getRequest(this), this.unloader = () => {
3137
+ this.close();
3138
+ }, b.addUnloadListener(this.unloader), this.xhr.open(this.method, this.url, !0), this.xhr.setRequestHeader && this.xhr.setRequestHeader("Content-Type", "application/json"), this.xhr.send(e);
3139
+ }
3140
+ close() {
3141
+ this.unloader && (b.removeUnloadListener(this.unloader), this.unloader = null), this.xhr && (this.hooks.abortRequest(this.xhr), this.xhr = null);
3142
+ }
3143
+ onChunk(e, t) {
3144
+ for (; ; ) {
3145
+ var r = this.advanceBuffer(t);
3146
+ if (r)
3147
+ this.emit("chunk", { status: e, data: r });
3148
+ else
3149
+ break;
3150
+ }
3151
+ this.isBufferTooLong(t) && this.emit("buffer_too_long");
3152
+ }
3153
+ advanceBuffer(e) {
3154
+ var t = e.slice(this.position), r = t.indexOf(`
3155
+ `);
3156
+ return r !== -1 ? (this.position += r + 1, t.slice(0, r)) : null;
3157
+ }
3158
+ isBufferTooLong(e) {
3159
+ return this.position === e.length && e.length > Dn;
3160
+ }
3161
+ }
3162
+ var Te;
3163
+ (function(n) {
3164
+ n[n.CONNECTING = 0] = "CONNECTING", n[n.OPEN = 1] = "OPEN", n[n.CLOSED = 3] = "CLOSED";
3165
+ })(Te || (Te = {}));
3166
+ const Y = Te;
3167
+ var Fn = 1;
3168
+ class Bn {
3169
+ constructor(e, t) {
3170
+ this.hooks = e, this.session = et(1e3) + "/" + Jn(8), this.location = $n(t), this.readyState = Y.CONNECTING, this.openStream();
3171
+ }
3172
+ send(e) {
3173
+ return this.sendRaw(JSON.stringify([e]));
3174
+ }
3175
+ ping() {
3176
+ this.hooks.sendHeartbeat(this);
3177
+ }
3178
+ close(e, t) {
3179
+ this.onClose(e, t, !0);
3180
+ }
3181
+ sendRaw(e) {
3182
+ if (this.readyState === Y.OPEN)
3183
+ try {
3184
+ return b.createSocketRequest("POST", Ze(Xn(this.location, this.session))).start(e), !0;
3185
+ } catch {
3186
+ return !1;
3187
+ }
3188
+ else
3189
+ return !1;
3190
+ }
3191
+ reconnect() {
3192
+ this.closeStream(), this.openStream();
3193
+ }
3194
+ onClose(e, t, r) {
3195
+ this.closeStream(), this.readyState = Y.CLOSED, this.onclose && this.onclose({
3196
+ code: e,
3197
+ reason: t,
3198
+ wasClean: r
3199
+ });
3200
+ }
3201
+ onChunk(e) {
3202
+ if (e.status === 200) {
3203
+ this.readyState === Y.OPEN && this.onActivity();
3204
+ var t, r = e.data.slice(0, 1);
3205
+ switch (r) {
3206
+ case "o":
3207
+ t = JSON.parse(e.data.slice(1) || "{}"), this.onOpen(t);
3208
+ break;
3209
+ case "a":
3210
+ t = JSON.parse(e.data.slice(1) || "[]");
3211
+ for (var s = 0; s < t.length; s++)
3212
+ this.onEvent(t[s]);
3213
+ break;
3214
+ case "m":
3215
+ t = JSON.parse(e.data.slice(1) || "null"), this.onEvent(t);
3216
+ break;
3217
+ case "h":
3218
+ this.hooks.onHeartbeat(this);
3219
+ break;
3220
+ case "c":
3221
+ t = JSON.parse(e.data.slice(1) || "[]"), this.onClose(t[0], t[1], !0);
3222
+ break;
3223
+ }
3224
+ }
3225
+ }
3226
+ onOpen(e) {
3227
+ this.readyState === Y.CONNECTING ? (e && e.hostname && (this.location.base = Vn(this.location.base, e.hostname)), this.readyState = Y.OPEN, this.onopen && this.onopen()) : this.onClose(1006, "Server lost session", !0);
3228
+ }
3229
+ onEvent(e) {
3230
+ this.readyState === Y.OPEN && this.onmessage && this.onmessage({ data: e });
3231
+ }
3232
+ onActivity() {
3233
+ this.onactivity && this.onactivity();
3234
+ }
3235
+ onError(e) {
3236
+ this.onerror && this.onerror(e);
3237
+ }
3238
+ openStream() {
3239
+ this.stream = b.createSocketRequest("POST", Ze(this.hooks.getReceiveURL(this.location, this.session))), this.stream.bind("chunk", (e) => {
3240
+ this.onChunk(e);
3241
+ }), this.stream.bind("finished", (e) => {
3242
+ this.hooks.onFinished(this, e);
3243
+ }), this.stream.bind("buffer_too_long", () => {
3244
+ this.reconnect();
3245
+ });
3246
+ try {
3247
+ this.stream.start();
3248
+ } catch (e) {
3249
+ U.defer(() => {
3250
+ this.onError(e), this.onClose(1006, "Could not start streaming", !1);
3251
+ });
3252
+ }
3253
+ }
3254
+ closeStream() {
3255
+ this.stream && (this.stream.unbind_all(), this.stream.close(), this.stream = null);
3256
+ }
3257
+ }
3258
+ function $n(n) {
3259
+ var e = /([^\?]*)\/*(\??.*)/.exec(n);
3260
+ return {
3261
+ base: e[1],
3262
+ queryString: e[2]
3263
+ };
3264
+ }
3265
+ function Xn(n, e) {
3266
+ return n.base + "/" + e + "/xhr_send";
3267
+ }
3268
+ function Ze(n) {
3269
+ var e = n.indexOf("?") === -1 ? "?" : "&";
3270
+ return n + e + "t=" + +/* @__PURE__ */ new Date() + "&n=" + Fn++;
3271
+ }
3272
+ function Vn(n, e) {
3273
+ var t = /(https?:\/\/)([^\/:]+)((\/|:)?.*)/.exec(n);
3274
+ return t[1] + e + t[3];
3275
+ }
3276
+ function et(n) {
3277
+ return b.randomInt(n);
3278
+ }
3279
+ function Jn(n) {
3280
+ for (var e = [], t = 0; t < n; t++)
3281
+ e.push(et(32).toString(32));
3282
+ return e.join("");
3283
+ }
3284
+ const Gn = Bn;
3285
+ var Kn = {
3286
+ getReceiveURL: function(n, e) {
3287
+ return n.base + "/" + e + "/xhr_streaming" + n.queryString;
3288
+ },
3289
+ onHeartbeat: function(n) {
3290
+ n.sendRaw("[]");
3291
+ },
3292
+ sendHeartbeat: function(n) {
3293
+ n.sendRaw("[]");
3294
+ },
3295
+ onFinished: function(n, e) {
3296
+ n.onClose(1006, "Connection interrupted (" + e + ")", !1);
3297
+ }
3298
+ };
3299
+ const Qn = Kn;
3300
+ var Yn = {
3301
+ getReceiveURL: function(n, e) {
3302
+ return n.base + "/" + e + "/xhr" + n.queryString;
3303
+ },
3304
+ onHeartbeat: function() {
3305
+ },
3306
+ sendHeartbeat: function(n) {
3307
+ n.sendRaw("[]");
3308
+ },
3309
+ onFinished: function(n, e) {
3310
+ e === 200 ? n.reconnect() : n.onClose(1006, "Connection interrupted (" + e + ")", !1);
3311
+ }
3312
+ };
3313
+ const Zn = Yn;
3314
+ var ei = {
3315
+ getRequest: function(n) {
3316
+ var e = b.getXHRAPI(), t = new e();
3317
+ return t.onreadystatechange = t.onprogress = function() {
3318
+ switch (t.readyState) {
3319
+ case 3:
3320
+ t.responseText && t.responseText.length > 0 && n.onChunk(t.status, t.responseText);
3321
+ break;
3322
+ case 4:
3323
+ t.responseText && t.responseText.length > 0 && n.onChunk(t.status, t.responseText), n.emit("finished", t.status), n.close();
3324
+ break;
3325
+ }
3326
+ }, t;
3327
+ },
3328
+ abortRequest: function(n) {
3329
+ n.onreadystatechange = null, n.abort();
3330
+ }
3331
+ };
3332
+ const ti = ei;
3333
+ var ni = {
3334
+ createStreamingSocket(n) {
3335
+ return this.createSocket(Qn, n);
3336
+ },
3337
+ createPollingSocket(n) {
3338
+ return this.createSocket(Zn, n);
3339
+ },
3340
+ createSocket(n, e) {
3341
+ return new Gn(n, e);
3342
+ },
3343
+ createXHR(n, e) {
3344
+ return this.createRequest(ti, n, e);
3345
+ },
3346
+ createRequest(n, e, t) {
3347
+ return new Wn(n, e, t);
3348
+ }
3349
+ };
3350
+ const tt = ni;
3351
+ tt.createXDR = function(n, e) {
3352
+ return this.createRequest(Hn, n, e);
3353
+ };
3354
+ var ii = {
3355
+ nextAuthCallbackID: 1,
3356
+ auth_callbacks: {},
3357
+ ScriptReceivers: S,
3358
+ DependenciesReceivers: W,
3359
+ getDefaultStrategy: Nn,
3360
+ Transports: pn,
3361
+ transportConnectionInitializer: Mn,
3362
+ HTTPFactory: tt,
3363
+ TimelineTransport: Zt,
3364
+ getXHRAPI() {
3365
+ return window.XMLHttpRequest;
3366
+ },
3367
+ getWebSocketAPI() {
3368
+ return window.WebSocket || window.MozWebSocket;
3369
+ },
3370
+ setup(n) {
3371
+ window.Pusher = n;
3372
+ var e = () => {
3373
+ this.onDocumentBody(n.ready);
3374
+ };
3375
+ window.JSON ? e() : j.load("json2", {}, e);
3376
+ },
3377
+ getDocument() {
3378
+ return document;
3379
+ },
3380
+ getProtocol() {
3381
+ return this.getDocument().location.protocol;
3382
+ },
3383
+ getAuthorizers() {
3384
+ return { ajax: xt, jsonp: Jt };
3385
+ },
3386
+ onDocumentBody(n) {
3387
+ document.body ? n() : setTimeout(() => {
3388
+ this.onDocumentBody(n);
3389
+ }, 0);
3390
+ },
3391
+ createJSONPRequest(n, e) {
3392
+ return new Kt(n, e);
3393
+ },
3394
+ createScriptRequest(n) {
3395
+ return new Gt(n);
3396
+ },
3397
+ getLocalStorage() {
3398
+ try {
3399
+ return window.localStorage;
3400
+ } catch {
3401
+ return;
3402
+ }
3403
+ },
3404
+ createXHR() {
3405
+ return this.getXHRAPI() ? this.createXMLHttpRequest() : this.createMicrosoftXHR();
3406
+ },
3407
+ createXMLHttpRequest() {
3408
+ var n = this.getXHRAPI();
3409
+ return new n();
3410
+ },
3411
+ createMicrosoftXHR() {
3412
+ return new ActiveXObject("Microsoft.XMLHTTP");
3413
+ },
3414
+ getNetwork() {
3415
+ return gn;
3416
+ },
3417
+ createWebSocket(n) {
3418
+ var e = this.getWebSocketAPI();
3419
+ return new e(n);
3420
+ },
3421
+ createSocketRequest(n, e) {
3422
+ if (this.isXHRSupported())
3423
+ return this.HTTPFactory.createXHR(n, e);
3424
+ if (this.isXDRSupported(e.indexOf("https:") === 0))
3425
+ return this.HTTPFactory.createXDR(n, e);
3426
+ throw "Cross-origin HTTP requests are not supported";
3427
+ },
3428
+ isXHRSupported() {
3429
+ var n = this.getXHRAPI();
3430
+ return !!n && new n().withCredentials !== void 0;
3431
+ },
3432
+ isXDRSupported(n) {
3433
+ var e = n ? "https:" : "http:", t = this.getProtocol();
3434
+ return !!window.XDomainRequest && t === e;
3435
+ },
3436
+ addUnloadListener(n) {
3437
+ window.addEventListener !== void 0 ? window.addEventListener("unload", n, !1) : window.attachEvent !== void 0 && window.attachEvent("onunload", n);
3438
+ },
3439
+ removeUnloadListener(n) {
3440
+ window.addEventListener !== void 0 ? window.removeEventListener("unload", n, !1) : window.detachEvent !== void 0 && window.detachEvent("onunload", n);
3441
+ },
3442
+ randomInt(n) {
3443
+ return Math.floor(function() {
3444
+ return (window.crypto || window.msCrypto).getRandomValues(new Uint32Array(1))[0] / Math.pow(2, 32);
3445
+ }() * n);
3446
+ }
3447
+ };
3448
+ const b = ii;
3449
+ var ke;
3450
+ (function(n) {
3451
+ n[n.ERROR = 3] = "ERROR", n[n.INFO = 6] = "INFO", n[n.DEBUG = 7] = "DEBUG";
3452
+ })(ke || (ke = {}));
3453
+ const ue = ke;
3454
+ class ri {
3455
+ constructor(e, t, r) {
3456
+ this.key = e, this.session = t, this.events = [], this.options = r || {}, this.sent = 0, this.uniqueID = 0;
3457
+ }
3458
+ log(e, t) {
3459
+ e <= this.options.level && (this.events.push(M({}, t, { timestamp: U.now() })), this.options.limit && this.events.length > this.options.limit && this.events.shift());
3460
+ }
3461
+ error(e) {
3462
+ this.log(ue.ERROR, e);
3463
+ }
3464
+ info(e) {
3465
+ this.log(ue.INFO, e);
3466
+ }
3467
+ debug(e) {
3468
+ this.log(ue.DEBUG, e);
3469
+ }
3470
+ isEmpty() {
3471
+ return this.events.length === 0;
3472
+ }
3473
+ send(e, t) {
3474
+ var r = M({
3475
+ session: this.session,
3476
+ bundle: this.sent + 1,
3477
+ key: this.key,
3478
+ lib: "js",
3479
+ version: this.options.version,
3480
+ cluster: this.options.cluster,
3481
+ features: this.options.features,
3482
+ timeline: this.events
3483
+ }, this.options.params);
3484
+ return this.events = [], e(r, (s, a) => {
3485
+ s || this.sent++, t && t(s, a);
3486
+ }), !0;
3487
+ }
3488
+ generateUniqueID() {
3489
+ return this.uniqueID++, this.uniqueID;
3490
+ }
3491
+ }
3492
+ class si {
3493
+ constructor(e, t, r, s) {
3494
+ this.name = e, this.priority = t, this.transport = r, this.options = s || {};
3495
+ }
3496
+ isSupported() {
3497
+ return this.transport.isSupported({
3498
+ useTLS: this.options.useTLS
3499
+ });
3500
+ }
3501
+ connect(e, t) {
3502
+ if (this.isSupported()) {
3503
+ if (this.priority < e)
3504
+ return nt(new q(), t);
3505
+ } else return nt(new D(), t);
3506
+ var r = !1, s = this.transport.createConnection(this.name, this.priority, this.options.key, this.options), a = null, u = function() {
3507
+ s.unbind("initialized", u), s.connect();
3508
+ }, p = function() {
3509
+ a = X.createHandshake(s, function(I) {
3510
+ r = !0, x(), t(null, I);
3511
+ });
3512
+ }, v = function(I) {
3513
+ x(), t(I);
3514
+ }, E = function() {
3515
+ x();
3516
+ var I;
3517
+ I = ae(s), t(new N(I));
3518
+ }, x = function() {
3519
+ s.unbind("initialized", u), s.unbind("open", p), s.unbind("error", v), s.unbind("closed", E);
3520
+ };
3521
+ return s.bind("initialized", u), s.bind("open", p), s.bind("error", v), s.bind("closed", E), s.initialize(), {
3522
+ abort: () => {
3523
+ r || (x(), a ? a.close() : s.close());
3524
+ },
3525
+ forceMinPriority: (I) => {
3526
+ r || this.priority < I && (a ? a.close() : s.close());
3527
+ }
3528
+ };
3529
+ }
3530
+ }
3531
+ function nt(n, e) {
3532
+ return U.defer(function() {
3533
+ e(n);
3534
+ }), {
3535
+ abort: function() {
3536
+ },
3537
+ forceMinPriority: function() {
3538
+ }
3539
+ };
3540
+ }
3541
+ const { Transports: oi } = b;
3542
+ var ai = function(n, e, t, r, s, a) {
3543
+ var u = oi[t];
3544
+ if (!u)
3545
+ throw new V(t);
3546
+ var p = (!n.enabledTransports || ze(n.enabledTransports, e) !== -1) && (!n.disabledTransports || ze(n.disabledTransports, e) === -1), v;
3547
+ return p ? (s = Object.assign({ ignoreNullOrigin: n.ignoreNullOrigin }, s), v = new si(e, r, a ? a.getAssistant(u) : u, s)) : v = ci, v;
3548
+ }, ci = {
3549
+ isSupported: function() {
3550
+ return !1;
3551
+ },
3552
+ connect: function(n, e) {
3553
+ var t = U.defer(function() {
3554
+ e(new D());
3555
+ });
3556
+ return {
3557
+ abort: function() {
3558
+ t.ensureAborted();
3559
+ },
3560
+ forceMinPriority: function() {
3561
+ }
3562
+ };
3563
+ }
3564
+ };
3565
+ function hi(n) {
3566
+ if (n == null)
3567
+ throw "You must pass an options object";
3568
+ if (n.cluster == null)
3569
+ throw "Options object must provide a cluster";
3570
+ "disableStats" in n && R.warn("The disableStats option is deprecated in favor of enableStats");
3571
+ }
3572
+ const ui = (n, e) => {
3573
+ var t = "socket_id=" + encodeURIComponent(n.socketId);
3574
+ for (var r in e.params)
3575
+ t += "&" + encodeURIComponent(r) + "=" + encodeURIComponent(e.params[r]);
3576
+ if (e.paramsProvider != null) {
3577
+ let s = e.paramsProvider();
3578
+ for (var r in s)
3579
+ t += "&" + encodeURIComponent(r) + "=" + encodeURIComponent(s[r]);
3580
+ }
3581
+ return t;
3582
+ }, li = (n) => {
3583
+ if (typeof b.getAuthorizers()[n.transport] > "u")
3584
+ throw `'${n.transport}' is not a recognized auth transport`;
3585
+ return (e, t) => {
3586
+ const r = ui(e, n);
3587
+ b.getAuthorizers()[n.transport](b, r, n, l.UserAuthentication, t);
3588
+ };
3589
+ }, di = (n, e) => {
3590
+ var t = "socket_id=" + encodeURIComponent(n.socketId);
3591
+ t += "&channel_name=" + encodeURIComponent(n.channelName);
3592
+ for (var r in e.params)
3593
+ t += "&" + encodeURIComponent(r) + "=" + encodeURIComponent(e.params[r]);
3594
+ if (e.paramsProvider != null) {
3595
+ let s = e.paramsProvider();
3596
+ for (var r in s)
3597
+ t += "&" + encodeURIComponent(r) + "=" + encodeURIComponent(s[r]);
3598
+ }
3599
+ return t;
3600
+ }, pi = (n) => {
3601
+ if (typeof b.getAuthorizers()[n.transport] > "u")
3602
+ throw `'${n.transport}' is not a recognized auth transport`;
3603
+ return (e, t) => {
3604
+ const r = di(e, n);
3605
+ b.getAuthorizers()[n.transport](b, r, n, l.ChannelAuthorization, t);
3606
+ };
3607
+ }, fi = (n, e, t) => {
3608
+ const r = {
3609
+ authTransport: e.transport,
3610
+ authEndpoint: e.endpoint,
3611
+ auth: {
3612
+ params: e.params,
3613
+ headers: e.headers
3614
+ }
3615
+ };
3616
+ return (s, a) => {
3617
+ const u = n.channel(s.channelName);
3618
+ t(u, r).authorize(s.socketId, a);
3619
+ };
3620
+ };
3621
+ function it(n, e) {
3622
+ let t = {
3623
+ activityTimeout: n.activityTimeout || _.activityTimeout,
3624
+ cluster: n.cluster,
3625
+ httpPath: n.httpPath || _.httpPath,
3626
+ httpPort: n.httpPort || _.httpPort,
3627
+ httpsPort: n.httpsPort || _.httpsPort,
3628
+ pongTimeout: n.pongTimeout || _.pongTimeout,
3629
+ statsHost: n.statsHost || _.stats_host,
3630
+ unavailableTimeout: n.unavailableTimeout || _.unavailableTimeout,
3631
+ wsPath: n.wsPath || _.wsPath,
3632
+ wsPort: n.wsPort || _.wsPort,
3633
+ wssPort: n.wssPort || _.wssPort,
3634
+ enableStats: yi(n),
3635
+ httpHost: gi(n),
3636
+ useTLS: bi(n),
3637
+ wsHost: mi(n),
3638
+ userAuthenticator: wi(n),
3639
+ channelAuthorizer: Si(n, e)
3640
+ };
3641
+ return "disabledTransports" in n && (t.disabledTransports = n.disabledTransports), "enabledTransports" in n && (t.enabledTransports = n.enabledTransports), "ignoreNullOrigin" in n && (t.ignoreNullOrigin = n.ignoreNullOrigin), "timelineParams" in n && (t.timelineParams = n.timelineParams), "nacl" in n && (t.nacl = n.nacl), t;
3642
+ }
3643
+ function gi(n) {
3644
+ return n.httpHost ? n.httpHost : n.cluster ? `sockjs-${n.cluster}.pusher.com` : _.httpHost;
3645
+ }
3646
+ function mi(n) {
3647
+ return n.wsHost ? n.wsHost : vi(n.cluster);
3648
+ }
3649
+ function vi(n) {
3650
+ return `ws-${n}.pusher.com`;
3651
+ }
3652
+ function bi(n) {
3653
+ return b.getProtocol() === "https:" ? !0 : n.forceTLS !== !1;
3654
+ }
3655
+ function yi(n) {
3656
+ return "enableStats" in n ? n.enableStats : "disableStats" in n ? !n.disableStats : !1;
3657
+ }
3658
+ const rt = (n) => "customHandler" in n && n.customHandler != null;
3659
+ function wi(n) {
3660
+ const e = Object.assign(Object.assign({}, _.userAuthentication), n.userAuthentication);
3661
+ return rt(e) ? e.customHandler : li(e);
3662
+ }
3663
+ function Ci(n, e) {
3664
+ let t;
3665
+ if ("channelAuthorization" in n)
3666
+ t = Object.assign(Object.assign({}, _.channelAuthorization), n.channelAuthorization);
3667
+ else if (t = {
3668
+ transport: n.authTransport || _.authTransport,
3669
+ endpoint: n.authEndpoint || _.authEndpoint
3670
+ }, "auth" in n && ("params" in n.auth && (t.params = n.auth.params), "headers" in n.auth && (t.headers = n.auth.headers)), "authorizer" in n)
3671
+ return {
3672
+ customHandler: fi(e, t, n.authorizer)
3673
+ };
3674
+ return t;
3675
+ }
3676
+ function Si(n, e) {
3677
+ const t = Ci(n, e);
3678
+ return rt(t) ? t.customHandler : pi(t);
3679
+ }
3680
+ class _i extends $ {
3681
+ constructor(e) {
3682
+ super(function(t, r) {
3683
+ R.debug(`No callbacks on watchlist events for ${t}`);
3684
+ }), this.pusher = e, this.bindWatchlistInternalEvent();
3685
+ }
3686
+ handleEvent(e) {
3687
+ e.data.events.forEach((t) => {
3688
+ this.emit(t.name, t);
3689
+ });
3690
+ }
3691
+ bindWatchlistInternalEvent() {
3692
+ this.pusher.connection.bind("message", (e) => {
3693
+ var t = e.event;
3694
+ t === "pusher_internal:watchlist_events" && this.handleEvent(e);
3695
+ });
3696
+ }
3697
+ }
3698
+ function Ti() {
3699
+ let n, e;
3700
+ return { promise: new Promise((r, s) => {
3701
+ n = r, e = s;
3702
+ }), resolve: n, reject: e };
3703
+ }
3704
+ const ki = Ti;
3705
+ class Ei extends $ {
3706
+ constructor(e) {
3707
+ super(function(t, r) {
3708
+ R.debug("No callbacks on user for " + t);
3709
+ }), this.signin_requested = !1, this.user_data = null, this.serverToUserChannel = null, this.signinDonePromise = null, this._signinDoneResolve = null, this._onAuthorize = (t, r) => {
3710
+ if (t) {
3711
+ R.warn(`Error during signin: ${t}`), this._cleanup();
3712
+ return;
3713
+ }
3714
+ this.pusher.send_event("pusher:signin", {
3715
+ auth: r.auth,
3716
+ user_data: r.user_data
3717
+ });
3718
+ }, this.pusher = e, this.pusher.connection.bind("state_change", ({ previous: t, current: r }) => {
3719
+ t !== "connected" && r === "connected" && this._signin(), t === "connected" && r !== "connected" && (this._cleanup(), this._newSigninPromiseIfNeeded());
3720
+ }), this.watchlist = new _i(e), this.pusher.connection.bind("message", (t) => {
3721
+ var r = t.event;
3722
+ r === "pusher:signin_success" && this._onSigninSuccess(t.data), this.serverToUserChannel && this.serverToUserChannel.name === t.channel && this.serverToUserChannel.handleEvent(t);
3723
+ });
3724
+ }
3725
+ signin() {
3726
+ this.signin_requested || (this.signin_requested = !0, this._signin());
3727
+ }
3728
+ _signin() {
3729
+ this.signin_requested && (this._newSigninPromiseIfNeeded(), this.pusher.connection.state === "connected" && this.pusher.config.userAuthenticator({
3730
+ socketId: this.pusher.connection.socket_id
3731
+ }, this._onAuthorize));
3732
+ }
3733
+ _onSigninSuccess(e) {
3734
+ try {
3735
+ this.user_data = JSON.parse(e.user_data);
3736
+ } catch {
3737
+ R.error(`Failed parsing user data after signin: ${e.user_data}`), this._cleanup();
3738
+ return;
3739
+ }
3740
+ if (typeof this.user_data.id != "string" || this.user_data.id === "") {
3741
+ R.error(`user_data doesn't contain an id. user_data: ${this.user_data}`), this._cleanup();
3742
+ return;
3743
+ }
3744
+ this._signinDoneResolve(), this._subscribeChannels();
3745
+ }
3746
+ _subscribeChannels() {
3747
+ const e = (t) => {
3748
+ t.subscriptionPending && t.subscriptionCancelled ? t.reinstateSubscription() : !t.subscriptionPending && this.pusher.connection.state === "connected" && t.subscribe();
3749
+ };
3750
+ this.serverToUserChannel = new ye(`#server-to-user-${this.user_data.id}`, this.pusher), this.serverToUserChannel.bind_global((t, r) => {
3751
+ t.indexOf("pusher_internal:") === 0 || t.indexOf("pusher:") === 0 || this.emit(t, r);
3752
+ }), e(this.serverToUserChannel);
3753
+ }
3754
+ _cleanup() {
3755
+ this.user_data = null, this.serverToUserChannel && (this.serverToUserChannel.unbind_all(), this.serverToUserChannel.disconnect(), this.serverToUserChannel = null), this.signin_requested && this._signinDoneResolve();
3756
+ }
3757
+ _newSigninPromiseIfNeeded() {
3758
+ if (!this.signin_requested || this.signinDonePromise && !this.signinDonePromise.done)
3759
+ return;
3760
+ const { promise: e, resolve: t } = ki();
3761
+ e.done = !1;
3762
+ const r = () => {
3763
+ e.done = !0;
3764
+ };
3765
+ e.then(r).catch(r), this.signinDonePromise = e, this._signinDoneResolve = t;
3766
+ }
3767
+ }
3768
+ class O {
3769
+ static ready() {
3770
+ O.isReady = !0;
3771
+ for (var e = 0, t = O.instances.length; e < t; e++)
3772
+ O.instances[e].connect();
3773
+ }
3774
+ static getClientFeatures() {
3775
+ return He(Fe({ ws: b.Transports.ws }, function(e) {
3776
+ return e.isSupported({});
3777
+ }));
3778
+ }
3779
+ constructor(e, t) {
3780
+ xi(e), hi(t), this.key = e, this.options = t, this.config = it(this.options, this), this.channels = X.createChannels(), this.global_emitter = new $(), this.sessionID = b.randomInt(1e9), this.timeline = new ri(this.key, this.sessionID, {
3781
+ cluster: this.config.cluster,
3782
+ features: O.getClientFeatures(),
3783
+ params: this.config.timelineParams || {},
3784
+ limit: 50,
3785
+ level: ue.INFO,
3786
+ version: _.VERSION
3787
+ }), this.config.enableStats && (this.timelineSender = X.createTimelineSender(this.timeline, {
3788
+ host: this.config.statsHost,
3789
+ path: "/timeline/v2/" + b.TimelineTransport.name
3790
+ }));
3791
+ var r = (s) => b.getDefaultStrategy(this.config, s, ai);
3792
+ this.connection = X.createConnectionManager(this.key, {
3793
+ getStrategy: r,
3794
+ timeline: this.timeline,
3795
+ activityTimeout: this.config.activityTimeout,
3796
+ pongTimeout: this.config.pongTimeout,
3797
+ unavailableTimeout: this.config.unavailableTimeout,
3798
+ useTLS: !!this.config.useTLS
3799
+ }), this.connection.bind("connected", () => {
3800
+ this.subscribeAll(), this.timelineSender && this.timelineSender.send(this.connection.isUsingTLS());
3801
+ }), this.connection.bind("message", (s) => {
3802
+ var a = s.event, u = a.indexOf("pusher_internal:") === 0;
3803
+ if (s.channel) {
3804
+ var p = this.channel(s.channel);
3805
+ p && p.handleEvent(s);
3806
+ }
3807
+ u || this.global_emitter.emit(s.event, s.data);
3808
+ }), this.connection.bind("connecting", () => {
3809
+ this.channels.disconnect();
3810
+ }), this.connection.bind("disconnected", () => {
3811
+ this.channels.disconnect();
3812
+ }), this.connection.bind("error", (s) => {
3813
+ R.warn(s);
3814
+ }), O.instances.push(this), this.timeline.info({ instances: O.instances.length }), this.user = new Ei(this), O.isReady && this.connect();
3815
+ }
3816
+ switchCluster(e) {
3817
+ const { appKey: t, cluster: r } = e;
3818
+ this.key = t, this.options = Object.assign(Object.assign({}, this.options), { cluster: r }), this.config = it(this.options, this), this.connection.switchCluster(this.key);
3819
+ }
3820
+ channel(e) {
3821
+ return this.channels.find(e);
3822
+ }
3823
+ allChannels() {
3824
+ return this.channels.all();
3825
+ }
3826
+ connect() {
3827
+ if (this.connection.connect(), this.timelineSender && !this.timelineSenderTimer) {
3828
+ var e = this.connection.isUsingTLS(), t = this.timelineSender;
3829
+ this.timelineSenderTimer = new jt(6e4, function() {
3830
+ t.send(e);
3831
+ });
3832
+ }
3833
+ }
3834
+ disconnect() {
3835
+ this.connection.disconnect(), this.timelineSenderTimer && (this.timelineSenderTimer.ensureAborted(), this.timelineSenderTimer = null);
3836
+ }
3837
+ bind(e, t, r) {
3838
+ return this.global_emitter.bind(e, t, r), this;
3839
+ }
3840
+ unbind(e, t, r) {
3841
+ return this.global_emitter.unbind(e, t, r), this;
3842
+ }
3843
+ bind_global(e) {
3844
+ return this.global_emitter.bind_global(e), this;
3845
+ }
3846
+ unbind_global(e) {
3847
+ return this.global_emitter.unbind_global(e), this;
3848
+ }
3849
+ unbind_all(e) {
3850
+ return this.global_emitter.unbind_all(), this;
3851
+ }
3852
+ subscribeAll() {
3853
+ var e;
3854
+ for (e in this.channels.channels)
3855
+ this.channels.channels.hasOwnProperty(e) && this.subscribe(e);
3856
+ }
3857
+ subscribe(e) {
3858
+ var t = this.channels.add(e, this);
3859
+ return t.subscriptionPending && t.subscriptionCancelled ? t.reinstateSubscription() : !t.subscriptionPending && this.connection.state === "connected" && t.subscribe(), t;
3860
+ }
3861
+ unsubscribe(e) {
3862
+ var t = this.channels.find(e);
3863
+ t && t.subscriptionPending ? t.cancelSubscription() : (t = this.channels.remove(e), t && t.subscribed && t.unsubscribe());
3864
+ }
3865
+ send_event(e, t, r) {
3866
+ return this.connection.send_event(e, t, r);
3867
+ }
3868
+ shouldUseTLS() {
3869
+ return this.config.useTLS;
3870
+ }
3871
+ signin() {
3872
+ this.user.signin();
3873
+ }
3874
+ }
3875
+ O.instances = [], O.isReady = !1, O.logToConsole = !1, O.Runtime = b, O.ScriptReceivers = b.ScriptReceivers, O.DependenciesReceivers = b.DependenciesReceivers, O.auth_callbacks = b.auth_callbacks;
3876
+ const le = O;
3877
+ function xi(n) {
3878
+ if (n == null)
3879
+ throw "You must pass your app key when you instantiate Pusher.";
3880
+ }
3881
+ b.setup(O);
3882
+ }
3883
+ /******/
3884
+ }, c = {};
3885
+ function h(y) {
3886
+ var f = c[y];
3887
+ if (f !== void 0)
3888
+ return f.exports;
3889
+ var m = c[y] = {
3890
+ /******/
3891
+ // no module.id needed
3892
+ /******/
3893
+ // no module.loaded needed
3894
+ /******/
3895
+ exports: {}
3896
+ /******/
3897
+ };
3898
+ return o[y].call(m.exports, m, m.exports, h), m.exports;
3899
+ }
3900
+ h.d = (y, f) => {
3901
+ for (var m in f)
3902
+ h.o(f, m) && !h.o(y, m) && Object.defineProperty(y, m, { enumerable: !0, get: f[m] });
3903
+ }, h.o = (y, f) => Object.prototype.hasOwnProperty.call(y, f);
3904
+ var C = h(721);
3905
+ return C;
3906
+ })()
3907
+ ));
3908
+ })(Ae)), Ae.exports;
3909
+ }
3910
+ var Ji = Vi();
3911
+ const Gi = /* @__PURE__ */ Xi(Ji), Pe = "/vendor/sendity-client/tailwind.css", Ki = {
3912
+ labels: {
3913
+ email: "Email",
3914
+ whatsapp: "WhatsApp"
3915
+ },
3916
+ ui: {
3917
+ sendCodePrompt: "Send this code to sign in:",
3918
+ successGreeting: "(Name), you're in!",
3919
+ by: "by",
3920
+ footerWaiting: "Waiting for your code…",
3921
+ footerWaitingUntil: "Waiting for your code until (Time)…"
3922
+ },
3923
+ templates: {
3924
+ emailSubject: "Sign me into (Host) with this code: (Code)",
3925
+ emailBody: `To authenticate with (Host), send this email without making any changes.
3926
+
3927
+ Code: (Code)`,
3928
+ whatsappText: "Sign me into (Host) with this code: (Code)"
3929
+ }
3930
+ }, Qi = {
3931
+ labels: {
3932
+ email: "E-Mail",
3933
+ whatsapp: "WhatsApp"
3934
+ },
3935
+ ui: {
3936
+ sendCodePrompt: "Sende diesen Code, um dich anzumelden:",
3937
+ successGreeting: "(Name), du bist drin!",
3938
+ by: "per",
3939
+ footerWaiting: "Wir warten auf deinen Code …",
3940
+ footerWaitingUntil: "Wir warten bis (Time) auf deinen Code …"
3941
+ },
3942
+ templates: {
3943
+ emailSubject: "Melde mich bei (Host) mit diesem Code an: (Code)",
3944
+ emailBody: `Um dich bei (Host) zu authentifizieren, sende diese E-Mail unverändert ab.
3945
+
3946
+ Code: (Code)`,
3947
+ whatsappText: "Melde mich bei (Host) mit diesem Code an: (Code)"
3948
+ }
3949
+ }, Yi = {
3950
+ labels: {
3951
+ email: "E-mail",
3952
+ whatsapp: "WhatsApp"
3953
+ },
3954
+ ui: {
3955
+ sendCodePrompt: "Envoyez ce code pour vous connecter :",
3956
+ successGreeting: "(Name), vous êtes connecté !",
3957
+ by: "par",
3958
+ footerWaiting: "En attente de votre code…",
3959
+ footerWaitingUntil: "En attente de votre code jusqu’à (Time)…"
3960
+ },
3961
+ templates: {
3962
+ emailSubject: "Connectez-moi à (Host) avec ce code : (Code)",
3963
+ emailBody: `Pour vous authentifier auprès de (Host), envoyez simplement cet e-mail sans aucune modification.
3964
+
3965
+ Code : (Code)`,
3966
+ whatsappText: "Connectez-moi à (Host) avec ce code : (Code)"
3967
+ }
3968
+ };
3969
+ function se(g) {
3970
+ switch (g) {
3971
+ case "de":
3972
+ return Qi;
3973
+ case "fr":
3974
+ return Yi;
3975
+ default:
3976
+ return Ki;
3977
+ }
3978
+ }
3979
+ const mt = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="size-6">
3980
+ <path d="M1.5 8.67v8.58a3 3 0 0 0 3 3h15a3 3 0 0 0 3-3V8.67l-8.928 5.493a3 3 0 0 1-3.144 0L1.5 8.67Z" />
3981
+ <path d="M22.5 6.908V6.75a3 3 0 0 0-3-3h-15a3 3 0 0 0-3 3v.158l9.714 5.978a1.5 1.5 0 0 0 1.572 0L22.5 6.908Z" />
3982
+ </svg>
3983
+ `, vt = '<svg role="img" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg"><title>WhatsApp</title><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413Z"/></svg>', je = "sendityAuthRequest", Zi = "https://sendity.io/api", er = ["mailto:verify@sendity.io"], tr = 600 * 1e3, nr = 5e3, ir = 15e3, Re = 2e3, rr = 0;
3984
+ function Ne(g, i) {
3985
+ return `sendity:auth-request:${encodeURIComponent(g)}:${encodeURIComponent(i)}`;
3986
+ }
3987
+ function bt(g, i, o, c = Date.now()) {
3988
+ g.removeItem(je);
3989
+ const h = Ne(i, o), C = g.getItem(h);
3990
+ if (!C) return null;
3991
+ try {
3992
+ const y = JSON.parse(C);
3993
+ if (typeof y.id != "string" || typeof y.clientSecret != "string" || typeof y.createdAt != "number")
3994
+ throw new Error("invalid stored auth request");
3995
+ return c - y.createdAt >= tr ? (g.removeItem(h), null) : { id: y.id, clientSecret: y.clientSecret };
3996
+ } catch {
3997
+ return g.removeItem(h), null;
3998
+ }
3999
+ }
4000
+ function sr(g, i, o, c, h = Date.now()) {
4001
+ g.setItem(Ne(i, o), JSON.stringify({ ...c, createdAt: h }));
4002
+ }
4003
+ function yt(g, i, o) {
4004
+ g.removeItem(Ne(i, o)), g.removeItem(je);
4005
+ }
4006
+ function Le() {
4007
+ return window.localStorage.removeItem(je), window.sessionStorage;
4008
+ }
4009
+ function or(g, i = window.location.origin) {
4010
+ return g.filter((o) => ar(o, i));
4011
+ }
4012
+ function ar(g, i) {
4013
+ try {
4014
+ const o = new URL(g, i);
4015
+ return ["http:", "https:", "mailto:", "whatsapp:"].includes(o.protocol);
4016
+ } catch {
4017
+ return !1;
4018
+ }
4019
+ }
4020
+ function cr(g, i, o) {
4021
+ return g === "polling" ? { start: !0, delayMs: 0 } : g === "push" ? { start: !1, delayMs: 0 } : !i || !o ? { start: !0, delayMs: 0 } : { start: !1, delayMs: 0 };
4022
+ }
4023
+ const ge = class ge extends HTMLElement {
4024
+ constructor() {
4025
+ super(), this.pollTimer = null, this.fallbackPollTimer = null, this.authenticatedEventTimer = null, this.codeContainerEl = null, this.codeEl = null, this.promptEl = null, this.successEl = null, this.spinnerEl = null, this.verifiersEl = null, this.footerEl = null, this.footerBrandEl = null, this.footerStatusEl = null, this.footerMessageEl = null, this.footerObserver = null, this.footerWaitTimer = null, this.currentConfig = null, this.destroyed = !1, this.lastCode = void 0, this.echo = null, this.authenticated = !1;
4026
+ const i = this.attachShadow({ mode: "open" });
4027
+ this.injectTailwind(i);
4028
+ const o = document.createElement("div");
4029
+ o.innerHTML = pt;
4030
+ const c = o.querySelector("template"), h = c ? c.content.cloneNode(!0) : document.createRange().createContextualFragment(pt), C = document.createElement("style");
4031
+ C.textContent = Ni, i.appendChild(C), i.appendChild(h);
4032
+ }
4033
+ static get observedAttributes() {
4034
+ return ["server-url", "public-key", "verify-urls", "lang", "transport", "hide-footer", "footer", "authenticated-event-delay-ms"];
4035
+ }
4036
+ connectedCallback() {
4037
+ this.codeContainerEl = this.shadowRoot?.querySelector(".code"), this.codeEl = this.shadowRoot?.querySelector(".formatted-code"), this.promptEl = this.shadowRoot?.querySelector(".prompt"), this.successEl = this.shadowRoot?.querySelector(".success"), this.spinnerEl = this.shadowRoot?.querySelector(".spinner"), this.verifiersEl = this.shadowRoot?.querySelector(".verifiers"), this.footerEl = this.shadowRoot?.querySelector(".sendity-footer"), this.footerBrandEl = this.shadowRoot?.querySelector(".footer-brand"), this.footerStatusEl = this.shadowRoot?.querySelector(".footer-status"), this.footerMessageEl = this.shadowRoot?.querySelector(".footer-message");
4038
+ try {
4039
+ this.currentConfig = this.resolveConfig();
4040
+ } catch (i) {
4041
+ this.handleInitialError(i);
4042
+ return;
4043
+ }
4044
+ this.configureFooter(), this.dispatchPublicEvent("sendity:ready", {
4045
+ transport: this.currentConfig.transport,
4046
+ channel: this.primaryChannel(this.currentConfig.verifyUrls)
4047
+ }), this.showLoading(), this.renderVerifiers(this.currentConfig.verifyUrls), this.start();
4048
+ }
4049
+ disconnectedCallback() {
4050
+ this.stop(), this.destroyed = !0;
4051
+ }
4052
+ attributeChangedCallback() {
4053
+ this.isConnected && (this.currentConfig = this.resolveConfig(), this.configureFooter(), this.renderVerifiers(this.currentConfig.verifyUrls));
4054
+ }
4055
+ start() {
4056
+ this.step().then((i) => {
4057
+ this.authenticated || this.destroyed || this.configureRealtime(i);
4058
+ }).catch((i) => {
4059
+ this.handleInitialError(i);
4060
+ });
4061
+ }
4062
+ stop() {
4063
+ this.pollTimer !== null && (clearInterval(this.pollTimer), this.pollTimer = null), this.fallbackPollTimer !== null && (clearTimeout(this.fallbackPollTimer), this.fallbackPollTimer = null), this.footerWaitTimer !== null && (clearTimeout(this.footerWaitTimer), this.footerWaitTimer = null), this.authenticatedEventTimer !== null && (clearTimeout(this.authenticatedEventTimer), this.authenticatedEventTimer = null), this.footerObserver?.disconnect(), this.footerObserver = null, this.echo && this.activeAuthRequestId && this.echo.leave(`sendity.auth-requests.${this.activeAuthRequestId}`), this.echo?.disconnect(), this.echo = null;
4064
+ }
4065
+ // Inject Tailwind CSS into the Shadow DOM so Tailwind utility classes
4066
+ // used in sendity.html work within the component. We cache the processed
4067
+ // CSS text across instances to avoid redundant network requests and ensure
4068
+ // the Tailwind layer is inserted before component CSS.
4069
+ injectTailwind(i) {
4070
+ const o = document.createElement("style");
4071
+ o.setAttribute("data-sendity-tw", ""), i.appendChild(o);
4072
+ const c = this.constructor;
4073
+ if (c.tailwindCssText !== null) {
4074
+ if (c.tailwindCssText)
4075
+ o.textContent = c.tailwindCssText;
4076
+ else {
4077
+ const h = document.createElement("link");
4078
+ h.rel = "stylesheet", h.href = Pe, i.insertBefore(h, o);
4079
+ }
4080
+ return;
4081
+ }
4082
+ c.tailwindLoading || (c.tailwindLoading = fetch(Pe).then((h) => h.ok ? h.text() : Promise.reject(new Error(`HTTP ${h.status}`))).then((h) => {
4083
+ c.tailwindCssText = h;
4084
+ }).catch((h) => {
4085
+ console.warn("[sendity-auth] Failed to load Tailwind CSS for Shadow DOM", h), c.tailwindCssText = "";
4086
+ })), c.tailwindLoading.then(() => {
4087
+ if (!this.destroyed && i)
4088
+ if (c.tailwindCssText)
4089
+ o.textContent = c.tailwindCssText;
4090
+ else {
4091
+ const h = document.createElement("link");
4092
+ h.rel = "stylesheet", h.href = Pe, i.insertBefore(h, o);
4093
+ }
4094
+ });
4095
+ }
4096
+ configureFooter() {
4097
+ if (this.footerEl) {
4098
+ if (this.isFooterHidden()) {
4099
+ this.footerEl.hidden = !0, this.footerWaitTimer !== null && (clearTimeout(this.footerWaitTimer), this.footerWaitTimer = null), this.footerObserver?.disconnect(), this.footerObserver = null;
4100
+ return;
4101
+ }
4102
+ this.footerEl.hidden = !1, this.footerBrandEl?.removeAttribute("hidden"), this.footerStatusEl?.setAttribute("hidden", ""), this.observeFooterVisibility();
4103
+ }
4104
+ }
4105
+ isFooterHidden() {
4106
+ const i = (this.getAttribute("footer") ?? "").trim().toLowerCase();
4107
+ return this.hasAttribute("hide-footer") || ["false", "hidden", "none", "off", "0"].includes(i);
4108
+ }
4109
+ observeFooterVisibility() {
4110
+ !this.footerEl || this.footerObserver || !("IntersectionObserver" in window) || (this.footerObserver = new IntersectionObserver((i) => {
4111
+ i.some((c) => c.isIntersecting) ? this.scheduleFooterWaitingState() : this.footerWaitTimer !== null && (clearTimeout(this.footerWaitTimer), this.footerWaitTimer = null);
4112
+ }), this.footerObserver.observe(this));
4113
+ }
4114
+ scheduleFooterWaitingState() {
4115
+ this.footerWaitTimer !== null || this.isFooterHidden() || (this.footerWaitTimer = window.setTimeout(() => {
4116
+ this.footerWaitTimer = null, this.showFooterWaitingState();
4117
+ }, ir));
4118
+ }
4119
+ showFooterWaitingState() {
4120
+ this.isFooterHidden() || (this.footerBrandEl?.setAttribute("hidden", ""), this.currentConfig && this.footerMessageEl && (this.footerMessageEl.textContent = this.waitingFooterMessage()), this.footerStatusEl?.removeAttribute("hidden"));
4121
+ }
4122
+ handleInitialError(i) {
4123
+ console.error("[sendity-auth] Unable to initialize authentication", i), this.renderError("Unable to initialize authentication, see console for details"), this.dispatchEvent(
4124
+ new CustomEvent("sendity:error", {
4125
+ bubbles: !0,
4126
+ composed: !0,
4127
+ detail: i instanceof Error ? { message: i.message, name: i.name } : { message: String(i) }
4128
+ })
4129
+ );
4130
+ }
4131
+ resolveConfig() {
4132
+ const i = {
4133
+ lang: navigator.language?.startsWith("de") ? "de" : navigator.language?.startsWith("fr") ? "fr" : "en",
4134
+ transport: "auto"
4135
+ }, o = (L) => this.getAttribute(L) ?? void 0, c = o("server-url")?.trim() || Zi, h = o("public-key")?.trim();
4136
+ if (!h)
4137
+ throw new Error("Missing required sendity-auth attribute: public-key");
4138
+ let C = [...er];
4139
+ const y = o("verify-urls");
4140
+ if (y)
4141
+ try {
4142
+ if (C = JSON.parse(y), !Array.isArray(C)) throw new Error("verify-urls not array");
4143
+ C = C.map(String);
4144
+ } catch {
4145
+ C = y.split(",").map((L) => L.trim()).filter(Boolean);
4146
+ }
4147
+ if (C = or(C), C.length === 0)
4148
+ throw new Error("Missing required sendity-auth attribute: verify-urls");
4149
+ let f = o("lang") || i.lang;
4150
+ f !== "en" && f !== "de" && f !== "fr" && (f = i.lang);
4151
+ const m = o("transport"), k = m === "push" || m === "polling" ? m : i.transport, S = this.parseAuthenticatedEventDelayMs(o("authenticated-event-delay-ms"));
4152
+ return { serverUrl: c, publicKey: h, verifyUrls: C, lang: f, transport: k, authenticatedEventDelayMs: S };
4153
+ }
4154
+ parseAuthenticatedEventDelayMs(i) {
4155
+ if (i === void 0 || i.trim() === "") return Re;
4156
+ const o = Number(i);
4157
+ return !Number.isFinite(o) || o < 0 ? Re : Math.round(o);
4158
+ }
4159
+ async step() {
4160
+ this.currentConfig || (this.currentConfig = this.resolveConfig());
4161
+ const { serverUrl: i, publicKey: o } = this.currentConfig, c = Le(), h = bt(c, i, o), C = h?.id;
4162
+ if (!C) {
4163
+ const k = await fetch(this.joinUrl(i, "/auth-requests"), {
4164
+ method: "POST",
4165
+ mode: "cors",
4166
+ headers: {
4167
+ "Content-Type": "application/json",
4168
+ Accept: "application/json"
4169
+ },
4170
+ body: JSON.stringify({ public_key: o })
4171
+ });
4172
+ if (!k.ok) throw new Error(`Auth request creation failed: ${k.status}`);
4173
+ const S = await k.json();
4174
+ if (!S.id) throw new Error("Missing id from server response");
4175
+ const L = this.extractClientSecret(S);
4176
+ if (!L) throw new Error("Missing client secret from server response");
4177
+ return sr(c, i, o, { id: String(S.id), clientSecret: L }), this.activeAuthRequestId = String(S.id), this.activeAuthRequestSecret = L, this.updateActiveAuthRequestExpiry(S), this.updateCode(S.formattedCode ?? S.code), this.dispatchPublicEvent("sendity:challenge-created", {
4178
+ verificationId: String(S.id),
4179
+ code: S.formattedCode ?? S.code ?? "",
4180
+ channel: this.primaryChannel(this.currentConfig.verifyUrls)
4181
+ }), S;
4182
+ }
4183
+ this.activeAuthRequestId = C, this.activeAuthRequestSecret = h.clientSecret;
4184
+ const y = await fetch(
4185
+ this.authRequestStatusUrl(i, C),
4186
+ this.authRequestStatusInit(h.clientSecret)
4187
+ );
4188
+ if (y.status !== 200)
4189
+ return yt(c, i, o), await this.step();
4190
+ const f = await y.json();
4191
+ if (f.status === "verified")
4192
+ return this.handleAuthenticated(f), f;
4193
+ f.id && (this.activeAuthRequestId = String(f.id));
4194
+ const m = this.extractClientSecret(f);
4195
+ return m && (this.activeAuthRequestSecret = m), this.updateActiveAuthRequestExpiry(f), this.updateCode(f.formattedCode ?? f.code), f;
4196
+ }
4197
+ configureRealtime(i) {
4198
+ this.currentConfig || (this.currentConfig = this.resolveConfig());
4199
+ const { transport: o } = this.currentConfig, c = i?.broadcasting, h = !!(c?.key && c.channel && c.authEndpoint);
4200
+ let C = !1;
4201
+ o !== "polling" && h && c ? C = this.subscribeToBroadcasting(c) : o === "push" && console.warn("[sendity-auth] Push transport requested, but server response does not contain broadcasting metadata");
4202
+ const y = cr(o, h, C);
4203
+ y.start && this.startPolling(y.delayMs);
4204
+ }
4205
+ subscribeToBroadcasting(i) {
4206
+ if (!this.currentConfig || !i.key || !i.channel || !i.authEndpoint) return !1;
4207
+ try {
4208
+ window.Pusher = Gi;
4209
+ const o = (i.scheme ?? "https") === "https", c = i.port ?? (o ? 443 : 80);
4210
+ return this.echo = new $i({
4211
+ broadcaster: "reverb",
4212
+ key: i.key,
4213
+ wsHost: i.host ?? new URL(this.currentConfig.serverUrl).hostname,
4214
+ wsPort: c,
4215
+ wssPort: c,
4216
+ wsPath: i.wsPath ?? "/ws",
4217
+ forceTLS: o,
4218
+ encrypted: o,
4219
+ enabledTransports: ["ws", "wss"],
4220
+ authEndpoint: this.joinUrl(this.currentConfig.serverUrl, i.authEndpoint),
4221
+ auth: {
4222
+ headers: {
4223
+ Accept: "application/json"
4224
+ }
4225
+ }
4226
+ }), this.echo.private(i.channel).listen(i.event ?? ".authenticated", (h) => {
4227
+ this.handleAuthenticated(h);
4228
+ }), !0;
4229
+ } catch (o) {
4230
+ return console.warn("[sendity-auth] realtime subscription failed, falling back to polling if enabled", o), this.currentConfig.transport === "auto" && this.startPolling(rr), !1;
4231
+ }
4232
+ }
4233
+ startPolling(i) {
4234
+ if (this.pollTimer !== null || this.authenticated) return;
4235
+ const o = () => {
4236
+ this.pollTimer !== null || this.authenticated || this.destroyed || (this.pollTimer = window.setInterval(() => {
4237
+ this.step().catch((c) => console.warn("[sendity-auth] poll failed", c));
4238
+ }, nr));
4239
+ };
4240
+ i > 0 ? this.fallbackPollTimer = window.setTimeout(() => {
4241
+ this.fallbackPollTimer = null, o();
4242
+ }, i) : o();
4243
+ }
4244
+ handleAuthenticated(i) {
4245
+ if (this.authenticated) return;
4246
+ if (!i.authorization) {
4247
+ console.warn("[sendity-auth] authenticated signal did not include authorization; fetching canonical status"), this.fetchAuthorizationAfterAuthenticatedSignal().catch((h) => {
4248
+ console.warn("[sendity-auth] failed to fetch authorization after authenticated signal", h);
4249
+ });
4250
+ return;
4251
+ }
4252
+ this.authenticated = !0, this.currentConfig && yt(Le(), this.currentConfig.serverUrl, this.currentConfig.publicKey), this.stopAuthTransports(), this.showSuccess(i.name);
4253
+ const o = this.toPublicAuthenticatedDetail(i), c = this.currentConfig?.authenticatedEventDelayMs ?? Re;
4254
+ this.authenticatedEventTimer = window.setTimeout(() => {
4255
+ this.authenticatedEventTimer = null, !this.destroyed && this.dispatchPublicEvent("sendity:authenticated", o);
4256
+ }, c);
4257
+ }
4258
+ stopAuthTransports() {
4259
+ this.pollTimer !== null && (clearInterval(this.pollTimer), this.pollTimer = null), this.fallbackPollTimer !== null && (clearTimeout(this.fallbackPollTimer), this.fallbackPollTimer = null), this.echo && this.activeAuthRequestId && this.echo.leave(`sendity.auth-requests.${this.activeAuthRequestId}`), this.echo?.disconnect(), this.echo = null;
4260
+ }
4261
+ dispatchPublicEvent(i, o) {
4262
+ this.dispatchEvent(new CustomEvent(i, { bubbles: !0, composed: !0, detail: o }));
4263
+ }
4264
+ toPublicAuthenticatedDetail(i) {
4265
+ const o = String(i.auth_request_id ?? i.authRequestId ?? this.activeAuthRequestId ?? ""), c = i.channel ?? this.primaryChannel(this.currentConfig?.verifyUrls ?? []), h = i.expires_at ?? i.expiresAt;
4266
+ return {
4267
+ sessionId: o,
4268
+ channel: c,
4269
+ ...i.identifier ? { address: i.identifier } : {},
4270
+ verificationId: o,
4271
+ signedResult: String(i.authorization ?? ""),
4272
+ ...h ? { expiresAt: String(h) } : {}
4273
+ };
4274
+ }
4275
+ primaryChannel(i) {
4276
+ const o = i[0] ?? "";
4277
+ return o.startsWith("mailto:") ? "email" : o.startsWith("whatsapp:") || o.startsWith("whatsapp://") ? "whatsapp" : "unknown";
4278
+ }
4279
+ authRequestStatusUrl(i, o) {
4280
+ return new URL(this.joinUrl(i, `/auth-requests/${encodeURIComponent(o)}`)).toString();
4281
+ }
4282
+ authRequestStatusInit(i) {
4283
+ return {
4284
+ method: "GET",
4285
+ mode: "cors",
4286
+ headers: {
4287
+ Accept: "application/json",
4288
+ "X-Sendity-Client-Secret": i
4289
+ }
4290
+ };
4291
+ }
4292
+ extractClientSecret(i) {
4293
+ return String(i.client_secret ?? i.clientSecret ?? "");
4294
+ }
4295
+ updateActiveAuthRequestExpiry(i) {
4296
+ const o = i.expires_at ?? i.expiresAt;
4297
+ o && (this.activeAuthRequestExpiresAt = String(o), this.updateCodeValidityDuration());
4298
+ }
4299
+ waitingFooterMessage() {
4300
+ if (!this.currentConfig) return "";
4301
+ const i = se(this.currentConfig.lang), o = this.formatExpiryTime(this.activeAuthRequestExpiresAt, this.currentConfig.lang);
4302
+ return o ? i.ui.footerWaitingUntil.replace("(Time)", o) : i.ui.footerWaiting;
4303
+ }
4304
+ formatExpiryTime(i, o) {
4305
+ if (!i) return null;
4306
+ const c = new Date(i);
4307
+ return Number.isNaN(c.getTime()) ? null : new Intl.DateTimeFormat(this.localeForLang(o), { timeStyle: "short" }).format(c);
4308
+ }
4309
+ localeForLang(i) {
4310
+ switch (i) {
4311
+ case "de":
4312
+ return "de-DE";
4313
+ case "fr":
4314
+ return "fr-FR";
4315
+ default:
4316
+ return "en-US";
4317
+ }
4318
+ }
4319
+ updateCodeValidityDuration() {
4320
+ if (!this.codeContainerEl || !this.activeAuthRequestExpiresAt) return;
4321
+ const i = new Date(this.activeAuthRequestExpiresAt).getTime();
4322
+ if (Number.isNaN(i)) return;
4323
+ const o = Math.max(1, Math.round((i - Date.now()) / 1e3));
4324
+ this.codeContainerEl.style.setProperty("--sendity-code-validity-duration", `${o}s`);
4325
+ }
4326
+ async fetchAuthorizationAfterAuthenticatedSignal() {
4327
+ this.currentConfig || (this.currentConfig = this.resolveConfig());
4328
+ const i = bt(Le(), this.currentConfig.serverUrl, this.currentConfig.publicKey), o = this.activeAuthRequestId ?? i?.id, c = this.activeAuthRequestSecret ?? i?.clientSecret;
4329
+ if (!o || !c)
4330
+ throw new Error("Cannot fetch authorization without an active auth request id and client secret");
4331
+ const h = await fetch(
4332
+ this.authRequestStatusUrl(this.currentConfig.serverUrl, o),
4333
+ this.authRequestStatusInit(c)
4334
+ );
4335
+ if (!h.ok)
4336
+ throw new Error(`Authorization fetch failed: ${h.status}`);
4337
+ const C = await h.json();
4338
+ if (C.status === "verified" && C.authorization) {
4339
+ this.handleAuthenticated(C);
4340
+ return;
4341
+ }
4342
+ throw new Error("Verified auth request did not include authorization");
4343
+ }
4344
+ updateCode(i) {
4345
+ if (!this.codeEl) return;
4346
+ if (!!(i && String(i).trim().length > 0)) {
4347
+ const c = String(i);
4348
+ this.lastCode = c, this.codeEl.textContent = c, this.showCodeState();
4349
+ } else {
4350
+ this.lastCode = void 0;
4351
+ const c = this.codeEl.getAttribute("data-placeholder") || "••••";
4352
+ this.codeEl.textContent = c, this.showLoading();
4353
+ }
4354
+ this.currentConfig && this.renderVerifiers(this.currentConfig.verifyUrls);
4355
+ }
4356
+ renderError(i) {
4357
+ this.codeEl && (this.codeEl.textContent = i), this.verifiersEl && (this.verifiersEl.innerHTML = "");
4358
+ }
4359
+ showLoading() {
4360
+ this.spinnerEl?.removeAttribute("hidden"), this.codeContainerEl?.classList.remove("code--active", "code--verified"), this.codeEl?.setAttribute("hidden", ""), this.promptEl?.setAttribute("hidden", ""), this.successEl?.setAttribute("hidden", "");
4361
+ }
4362
+ showCodeState() {
4363
+ if (this.spinnerEl?.setAttribute("hidden", ""), this.codeContainerEl?.classList.remove("code--verified"), this.codeContainerEl?.classList.add("code--active"), this.codeEl?.removeAttribute("hidden"), this.currentConfig && this.promptEl) {
4364
+ const i = se(this.currentConfig.lang);
4365
+ this.promptEl.textContent = i.ui.sendCodePrompt, this.promptEl.removeAttribute("hidden");
4366
+ }
4367
+ this.successEl?.setAttribute("hidden", "");
4368
+ }
4369
+ showSuccess(i) {
4370
+ if (this.spinnerEl?.setAttribute("hidden", ""), this.codeContainerEl?.classList.remove("code--active"), this.codeContainerEl?.classList.add("code--verified"), this.promptEl?.setAttribute("hidden", ""), this.footerWaitTimer !== null && (clearTimeout(this.footerWaitTimer), this.footerWaitTimer = null), this.footerEl && (this.footerEl.hidden = !0), this.verifiersEl && (this.verifiersEl.innerHTML = ""), this.currentConfig && this.successEl) {
4371
+ const o = se(this.currentConfig.lang), c = i && i.trim().length > 0 ? o.ui.successGreeting.replace("(Name)", i) : "You're in!";
4372
+ this.successEl.innerHTML = `
4373
+ <span class="success-check" aria-hidden="true">
4374
+ <svg viewBox="0 0 24 24"><path d="M5 12.5 10 17l9-10" /></svg>
4375
+ </span>
4376
+ <span class="success-message">${this.escapeHtml(c)}</span>
4377
+ `, this.successEl.removeAttribute("hidden");
4378
+ }
4379
+ }
4380
+ escapeHtml(i) {
4381
+ return i.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#039;");
4382
+ }
4383
+ renderVerifiers(i) {
4384
+ if (!this.verifiersEl) return;
4385
+ this.verifiersEl.innerHTML = "";
4386
+ const o = this.currentConfig;
4387
+ i.forEach((c) => {
4388
+ const h = document.createElement("a"), C = this.buildLink(c, o.lang);
4389
+ h.href = C, h.target = "_blank", h.rel = "noopener noreferrer", h.addEventListener("click", () => {
4390
+ this.footerWaitTimer !== null && (clearTimeout(this.footerWaitTimer), this.footerWaitTimer = null), this.showFooterWaitingState();
4391
+ });
4392
+ const y = document.createElement("span");
4393
+ y.className = "icon", y.setAttribute("aria-hidden", "true");
4394
+ const f = this.iconForUrl(c);
4395
+ f && (y.innerHTML = f);
4396
+ const m = document.createElement("span");
4397
+ m.className = "label", m.textContent = this.labelForUrl(c, o.lang), f && h.appendChild(y), h.appendChild(m), this.verifiersEl.appendChild(h);
4398
+ });
4399
+ }
4400
+ iconForUrl(i) {
4401
+ try {
4402
+ const o = new URL(i, window.location.origin);
4403
+ if (o.protocol === "mailto:") return mt;
4404
+ if (o.protocol === "whatsapp:" || o.protocol === "whatsapp://") return vt;
4405
+ } catch {
4406
+ if (i.startsWith("mailto:")) return mt;
4407
+ if (i.startsWith("whatsapp:") || i.startsWith("whatsapp://")) return vt;
4408
+ }
4409
+ return null;
4410
+ }
4411
+ labelForUrl(i, o) {
4412
+ const c = se(o);
4413
+ try {
4414
+ const h = new URL(i, window.location.origin);
4415
+ return h.protocol === "mailto:" ? `${c.ui.by} ${c.labels.email}` : h.protocol.startsWith("http") ? h.hostname : h.protocol === "whatsapp:" ? `${c.ui.by} ${c.labels.whatsapp}` : h.protocol.replace(":", "");
4416
+ } catch {
4417
+ return i.startsWith("mailto:") ? `${c.ui.by} ${c.labels.email}` : i.startsWith("whatsapp:") || i.startsWith("whatsapp://") ? `${c.ui.by} ${c.labels.whatsapp}` : i;
4418
+ }
4419
+ }
4420
+ buildLink(i, o) {
4421
+ const c = this.lastCode, h = se(o), C = window.location.host;
4422
+ if (!c) return i;
4423
+ if (i.startsWith("mailto:")) {
4424
+ const [y, f = ""] = i.split("?"), m = new URLSearchParams(f), k = this.applyTemplate(h.templates.emailSubject, C, c), S = this.applyTemplate(h.templates.emailBody, C, c);
4425
+ m.set("subject", k), m.set("body", S);
4426
+ const L = this.toQuery(m);
4427
+ return `${y}?${L}`;
4428
+ }
4429
+ if (i.startsWith("whatsapp:") || i.startsWith("whatsapp://")) {
4430
+ const [y, f = ""] = i.split("?"), m = new URLSearchParams(f), k = this.applyTemplate(h.templates.whatsappText, C, c);
4431
+ m.set("text", k);
4432
+ const S = this.toQuery(m);
4433
+ return `${y}?${S}`;
4434
+ }
4435
+ return i;
4436
+ }
4437
+ applyTemplate(i, o, c) {
4438
+ return i.replaceAll("(Host)", o).replaceAll("(Code)", c);
4439
+ }
4440
+ // Build query string without using URLSearchParams.toString() because it encodes
4441
+ // spaces as '+', which breaks expectations for many mail clients handling mailto:
4442
+ // We use encodeURIComponent so spaces become '%20' and follow RFC 3986 style.
4443
+ toQuery(i) {
4444
+ const o = [];
4445
+ return i.forEach((c, h) => {
4446
+ const C = encodeURIComponent(h), y = encodeURIComponent(c);
4447
+ o.push(`${C}=${y}`);
4448
+ }), o.join("&");
4449
+ }
4450
+ joinUrl(i, o) {
4451
+ return i.endsWith("/") && o.startsWith("/") ? i + o.slice(1) : !i.endsWith("/") && !o.startsWith("/") ? i + "/" + o : i + o;
4452
+ }
4453
+ };
4454
+ ge.tailwindCssText = null, ge.tailwindLoading = null;
4455
+ let Ie = ge;
4456
+ customElements.get("sendity-auth") || customElements.define("sendity-auth", Ie);
4457
+ export {
4458
+ Ie as Sendity
4459
+ };