@genai-fi/base 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +18 -0
  3. package/dist/Button-DQwRVw4a.js +1918 -0
  4. package/dist/DefaultPropsProvider-C0Ib4Mye.js +520 -0
  5. package/dist/DialogQR-BU45QB3i.js +1625 -0
  6. package/dist/FileSaver.min-DhePf63e.js +2397 -0
  7. package/dist/FlashWifi-CaAOKd3g.js +33 -0
  8. package/dist/_commonjsHelpers-DaMA6jEr.js +8 -0
  9. package/dist/assets/AlertPara.css +1 -0
  10. package/dist/assets/ConnectionStatus.css +1 -0
  11. package/dist/assets/DialogQR.css +1 -0
  12. package/dist/assets/Motd.css +1 -0
  13. package/dist/assets/Privacy.css +1 -0
  14. package/dist/assets/Spinner.css +1 -0
  15. package/dist/assets/Webcam.css +1 -0
  16. package/dist/assets/style.css +1 -0
  17. package/dist/assets/theme.css +1 -0
  18. package/dist/colours.module.css +19 -0
  19. package/dist/components/AlertPara/AlertPara.d.ts +8 -0
  20. package/dist/components/AlertPara/AlertPara.js +19 -0
  21. package/dist/components/BusyButton/BusyButton.d.ts +7 -0
  22. package/dist/components/BusyButton/BusyButton.js +25 -0
  23. package/dist/components/Button/Button.d.ts +6 -0
  24. package/dist/components/Button/Button.js +6 -0
  25. package/dist/components/ConnectionStatus/ConnectionStatus.d.ts +12 -0
  26. package/dist/components/ConnectionStatus/ConnectionStatus.js +82 -0
  27. package/dist/components/ConnectionStatus/FlashWifi.d.ts +1 -0
  28. package/dist/components/ConnectionStatus/FlashWifi.js +6 -0
  29. package/dist/components/ConnectionStatus/check.d.ts +1 -0
  30. package/dist/components/ConnectionStatus/check.js +10 -0
  31. package/dist/components/ConnectionStatus/ice.d.ts +13 -0
  32. package/dist/components/ConnectionStatus/ice.js +12 -0
  33. package/dist/components/ContentLoader/ContentError.d.ts +5 -0
  34. package/dist/components/ContentLoader/ContentError.js +21 -0
  35. package/dist/components/ContentLoader/ContentLoader.d.ts +8 -0
  36. package/dist/components/ContentLoader/ContentLoader.js +51 -0
  37. package/dist/components/ContentLoader/ContentProgress.d.ts +6 -0
  38. package/dist/components/ContentLoader/ContentProgress.js +31 -0
  39. package/dist/components/Motd/Motd.d.ts +5 -0
  40. package/dist/components/Motd/Motd.js +48 -0
  41. package/dist/components/Privacy/Privacy.d.ts +7 -0
  42. package/dist/components/Privacy/Privacy.js +57 -0
  43. package/dist/components/QRCode/DialogQR.d.ts +7 -0
  44. package/dist/components/QRCode/DialogQR.js +14 -0
  45. package/dist/components/QRCode/QRCode.d.ts +9 -0
  46. package/dist/components/QRCode/QRCode.js +61 -0
  47. package/dist/components/Spinner/Spinner.d.ts +6 -0
  48. package/dist/components/Spinner/Spinner.js +33 -0
  49. package/dist/components/Webcam/Webcam.d.ts +15 -0
  50. package/dist/components/Webcam/Webcam.js +397 -0
  51. package/dist/components/Webcam/webcamClass.d.ts +32 -0
  52. package/dist/components/Webcam/webcamClass.js +76 -0
  53. package/dist/createSvgIcon-BfF8yuCp.js +249 -0
  54. package/dist/createTheme-BIcG8YPQ.js +2895 -0
  55. package/dist/hooks/id.d.ts +1 -0
  56. package/dist/hooks/id.js +16 -0
  57. package/dist/hooks/onlyOnce.d.ts +1 -0
  58. package/dist/hooks/onlyOnce.js +7 -0
  59. package/dist/hooks/peer.d.ts +25 -0
  60. package/dist/hooks/peer.js +70 -0
  61. package/dist/hooks/random.d.ts +1 -0
  62. package/dist/hooks/random.js +9 -0
  63. package/dist/hooks/useTabActive.d.ts +1 -0
  64. package/dist/hooks/useTabActive.js +17 -0
  65. package/dist/index-SOhdqzHq.js +113 -0
  66. package/dist/main.d.ts +21 -0
  67. package/dist/main.js +49 -0
  68. package/dist/react-D-b-Xrzv.js +98 -0
  69. package/dist/services/peer2peer/Incoming.d.ts +13 -0
  70. package/dist/services/peer2peer/Incoming.js +39 -0
  71. package/dist/services/peer2peer/Outgoing.d.ts +25 -0
  72. package/dist/services/peer2peer/Outgoing.js +65 -0
  73. package/dist/services/peer2peer/Peer2Peer.d.ts +80 -0
  74. package/dist/services/peer2peer/Peer2Peer.js +3367 -0
  75. package/dist/services/peer2peer/PeerConnection.d.ts +40 -0
  76. package/dist/services/peer2peer/PeerConnection.js +155 -0
  77. package/dist/services/peer2peer/error.d.ts +2 -0
  78. package/dist/services/peer2peer/error.js +5 -0
  79. package/dist/services/peer2peer/types.d.ts +38 -0
  80. package/dist/services/peer2peer/types.js +1 -0
  81. package/dist/state/webrtcState.d.ts +12 -0
  82. package/dist/state/webrtcState.js +6 -0
  83. package/dist/style/theme.d.ts +1 -0
  84. package/dist/style/theme.js +33 -0
  85. package/dist/style.module-DSFm2eLD.js +9 -0
  86. package/dist/util/backoff.d.ts +1 -0
  87. package/dist/util/backoff.js +6 -0
  88. package/dist/util/base64.d.ts +2 -0
  89. package/dist/util/base64.js +19 -0
  90. package/dist/util/canvas.d.ts +7 -0
  91. package/dist/util/canvas.js +92 -0
  92. package/dist/util/crypto.d.ts +7 -0
  93. package/dist/util/crypto.js +50 -0
  94. package/dist/util/randomId.d.ts +1 -0
  95. package/dist/util/randomId.js +8 -0
  96. package/dist/util/zip.d.ts +13 -0
  97. package/dist/util/zip.js +94 -0
  98. package/dist/webrtcState-D0nJpE9Z.js +406 -0
  99. package/package.json +88 -0
@@ -0,0 +1,3367 @@
1
+ var ft = Object.defineProperty;
2
+ var ht = (r) => {
3
+ throw TypeError(r);
4
+ };
5
+ var lt = (r, e, t) => e in r ? ft(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
6
+ var m = (r, e, t) => lt(r, typeof e != "symbol" ? e + "" : e, t);
7
+ var M = (r, e, t) => e.has(r) ? ht("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(r) : e.set(r, t);
8
+ import { g as ut } from "../../_commonjsHelpers-DaMA6jEr.js";
9
+ import { E as dt } from "../../index-SOhdqzHq.js";
10
+ import q from "./PeerConnection.js";
11
+ import mt from "./Outgoing.js";
12
+ import gt from "./Incoming.js";
13
+ function yt(r, e) {
14
+ for (var t = 0; t < e.length; t++) {
15
+ const n = e[t];
16
+ if (typeof n != "string" && !Array.isArray(n)) {
17
+ for (const i in n)
18
+ if (i !== "default" && !(i in r)) {
19
+ const s = Object.getOwnPropertyDescriptor(n, i);
20
+ s && Object.defineProperty(r, i, s.get ? s : {
21
+ enumerable: !0,
22
+ get: () => n[i]
23
+ });
24
+ }
25
+ }
26
+ }
27
+ return Object.freeze(Object.defineProperty(r, Symbol.toStringTag, { value: "Module" }));
28
+ }
29
+ class _t {
30
+ constructor() {
31
+ this.encoder = new TextEncoder(), this._pieces = [], this._parts = [];
32
+ }
33
+ append_buffer(e) {
34
+ this.flush(), this._parts.push(e);
35
+ }
36
+ append(e) {
37
+ this._pieces.push(e);
38
+ }
39
+ flush() {
40
+ if (this._pieces.length > 0) {
41
+ const e = new Uint8Array(this._pieces);
42
+ this._parts.push(e), this._pieces = [];
43
+ }
44
+ }
45
+ toArrayBuffer() {
46
+ const e = [];
47
+ for (const t of this._parts) e.push(t);
48
+ return Ct(e).buffer;
49
+ }
50
+ }
51
+ function Ct(r) {
52
+ let e = 0;
53
+ for (const i of r) e += i.byteLength;
54
+ const t = new Uint8Array(e);
55
+ let n = 0;
56
+ for (const i of r) {
57
+ const s = new Uint8Array(i.buffer, i.byteOffset, i.byteLength);
58
+ t.set(s, n), n += i.byteLength;
59
+ }
60
+ return t;
61
+ }
62
+ function Te(r) {
63
+ return new bt(r).unpack();
64
+ }
65
+ function Re(r) {
66
+ const e = new vt(), t = e.pack(r);
67
+ return t instanceof Promise ? t.then(() => e.getBuffer()) : e.getBuffer();
68
+ }
69
+ class bt {
70
+ constructor(e) {
71
+ this.index = 0, this.dataBuffer = e, this.dataView = new Uint8Array(this.dataBuffer), this.length = this.dataBuffer.byteLength;
72
+ }
73
+ unpack() {
74
+ const e = this.unpack_uint8();
75
+ if (e < 128) return e;
76
+ if ((e ^ 224) < 32) return (e ^ 224) - 32;
77
+ let t;
78
+ if ((t = e ^ 160) <= 15) return this.unpack_raw(t);
79
+ if ((t = e ^ 176) <= 15) return this.unpack_string(t);
80
+ if ((t = e ^ 144) <= 15) return this.unpack_array(t);
81
+ if ((t = e ^ 128) <= 15) return this.unpack_map(t);
82
+ switch (e) {
83
+ case 192:
84
+ return null;
85
+ case 193:
86
+ return;
87
+ case 194:
88
+ return !1;
89
+ case 195:
90
+ return !0;
91
+ case 202:
92
+ return this.unpack_float();
93
+ case 203:
94
+ return this.unpack_double();
95
+ case 204:
96
+ return this.unpack_uint8();
97
+ case 205:
98
+ return this.unpack_uint16();
99
+ case 206:
100
+ return this.unpack_uint32();
101
+ case 207:
102
+ return this.unpack_uint64();
103
+ case 208:
104
+ return this.unpack_int8();
105
+ case 209:
106
+ return this.unpack_int16();
107
+ case 210:
108
+ return this.unpack_int32();
109
+ case 211:
110
+ return this.unpack_int64();
111
+ case 212:
112
+ return;
113
+ case 213:
114
+ return;
115
+ case 214:
116
+ return;
117
+ case 215:
118
+ return;
119
+ case 216:
120
+ return t = this.unpack_uint16(), this.unpack_string(t);
121
+ case 217:
122
+ return t = this.unpack_uint32(), this.unpack_string(t);
123
+ case 218:
124
+ return t = this.unpack_uint16(), this.unpack_raw(t);
125
+ case 219:
126
+ return t = this.unpack_uint32(), this.unpack_raw(t);
127
+ case 220:
128
+ return t = this.unpack_uint16(), this.unpack_array(t);
129
+ case 221:
130
+ return t = this.unpack_uint32(), this.unpack_array(t);
131
+ case 222:
132
+ return t = this.unpack_uint16(), this.unpack_map(t);
133
+ case 223:
134
+ return t = this.unpack_uint32(), this.unpack_map(t);
135
+ }
136
+ }
137
+ unpack_uint8() {
138
+ const e = this.dataView[this.index] & 255;
139
+ return this.index++, e;
140
+ }
141
+ unpack_uint16() {
142
+ const e = this.read(2), t = (e[0] & 255) * 256 + (e[1] & 255);
143
+ return this.index += 2, t;
144
+ }
145
+ unpack_uint32() {
146
+ const e = this.read(4), t = ((e[0] * 256 + e[1]) * 256 + e[2]) * 256 + e[3];
147
+ return this.index += 4, t;
148
+ }
149
+ unpack_uint64() {
150
+ const e = this.read(8), t = ((((((e[0] * 256 + e[1]) * 256 + e[2]) * 256 + e[3]) * 256 + e[4]) * 256 + e[5]) * 256 + e[6]) * 256 + e[7];
151
+ return this.index += 8, t;
152
+ }
153
+ unpack_int8() {
154
+ const e = this.unpack_uint8();
155
+ return e < 128 ? e : e - 256;
156
+ }
157
+ unpack_int16() {
158
+ const e = this.unpack_uint16();
159
+ return e < 32768 ? e : e - 65536;
160
+ }
161
+ unpack_int32() {
162
+ const e = this.unpack_uint32();
163
+ return e < 2 ** 31 ? e : e - 2 ** 32;
164
+ }
165
+ unpack_int64() {
166
+ const e = this.unpack_uint64();
167
+ return e < 2 ** 63 ? e : e - 2 ** 64;
168
+ }
169
+ unpack_raw(e) {
170
+ if (this.length < this.index + e) throw new Error(`BinaryPackFailure: index is out of range ${this.index} ${e} ${this.length}`);
171
+ const t = this.dataBuffer.slice(this.index, this.index + e);
172
+ return this.index += e, t;
173
+ }
174
+ unpack_string(e) {
175
+ const t = this.read(e);
176
+ let n = 0, i = "", s, o;
177
+ for (; n < e; )
178
+ s = t[n], s < 160 ? (o = s, n++) : (s ^ 192) < 32 ? (o = (s & 31) << 6 | t[n + 1] & 63, n += 2) : (s ^ 224) < 16 ? (o = (s & 15) << 12 | (t[n + 1] & 63) << 6 | t[n + 2] & 63, n += 3) : (o = (s & 7) << 18 | (t[n + 1] & 63) << 12 | (t[n + 2] & 63) << 6 | t[n + 3] & 63, n += 4), i += String.fromCodePoint(o);
179
+ return this.index += e, i;
180
+ }
181
+ unpack_array(e) {
182
+ const t = new Array(e);
183
+ for (let n = 0; n < e; n++) t[n] = this.unpack();
184
+ return t;
185
+ }
186
+ unpack_map(e) {
187
+ const t = {};
188
+ for (let n = 0; n < e; n++) {
189
+ const i = this.unpack();
190
+ t[i] = this.unpack();
191
+ }
192
+ return t;
193
+ }
194
+ unpack_float() {
195
+ const e = this.unpack_uint32(), t = e >> 31, n = (e >> 23 & 255) - 127, i = e & 8388607 | 8388608;
196
+ return (t === 0 ? 1 : -1) * i * 2 ** (n - 23);
197
+ }
198
+ unpack_double() {
199
+ const e = this.unpack_uint32(), t = this.unpack_uint32(), n = e >> 31, i = (e >> 20 & 2047) - 1023, o = (e & 1048575 | 1048576) * 2 ** (i - 20) + t * 2 ** (i - 52);
200
+ return (n === 0 ? 1 : -1) * o;
201
+ }
202
+ read(e) {
203
+ const t = this.index;
204
+ if (t + e <= this.length) return this.dataView.subarray(t, t + e);
205
+ throw new Error("BinaryPackFailure: read index out of range");
206
+ }
207
+ }
208
+ class vt {
209
+ getBuffer() {
210
+ return this._bufferBuilder.toArrayBuffer();
211
+ }
212
+ pack(e) {
213
+ if (typeof e == "string") this.pack_string(e);
214
+ else if (typeof e == "number")
215
+ Math.floor(e) === e ? this.pack_integer(e) : this.pack_double(e);
216
+ else if (typeof e == "boolean")
217
+ e === !0 ? this._bufferBuilder.append(195) : e === !1 && this._bufferBuilder.append(194);
218
+ else if (e === void 0) this._bufferBuilder.append(192);
219
+ else if (typeof e == "object")
220
+ if (e === null) this._bufferBuilder.append(192);
221
+ else {
222
+ const t = e.constructor;
223
+ if (e instanceof Array) {
224
+ const n = this.pack_array(e);
225
+ if (n instanceof Promise) return n.then(() => this._bufferBuilder.flush());
226
+ } else if (e instanceof ArrayBuffer) this.pack_bin(new Uint8Array(e));
227
+ else if ("BYTES_PER_ELEMENT" in e) {
228
+ const n = e;
229
+ this.pack_bin(new Uint8Array(n.buffer, n.byteOffset, n.byteLength));
230
+ } else if (e instanceof Date) this.pack_string(e.toString());
231
+ else {
232
+ if (e instanceof Blob) return e.arrayBuffer().then((n) => {
233
+ this.pack_bin(new Uint8Array(n)), this._bufferBuilder.flush();
234
+ });
235
+ if (t == Object || t.toString().startsWith("class")) {
236
+ const n = this.pack_object(e);
237
+ if (n instanceof Promise) return n.then(() => this._bufferBuilder.flush());
238
+ } else throw new Error(`Type "${t.toString()}" not yet supported`);
239
+ }
240
+ }
241
+ else throw new Error(`Type "${typeof e}" not yet supported`);
242
+ this._bufferBuilder.flush();
243
+ }
244
+ pack_bin(e) {
245
+ const t = e.length;
246
+ if (t <= 15) this.pack_uint8(160 + t);
247
+ else if (t <= 65535)
248
+ this._bufferBuilder.append(218), this.pack_uint16(t);
249
+ else if (t <= 4294967295)
250
+ this._bufferBuilder.append(219), this.pack_uint32(t);
251
+ else throw new Error("Invalid length");
252
+ this._bufferBuilder.append_buffer(e);
253
+ }
254
+ pack_string(e) {
255
+ const t = this._textEncoder.encode(e), n = t.length;
256
+ if (n <= 15) this.pack_uint8(176 + n);
257
+ else if (n <= 65535)
258
+ this._bufferBuilder.append(216), this.pack_uint16(n);
259
+ else if (n <= 4294967295)
260
+ this._bufferBuilder.append(217), this.pack_uint32(n);
261
+ else throw new Error("Invalid length");
262
+ this._bufferBuilder.append_buffer(t);
263
+ }
264
+ pack_array(e) {
265
+ const t = e.length;
266
+ if (t <= 15) this.pack_uint8(144 + t);
267
+ else if (t <= 65535)
268
+ this._bufferBuilder.append(220), this.pack_uint16(t);
269
+ else if (t <= 4294967295)
270
+ this._bufferBuilder.append(221), this.pack_uint32(t);
271
+ else throw new Error("Invalid length");
272
+ const n = (i) => {
273
+ if (i < t) {
274
+ const s = this.pack(e[i]);
275
+ return s instanceof Promise ? s.then(() => n(i + 1)) : n(i + 1);
276
+ }
277
+ };
278
+ return n(0);
279
+ }
280
+ pack_integer(e) {
281
+ if (e >= -32 && e <= 127) this._bufferBuilder.append(e & 255);
282
+ else if (e >= 0 && e <= 255)
283
+ this._bufferBuilder.append(204), this.pack_uint8(e);
284
+ else if (e >= -128 && e <= 127)
285
+ this._bufferBuilder.append(208), this.pack_int8(e);
286
+ else if (e >= 0 && e <= 65535)
287
+ this._bufferBuilder.append(205), this.pack_uint16(e);
288
+ else if (e >= -32768 && e <= 32767)
289
+ this._bufferBuilder.append(209), this.pack_int16(e);
290
+ else if (e >= 0 && e <= 4294967295)
291
+ this._bufferBuilder.append(206), this.pack_uint32(e);
292
+ else if (e >= -2147483648 && e <= 2147483647)
293
+ this._bufferBuilder.append(210), this.pack_int32(e);
294
+ else if (e >= -9223372036854776e3 && e <= 9223372036854776e3)
295
+ this._bufferBuilder.append(211), this.pack_int64(e);
296
+ else if (e >= 0 && e <= 18446744073709552e3)
297
+ this._bufferBuilder.append(207), this.pack_uint64(e);
298
+ else throw new Error("Invalid integer");
299
+ }
300
+ pack_double(e) {
301
+ let t = 0;
302
+ e < 0 && (t = 1, e = -e);
303
+ const n = Math.floor(Math.log(e) / Math.LN2), i = e / 2 ** n - 1, s = Math.floor(i * 2 ** 52), o = 2 ** 32, a = t << 31 | n + 1023 << 20 | s / o & 1048575, c = s % o;
304
+ this._bufferBuilder.append(203), this.pack_int32(a), this.pack_int32(c);
305
+ }
306
+ pack_object(e) {
307
+ const t = Object.keys(e), n = t.length;
308
+ if (n <= 15) this.pack_uint8(128 + n);
309
+ else if (n <= 65535)
310
+ this._bufferBuilder.append(222), this.pack_uint16(n);
311
+ else if (n <= 4294967295)
312
+ this._bufferBuilder.append(223), this.pack_uint32(n);
313
+ else throw new Error("Invalid length");
314
+ const i = (s) => {
315
+ if (s < t.length) {
316
+ const o = t[s];
317
+ if (e.hasOwnProperty(o)) {
318
+ this.pack(o);
319
+ const a = this.pack(e[o]);
320
+ if (a instanceof Promise) return a.then(() => i(s + 1));
321
+ }
322
+ return i(s + 1);
323
+ }
324
+ };
325
+ return i(0);
326
+ }
327
+ pack_uint8(e) {
328
+ this._bufferBuilder.append(e);
329
+ }
330
+ pack_uint16(e) {
331
+ this._bufferBuilder.append(e >> 8), this._bufferBuilder.append(e & 255);
332
+ }
333
+ pack_uint32(e) {
334
+ const t = e & 4294967295;
335
+ this._bufferBuilder.append((t & 4278190080) >>> 24), this._bufferBuilder.append((t & 16711680) >>> 16), this._bufferBuilder.append((t & 65280) >>> 8), this._bufferBuilder.append(t & 255);
336
+ }
337
+ pack_uint64(e) {
338
+ const t = e / 4294967296, n = e % 2 ** 32;
339
+ this._bufferBuilder.append((t & 4278190080) >>> 24), this._bufferBuilder.append((t & 16711680) >>> 16), this._bufferBuilder.append((t & 65280) >>> 8), this._bufferBuilder.append(t & 255), this._bufferBuilder.append((n & 4278190080) >>> 24), this._bufferBuilder.append((n & 16711680) >>> 16), this._bufferBuilder.append((n & 65280) >>> 8), this._bufferBuilder.append(n & 255);
340
+ }
341
+ pack_int8(e) {
342
+ this._bufferBuilder.append(e & 255);
343
+ }
344
+ pack_int16(e) {
345
+ this._bufferBuilder.append((e & 65280) >> 8), this._bufferBuilder.append(e & 255);
346
+ }
347
+ pack_int32(e) {
348
+ this._bufferBuilder.append(e >>> 24 & 255), this._bufferBuilder.append((e & 16711680) >>> 16), this._bufferBuilder.append((e & 65280) >>> 8), this._bufferBuilder.append(e & 255);
349
+ }
350
+ pack_int64(e) {
351
+ const t = Math.floor(e / 4294967296), n = e % 2 ** 32;
352
+ this._bufferBuilder.append((t & 4278190080) >>> 24), this._bufferBuilder.append((t & 16711680) >>> 16), this._bufferBuilder.append((t & 65280) >>> 8), this._bufferBuilder.append(t & 255), this._bufferBuilder.append((n & 4278190080) >>> 24), this._bufferBuilder.append((n & 16711680) >>> 16), this._bufferBuilder.append((n & 65280) >>> 8), this._bufferBuilder.append(n & 255);
353
+ }
354
+ constructor() {
355
+ this._bufferBuilder = new _t(), this._textEncoder = new TextEncoder();
356
+ }
357
+ }
358
+ let xe = !0, Pe = !0;
359
+ function U(r, e, t) {
360
+ const n = r.match(e);
361
+ return n && n.length >= t && parseInt(n[t], 10);
362
+ }
363
+ function x(r, e, t) {
364
+ if (!r.RTCPeerConnection)
365
+ return;
366
+ const n = r.RTCPeerConnection.prototype, i = n.addEventListener;
367
+ n.addEventListener = function(o, a) {
368
+ if (o !== e)
369
+ return i.apply(this, arguments);
370
+ const c = (p) => {
371
+ const f = t(p);
372
+ f && (a.handleEvent ? a.handleEvent(f) : a(f));
373
+ };
374
+ return this._eventMap = this._eventMap || {}, this._eventMap[e] || (this._eventMap[e] = /* @__PURE__ */ new Map()), this._eventMap[e].set(a, c), i.apply(this, [
375
+ o,
376
+ c
377
+ ]);
378
+ };
379
+ const s = n.removeEventListener;
380
+ n.removeEventListener = function(o, a) {
381
+ if (o !== e || !this._eventMap || !this._eventMap[e])
382
+ return s.apply(this, arguments);
383
+ if (!this._eventMap[e].has(a))
384
+ return s.apply(this, arguments);
385
+ const c = this._eventMap[e].get(a);
386
+ return this._eventMap[e].delete(a), this._eventMap[e].size === 0 && delete this._eventMap[e], Object.keys(this._eventMap).length === 0 && delete this._eventMap, s.apply(this, [
387
+ o,
388
+ c
389
+ ]);
390
+ }, Object.defineProperty(n, "on" + e, {
391
+ get() {
392
+ return this["_on" + e];
393
+ },
394
+ set(o) {
395
+ this["_on" + e] && (this.removeEventListener(
396
+ e,
397
+ this["_on" + e]
398
+ ), delete this["_on" + e]), o && this.addEventListener(
399
+ e,
400
+ this["_on" + e] = o
401
+ );
402
+ },
403
+ enumerable: !0,
404
+ configurable: !0
405
+ });
406
+ }
407
+ function kt(r) {
408
+ return typeof r != "boolean" ? new Error("Argument type: " + typeof r + ". Please use a boolean.") : (xe = r, r ? "adapter.js logging disabled" : "adapter.js logging enabled");
409
+ }
410
+ function St(r) {
411
+ return typeof r != "boolean" ? new Error("Argument type: " + typeof r + ". Please use a boolean.") : (Pe = !r, "adapter.js deprecation warnings " + (r ? "disabled" : "enabled"));
412
+ }
413
+ function Ee() {
414
+ if (typeof window == "object") {
415
+ if (xe)
416
+ return;
417
+ typeof console < "u" && typeof console.log == "function" && console.log.apply(console, arguments);
418
+ }
419
+ }
420
+ function pe(r, e) {
421
+ Pe && console.warn(r + " is deprecated, please use " + e + " instead.");
422
+ }
423
+ function Tt(r) {
424
+ const e = { browser: null, version: null };
425
+ if (typeof r > "u" || !r.navigator || !r.navigator.userAgent)
426
+ return e.browser = "Not a browser.", e;
427
+ const { navigator: t } = r;
428
+ if (t.userAgentData && t.userAgentData.brands) {
429
+ const n = t.userAgentData.brands.find((i) => i.brand === "Chromium");
430
+ if (n)
431
+ return { browser: "chrome", version: parseInt(n.version, 10) };
432
+ }
433
+ if (t.mozGetUserMedia)
434
+ e.browser = "firefox", e.version = U(
435
+ t.userAgent,
436
+ /Firefox\/(\d+)\./,
437
+ 1
438
+ );
439
+ else if (t.webkitGetUserMedia || r.isSecureContext === !1 && r.webkitRTCPeerConnection)
440
+ e.browser = "chrome", e.version = U(
441
+ t.userAgent,
442
+ /Chrom(e|ium)\/(\d+)\./,
443
+ 2
444
+ );
445
+ else if (r.RTCPeerConnection && t.userAgent.match(/AppleWebKit\/(\d+)\./))
446
+ e.browser = "safari", e.version = U(
447
+ t.userAgent,
448
+ /AppleWebKit\/(\d+)\./,
449
+ 1
450
+ ), e.supportsUnifiedPlan = r.RTCRtpTransceiver && "currentDirection" in r.RTCRtpTransceiver.prototype;
451
+ else
452
+ return e.browser = "Not a supported browser.", e;
453
+ return e;
454
+ }
455
+ function ue(r) {
456
+ return Object.prototype.toString.call(r) === "[object Object]";
457
+ }
458
+ function De(r) {
459
+ return ue(r) ? Object.keys(r).reduce(function(e, t) {
460
+ const n = ue(r[t]), i = n ? De(r[t]) : r[t], s = n && !Object.keys(i).length;
461
+ return i === void 0 || s ? e : Object.assign(e, { [t]: i });
462
+ }, {}) : r;
463
+ }
464
+ function Z(r, e, t) {
465
+ !e || t.has(e.id) || (t.set(e.id, e), Object.keys(e).forEach((n) => {
466
+ n.endsWith("Id") ? Z(r, r.get(e[n]), t) : n.endsWith("Ids") && e[n].forEach((i) => {
467
+ Z(r, r.get(i), t);
468
+ });
469
+ }));
470
+ }
471
+ function de(r, e, t) {
472
+ const n = t ? "outbound-rtp" : "inbound-rtp", i = /* @__PURE__ */ new Map();
473
+ if (e === null)
474
+ return i;
475
+ const s = [];
476
+ return r.forEach((o) => {
477
+ o.type === "track" && o.trackIdentifier === e.id && s.push(o);
478
+ }), s.forEach((o) => {
479
+ r.forEach((a) => {
480
+ a.type === n && a.trackId === o.id && Z(r, a, i);
481
+ });
482
+ }), i;
483
+ }
484
+ const me = Ee;
485
+ function Ie(r, e) {
486
+ const t = r && r.navigator;
487
+ if (!t.mediaDevices)
488
+ return;
489
+ const n = function(a) {
490
+ if (typeof a != "object" || a.mandatory || a.optional)
491
+ return a;
492
+ const c = {};
493
+ return Object.keys(a).forEach((p) => {
494
+ if (p === "require" || p === "advanced" || p === "mediaSource")
495
+ return;
496
+ const f = typeof a[p] == "object" ? a[p] : { ideal: a[p] };
497
+ f.exact !== void 0 && typeof f.exact == "number" && (f.min = f.max = f.exact);
498
+ const h = function(l, d) {
499
+ return l ? l + d.charAt(0).toUpperCase() + d.slice(1) : d === "deviceId" ? "sourceId" : d;
500
+ };
501
+ if (f.ideal !== void 0) {
502
+ c.optional = c.optional || [];
503
+ let l = {};
504
+ typeof f.ideal == "number" ? (l[h("min", p)] = f.ideal, c.optional.push(l), l = {}, l[h("max", p)] = f.ideal, c.optional.push(l)) : (l[h("", p)] = f.ideal, c.optional.push(l));
505
+ }
506
+ f.exact !== void 0 && typeof f.exact != "number" ? (c.mandatory = c.mandatory || {}, c.mandatory[h("", p)] = f.exact) : ["min", "max"].forEach((l) => {
507
+ f[l] !== void 0 && (c.mandatory = c.mandatory || {}, c.mandatory[h(l, p)] = f[l]);
508
+ });
509
+ }), a.advanced && (c.optional = (c.optional || []).concat(a.advanced)), c;
510
+ }, i = function(a, c) {
511
+ if (e.version >= 61)
512
+ return c(a);
513
+ if (a = JSON.parse(JSON.stringify(a)), a && typeof a.audio == "object") {
514
+ const p = function(f, h, l) {
515
+ h in f && !(l in f) && (f[l] = f[h], delete f[h]);
516
+ };
517
+ a = JSON.parse(JSON.stringify(a)), p(a.audio, "autoGainControl", "googAutoGainControl"), p(a.audio, "noiseSuppression", "googNoiseSuppression"), a.audio = n(a.audio);
518
+ }
519
+ if (a && typeof a.video == "object") {
520
+ let p = a.video.facingMode;
521
+ p = p && (typeof p == "object" ? p : { ideal: p });
522
+ const f = e.version < 66;
523
+ if (p && (p.exact === "user" || p.exact === "environment" || p.ideal === "user" || p.ideal === "environment") && !(t.mediaDevices.getSupportedConstraints && t.mediaDevices.getSupportedConstraints().facingMode && !f)) {
524
+ delete a.video.facingMode;
525
+ let h;
526
+ if (p.exact === "environment" || p.ideal === "environment" ? h = ["back", "rear"] : (p.exact === "user" || p.ideal === "user") && (h = ["front"]), h)
527
+ return t.mediaDevices.enumerateDevices().then((l) => {
528
+ l = l.filter((y) => y.kind === "videoinput");
529
+ let d = l.find((y) => h.some((b) => y.label.toLowerCase().includes(b)));
530
+ return !d && l.length && h.includes("back") && (d = l[l.length - 1]), d && (a.video.deviceId = p.exact ? { exact: d.deviceId } : { ideal: d.deviceId }), a.video = n(a.video), me("chrome: " + JSON.stringify(a)), c(a);
531
+ });
532
+ }
533
+ a.video = n(a.video);
534
+ }
535
+ return me("chrome: " + JSON.stringify(a)), c(a);
536
+ }, s = function(a) {
537
+ return e.version >= 64 ? a : {
538
+ name: {
539
+ PermissionDeniedError: "NotAllowedError",
540
+ PermissionDismissedError: "NotAllowedError",
541
+ InvalidStateError: "NotAllowedError",
542
+ DevicesNotFoundError: "NotFoundError",
543
+ ConstraintNotSatisfiedError: "OverconstrainedError",
544
+ TrackStartError: "NotReadableError",
545
+ MediaDeviceFailedDueToShutdown: "NotAllowedError",
546
+ MediaDeviceKillSwitchOn: "NotAllowedError",
547
+ TabCaptureError: "AbortError",
548
+ ScreenCaptureError: "AbortError",
549
+ DeviceCaptureError: "AbortError"
550
+ }[a.name] || a.name,
551
+ message: a.message,
552
+ constraint: a.constraint || a.constraintName,
553
+ toString() {
554
+ return this.name + (this.message && ": ") + this.message;
555
+ }
556
+ };
557
+ }, o = function(a, c, p) {
558
+ i(a, (f) => {
559
+ t.webkitGetUserMedia(f, c, (h) => {
560
+ p && p(s(h));
561
+ });
562
+ });
563
+ };
564
+ if (t.getUserMedia = o.bind(t), t.mediaDevices.getUserMedia) {
565
+ const a = t.mediaDevices.getUserMedia.bind(t.mediaDevices);
566
+ t.mediaDevices.getUserMedia = function(c) {
567
+ return i(c, (p) => a(p).then((f) => {
568
+ if (p.audio && !f.getAudioTracks().length || p.video && !f.getVideoTracks().length)
569
+ throw f.getTracks().forEach((h) => {
570
+ h.stop();
571
+ }), new DOMException("", "NotFoundError");
572
+ return f;
573
+ }, (f) => Promise.reject(s(f))));
574
+ };
575
+ }
576
+ }
577
+ function Me(r) {
578
+ r.MediaStream = r.MediaStream || r.webkitMediaStream;
579
+ }
580
+ function Oe(r) {
581
+ if (typeof r == "object" && r.RTCPeerConnection && !("ontrack" in r.RTCPeerConnection.prototype)) {
582
+ Object.defineProperty(r.RTCPeerConnection.prototype, "ontrack", {
583
+ get() {
584
+ return this._ontrack;
585
+ },
586
+ set(t) {
587
+ this._ontrack && this.removeEventListener("track", this._ontrack), this.addEventListener("track", this._ontrack = t);
588
+ },
589
+ enumerable: !0,
590
+ configurable: !0
591
+ });
592
+ const e = r.RTCPeerConnection.prototype.setRemoteDescription;
593
+ r.RTCPeerConnection.prototype.setRemoteDescription = function() {
594
+ return this._ontrackpoly || (this._ontrackpoly = (n) => {
595
+ n.stream.addEventListener("addtrack", (i) => {
596
+ let s;
597
+ r.RTCPeerConnection.prototype.getReceivers ? s = this.getReceivers().find((a) => a.track && a.track.id === i.track.id) : s = { track: i.track };
598
+ const o = new Event("track");
599
+ o.track = i.track, o.receiver = s, o.transceiver = { receiver: s }, o.streams = [n.stream], this.dispatchEvent(o);
600
+ }), n.stream.getTracks().forEach((i) => {
601
+ let s;
602
+ r.RTCPeerConnection.prototype.getReceivers ? s = this.getReceivers().find((a) => a.track && a.track.id === i.id) : s = { track: i };
603
+ const o = new Event("track");
604
+ o.track = i, o.receiver = s, o.transceiver = { receiver: s }, o.streams = [n.stream], this.dispatchEvent(o);
605
+ });
606
+ }, this.addEventListener("addstream", this._ontrackpoly)), e.apply(this, arguments);
607
+ };
608
+ } else
609
+ x(r, "track", (e) => (e.transceiver || Object.defineProperty(
610
+ e,
611
+ "transceiver",
612
+ { value: { receiver: e.receiver } }
613
+ ), e));
614
+ }
615
+ function Ae(r) {
616
+ if (typeof r == "object" && r.RTCPeerConnection && !("getSenders" in r.RTCPeerConnection.prototype) && "createDTMFSender" in r.RTCPeerConnection.prototype) {
617
+ const e = function(i, s) {
618
+ return {
619
+ track: s,
620
+ get dtmf() {
621
+ return this._dtmf === void 0 && (s.kind === "audio" ? this._dtmf = i.createDTMFSender(s) : this._dtmf = null), this._dtmf;
622
+ },
623
+ _pc: i
624
+ };
625
+ };
626
+ if (!r.RTCPeerConnection.prototype.getSenders) {
627
+ r.RTCPeerConnection.prototype.getSenders = function() {
628
+ return this._senders = this._senders || [], this._senders.slice();
629
+ };
630
+ const i = r.RTCPeerConnection.prototype.addTrack;
631
+ r.RTCPeerConnection.prototype.addTrack = function(a, c) {
632
+ let p = i.apply(this, arguments);
633
+ return p || (p = e(this, a), this._senders.push(p)), p;
634
+ };
635
+ const s = r.RTCPeerConnection.prototype.removeTrack;
636
+ r.RTCPeerConnection.prototype.removeTrack = function(a) {
637
+ s.apply(this, arguments);
638
+ const c = this._senders.indexOf(a);
639
+ c !== -1 && this._senders.splice(c, 1);
640
+ };
641
+ }
642
+ const t = r.RTCPeerConnection.prototype.addStream;
643
+ r.RTCPeerConnection.prototype.addStream = function(s) {
644
+ this._senders = this._senders || [], t.apply(this, [s]), s.getTracks().forEach((o) => {
645
+ this._senders.push(e(this, o));
646
+ });
647
+ };
648
+ const n = r.RTCPeerConnection.prototype.removeStream;
649
+ r.RTCPeerConnection.prototype.removeStream = function(s) {
650
+ this._senders = this._senders || [], n.apply(this, [s]), s.getTracks().forEach((o) => {
651
+ const a = this._senders.find((c) => c.track === o);
652
+ a && this._senders.splice(this._senders.indexOf(a), 1);
653
+ });
654
+ };
655
+ } else if (typeof r == "object" && r.RTCPeerConnection && "getSenders" in r.RTCPeerConnection.prototype && "createDTMFSender" in r.RTCPeerConnection.prototype && r.RTCRtpSender && !("dtmf" in r.RTCRtpSender.prototype)) {
656
+ const e = r.RTCPeerConnection.prototype.getSenders;
657
+ r.RTCPeerConnection.prototype.getSenders = function() {
658
+ const n = e.apply(this, []);
659
+ return n.forEach((i) => i._pc = this), n;
660
+ }, Object.defineProperty(r.RTCRtpSender.prototype, "dtmf", {
661
+ get() {
662
+ return this._dtmf === void 0 && (this.track.kind === "audio" ? this._dtmf = this._pc.createDTMFSender(this.track) : this._dtmf = null), this._dtmf;
663
+ }
664
+ });
665
+ }
666
+ }
667
+ function $e(r) {
668
+ if (!(typeof r == "object" && r.RTCPeerConnection && r.RTCRtpSender && r.RTCRtpReceiver))
669
+ return;
670
+ if (!("getStats" in r.RTCRtpSender.prototype)) {
671
+ const t = r.RTCPeerConnection.prototype.getSenders;
672
+ t && (r.RTCPeerConnection.prototype.getSenders = function() {
673
+ const s = t.apply(this, []);
674
+ return s.forEach((o) => o._pc = this), s;
675
+ });
676
+ const n = r.RTCPeerConnection.prototype.addTrack;
677
+ n && (r.RTCPeerConnection.prototype.addTrack = function() {
678
+ const s = n.apply(this, arguments);
679
+ return s._pc = this, s;
680
+ }), r.RTCRtpSender.prototype.getStats = function() {
681
+ const s = this;
682
+ return this._pc.getStats().then((o) => (
683
+ /* Note: this will include stats of all senders that
684
+ * send a track with the same id as sender.track as
685
+ * it is not possible to identify the RTCRtpSender.
686
+ */
687
+ de(o, s.track, !0)
688
+ ));
689
+ };
690
+ }
691
+ if (!("getStats" in r.RTCRtpReceiver.prototype)) {
692
+ const t = r.RTCPeerConnection.prototype.getReceivers;
693
+ t && (r.RTCPeerConnection.prototype.getReceivers = function() {
694
+ const i = t.apply(this, []);
695
+ return i.forEach((s) => s._pc = this), i;
696
+ }), x(r, "track", (n) => (n.receiver._pc = n.srcElement, n)), r.RTCRtpReceiver.prototype.getStats = function() {
697
+ const i = this;
698
+ return this._pc.getStats().then((s) => de(s, i.track, !1));
699
+ };
700
+ }
701
+ if (!("getStats" in r.RTCRtpSender.prototype && "getStats" in r.RTCRtpReceiver.prototype))
702
+ return;
703
+ const e = r.RTCPeerConnection.prototype.getStats;
704
+ r.RTCPeerConnection.prototype.getStats = function() {
705
+ if (arguments.length > 0 && arguments[0] instanceof r.MediaStreamTrack) {
706
+ const n = arguments[0];
707
+ let i, s, o;
708
+ return this.getSenders().forEach((a) => {
709
+ a.track === n && (i ? o = !0 : i = a);
710
+ }), this.getReceivers().forEach((a) => (a.track === n && (s ? o = !0 : s = a), a.track === n)), o || i && s ? Promise.reject(new DOMException(
711
+ "There are more than one sender or receiver for the track.",
712
+ "InvalidAccessError"
713
+ )) : i ? i.getStats() : s ? s.getStats() : Promise.reject(new DOMException(
714
+ "There is no sender or receiver for the track.",
715
+ "InvalidAccessError"
716
+ ));
717
+ }
718
+ return e.apply(this, arguments);
719
+ };
720
+ }
721
+ function je(r) {
722
+ r.RTCPeerConnection.prototype.getLocalStreams = function() {
723
+ return this._shimmedLocalStreams = this._shimmedLocalStreams || {}, Object.keys(this._shimmedLocalStreams).map((o) => this._shimmedLocalStreams[o][0]);
724
+ };
725
+ const e = r.RTCPeerConnection.prototype.addTrack;
726
+ r.RTCPeerConnection.prototype.addTrack = function(o, a) {
727
+ if (!a)
728
+ return e.apply(this, arguments);
729
+ this._shimmedLocalStreams = this._shimmedLocalStreams || {};
730
+ const c = e.apply(this, arguments);
731
+ return this._shimmedLocalStreams[a.id] ? this._shimmedLocalStreams[a.id].indexOf(c) === -1 && this._shimmedLocalStreams[a.id].push(c) : this._shimmedLocalStreams[a.id] = [a, c], c;
732
+ };
733
+ const t = r.RTCPeerConnection.prototype.addStream;
734
+ r.RTCPeerConnection.prototype.addStream = function(o) {
735
+ this._shimmedLocalStreams = this._shimmedLocalStreams || {}, o.getTracks().forEach((p) => {
736
+ if (this.getSenders().find((h) => h.track === p))
737
+ throw new DOMException(
738
+ "Track already exists.",
739
+ "InvalidAccessError"
740
+ );
741
+ });
742
+ const a = this.getSenders();
743
+ t.apply(this, arguments);
744
+ const c = this.getSenders().filter((p) => a.indexOf(p) === -1);
745
+ this._shimmedLocalStreams[o.id] = [o].concat(c);
746
+ };
747
+ const n = r.RTCPeerConnection.prototype.removeStream;
748
+ r.RTCPeerConnection.prototype.removeStream = function(o) {
749
+ return this._shimmedLocalStreams = this._shimmedLocalStreams || {}, delete this._shimmedLocalStreams[o.id], n.apply(this, arguments);
750
+ };
751
+ const i = r.RTCPeerConnection.prototype.removeTrack;
752
+ r.RTCPeerConnection.prototype.removeTrack = function(o) {
753
+ return this._shimmedLocalStreams = this._shimmedLocalStreams || {}, o && Object.keys(this._shimmedLocalStreams).forEach((a) => {
754
+ const c = this._shimmedLocalStreams[a].indexOf(o);
755
+ c !== -1 && this._shimmedLocalStreams[a].splice(c, 1), this._shimmedLocalStreams[a].length === 1 && delete this._shimmedLocalStreams[a];
756
+ }), i.apply(this, arguments);
757
+ };
758
+ }
759
+ function Le(r, e) {
760
+ if (!r.RTCPeerConnection)
761
+ return;
762
+ if (r.RTCPeerConnection.prototype.addTrack && e.version >= 65)
763
+ return je(r);
764
+ const t = r.RTCPeerConnection.prototype.getLocalStreams;
765
+ r.RTCPeerConnection.prototype.getLocalStreams = function() {
766
+ const f = t.apply(this);
767
+ return this._reverseStreams = this._reverseStreams || {}, f.map((h) => this._reverseStreams[h.id]);
768
+ };
769
+ const n = r.RTCPeerConnection.prototype.addStream;
770
+ r.RTCPeerConnection.prototype.addStream = function(f) {
771
+ if (this._streams = this._streams || {}, this._reverseStreams = this._reverseStreams || {}, f.getTracks().forEach((h) => {
772
+ if (this.getSenders().find((d) => d.track === h))
773
+ throw new DOMException(
774
+ "Track already exists.",
775
+ "InvalidAccessError"
776
+ );
777
+ }), !this._reverseStreams[f.id]) {
778
+ const h = new r.MediaStream(f.getTracks());
779
+ this._streams[f.id] = h, this._reverseStreams[h.id] = f, f = h;
780
+ }
781
+ n.apply(this, [f]);
782
+ };
783
+ const i = r.RTCPeerConnection.prototype.removeStream;
784
+ r.RTCPeerConnection.prototype.removeStream = function(f) {
785
+ this._streams = this._streams || {}, this._reverseStreams = this._reverseStreams || {}, i.apply(this, [this._streams[f.id] || f]), delete this._reverseStreams[this._streams[f.id] ? this._streams[f.id].id : f.id], delete this._streams[f.id];
786
+ }, r.RTCPeerConnection.prototype.addTrack = function(f, h) {
787
+ if (this.signalingState === "closed")
788
+ throw new DOMException(
789
+ "The RTCPeerConnection's signalingState is 'closed'.",
790
+ "InvalidStateError"
791
+ );
792
+ const l = [].slice.call(arguments, 1);
793
+ if (l.length !== 1 || !l[0].getTracks().find((b) => b === f))
794
+ throw new DOMException(
795
+ "The adapter.js addTrack polyfill only supports a single stream which is associated with the specified track.",
796
+ "NotSupportedError"
797
+ );
798
+ if (this.getSenders().find((b) => b.track === f))
799
+ throw new DOMException(
800
+ "Track already exists.",
801
+ "InvalidAccessError"
802
+ );
803
+ this._streams = this._streams || {}, this._reverseStreams = this._reverseStreams || {};
804
+ const y = this._streams[h.id];
805
+ if (y)
806
+ y.addTrack(f), Promise.resolve().then(() => {
807
+ this.dispatchEvent(new Event("negotiationneeded"));
808
+ });
809
+ else {
810
+ const b = new r.MediaStream([f]);
811
+ this._streams[h.id] = b, this._reverseStreams[b.id] = h, this.addStream(b);
812
+ }
813
+ return this.getSenders().find((b) => b.track === f);
814
+ };
815
+ function s(p, f) {
816
+ let h = f.sdp;
817
+ return Object.keys(p._reverseStreams || []).forEach((l) => {
818
+ const d = p._reverseStreams[l], y = p._streams[d.id];
819
+ h = h.replace(
820
+ new RegExp(y.id, "g"),
821
+ d.id
822
+ );
823
+ }), new RTCSessionDescription({
824
+ type: f.type,
825
+ sdp: h
826
+ });
827
+ }
828
+ function o(p, f) {
829
+ let h = f.sdp;
830
+ return Object.keys(p._reverseStreams || []).forEach((l) => {
831
+ const d = p._reverseStreams[l], y = p._streams[d.id];
832
+ h = h.replace(
833
+ new RegExp(d.id, "g"),
834
+ y.id
835
+ );
836
+ }), new RTCSessionDescription({
837
+ type: f.type,
838
+ sdp: h
839
+ });
840
+ }
841
+ ["createOffer", "createAnswer"].forEach(function(p) {
842
+ const f = r.RTCPeerConnection.prototype[p], h = { [p]() {
843
+ const l = arguments;
844
+ return arguments.length && typeof arguments[0] == "function" ? f.apply(this, [
845
+ (y) => {
846
+ const b = s(this, y);
847
+ l[0].apply(null, [b]);
848
+ },
849
+ (y) => {
850
+ l[1] && l[1].apply(null, y);
851
+ },
852
+ arguments[2]
853
+ ]) : f.apply(this, arguments).then((y) => s(this, y));
854
+ } };
855
+ r.RTCPeerConnection.prototype[p] = h[p];
856
+ });
857
+ const a = r.RTCPeerConnection.prototype.setLocalDescription;
858
+ r.RTCPeerConnection.prototype.setLocalDescription = function() {
859
+ return !arguments.length || !arguments[0].type ? a.apply(this, arguments) : (arguments[0] = o(this, arguments[0]), a.apply(this, arguments));
860
+ };
861
+ const c = Object.getOwnPropertyDescriptor(
862
+ r.RTCPeerConnection.prototype,
863
+ "localDescription"
864
+ );
865
+ Object.defineProperty(
866
+ r.RTCPeerConnection.prototype,
867
+ "localDescription",
868
+ {
869
+ get() {
870
+ const p = c.get.apply(this);
871
+ return p.type === "" ? p : s(this, p);
872
+ }
873
+ }
874
+ ), r.RTCPeerConnection.prototype.removeTrack = function(f) {
875
+ if (this.signalingState === "closed")
876
+ throw new DOMException(
877
+ "The RTCPeerConnection's signalingState is 'closed'.",
878
+ "InvalidStateError"
879
+ );
880
+ if (!f._pc)
881
+ throw new DOMException("Argument 1 of RTCPeerConnection.removeTrack does not implement interface RTCRtpSender.", "TypeError");
882
+ if (!(f._pc === this))
883
+ throw new DOMException(
884
+ "Sender was not created by this connection.",
885
+ "InvalidAccessError"
886
+ );
887
+ this._streams = this._streams || {};
888
+ let l;
889
+ Object.keys(this._streams).forEach((d) => {
890
+ this._streams[d].getTracks().find((b) => f.track === b) && (l = this._streams[d]);
891
+ }), l && (l.getTracks().length === 1 ? this.removeStream(this._reverseStreams[l.id]) : l.removeTrack(f.track), this.dispatchEvent(new Event("negotiationneeded")));
892
+ };
893
+ }
894
+ function w(r, e) {
895
+ !r.RTCPeerConnection && r.webkitRTCPeerConnection && (r.RTCPeerConnection = r.webkitRTCPeerConnection), r.RTCPeerConnection && e.version < 53 && ["setLocalDescription", "setRemoteDescription", "addIceCandidate"].forEach(function(t) {
896
+ const n = r.RTCPeerConnection.prototype[t], i = { [t]() {
897
+ return arguments[0] = new (t === "addIceCandidate" ? r.RTCIceCandidate : r.RTCSessionDescription)(arguments[0]), n.apply(this, arguments);
898
+ } };
899
+ r.RTCPeerConnection.prototype[t] = i[t];
900
+ });
901
+ }
902
+ function Be(r, e) {
903
+ x(r, "negotiationneeded", (t) => {
904
+ const n = t.target;
905
+ if (!((e.version < 72 || n.getConfiguration && n.getConfiguration().sdpSemantics === "plan-b") && n.signalingState !== "stable"))
906
+ return t;
907
+ });
908
+ }
909
+ const ge = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
910
+ __proto__: null,
911
+ fixNegotiationNeeded: Be,
912
+ shimAddTrackRemoveTrack: Le,
913
+ shimAddTrackRemoveTrackWithNative: je,
914
+ shimGetSendersWithDtmf: Ae,
915
+ shimGetUserMedia: Ie,
916
+ shimMediaStream: Me,
917
+ shimOnTrack: Oe,
918
+ shimPeerConnection: w,
919
+ shimSenderReceiverGetStats: $e
920
+ }, Symbol.toStringTag, { value: "Module" }));
921
+ function Fe(r, e) {
922
+ const t = r && r.navigator, n = r && r.MediaStreamTrack;
923
+ if (t.getUserMedia = function(i, s, o) {
924
+ pe(
925
+ "navigator.getUserMedia",
926
+ "navigator.mediaDevices.getUserMedia"
927
+ ), t.mediaDevices.getUserMedia(i).then(s, o);
928
+ }, !(e.version > 55 && "autoGainControl" in t.mediaDevices.getSupportedConstraints())) {
929
+ const i = function(o, a, c) {
930
+ a in o && !(c in o) && (o[c] = o[a], delete o[a]);
931
+ }, s = t.mediaDevices.getUserMedia.bind(t.mediaDevices);
932
+ if (t.mediaDevices.getUserMedia = function(o) {
933
+ return typeof o == "object" && typeof o.audio == "object" && (o = JSON.parse(JSON.stringify(o)), i(o.audio, "autoGainControl", "mozAutoGainControl"), i(o.audio, "noiseSuppression", "mozNoiseSuppression")), s(o);
934
+ }, n && n.prototype.getSettings) {
935
+ const o = n.prototype.getSettings;
936
+ n.prototype.getSettings = function() {
937
+ const a = o.apply(this, arguments);
938
+ return i(a, "mozAutoGainControl", "autoGainControl"), i(a, "mozNoiseSuppression", "noiseSuppression"), a;
939
+ };
940
+ }
941
+ if (n && n.prototype.applyConstraints) {
942
+ const o = n.prototype.applyConstraints;
943
+ n.prototype.applyConstraints = function(a) {
944
+ return this.kind === "audio" && typeof a == "object" && (a = JSON.parse(JSON.stringify(a)), i(a, "autoGainControl", "mozAutoGainControl"), i(a, "noiseSuppression", "mozNoiseSuppression")), o.apply(this, [a]);
945
+ };
946
+ }
947
+ }
948
+ }
949
+ function Rt(r, e) {
950
+ r.navigator.mediaDevices && "getDisplayMedia" in r.navigator.mediaDevices || r.navigator.mediaDevices && (r.navigator.mediaDevices.getDisplayMedia = function(n) {
951
+ if (!(n && n.video)) {
952
+ const i = new DOMException("getDisplayMedia without video constraints is undefined");
953
+ return i.name = "NotFoundError", i.code = 8, Promise.reject(i);
954
+ }
955
+ return n.video === !0 ? n.video = { mediaSource: e } : n.video.mediaSource = e, r.navigator.mediaDevices.getUserMedia(n);
956
+ });
957
+ }
958
+ function Ue(r) {
959
+ typeof r == "object" && r.RTCTrackEvent && "receiver" in r.RTCTrackEvent.prototype && !("transceiver" in r.RTCTrackEvent.prototype) && Object.defineProperty(r.RTCTrackEvent.prototype, "transceiver", {
960
+ get() {
961
+ return { receiver: this.receiver };
962
+ }
963
+ });
964
+ }
965
+ function ee(r, e) {
966
+ if (typeof r != "object" || !(r.RTCPeerConnection || r.mozRTCPeerConnection))
967
+ return;
968
+ !r.RTCPeerConnection && r.mozRTCPeerConnection && (r.RTCPeerConnection = r.mozRTCPeerConnection), e.version < 53 && ["setLocalDescription", "setRemoteDescription", "addIceCandidate"].forEach(function(i) {
969
+ const s = r.RTCPeerConnection.prototype[i], o = { [i]() {
970
+ return arguments[0] = new (i === "addIceCandidate" ? r.RTCIceCandidate : r.RTCSessionDescription)(arguments[0]), s.apply(this, arguments);
971
+ } };
972
+ r.RTCPeerConnection.prototype[i] = o[i];
973
+ });
974
+ const t = {
975
+ inboundrtp: "inbound-rtp",
976
+ outboundrtp: "outbound-rtp",
977
+ candidatepair: "candidate-pair",
978
+ localcandidate: "local-candidate",
979
+ remotecandidate: "remote-candidate"
980
+ }, n = r.RTCPeerConnection.prototype.getStats;
981
+ r.RTCPeerConnection.prototype.getStats = function() {
982
+ const [s, o, a] = arguments;
983
+ return n.apply(this, [s || null]).then((c) => {
984
+ if (e.version < 53 && !o)
985
+ try {
986
+ c.forEach((p) => {
987
+ p.type = t[p.type] || p.type;
988
+ });
989
+ } catch (p) {
990
+ if (p.name !== "TypeError")
991
+ throw p;
992
+ c.forEach((f, h) => {
993
+ c.set(h, Object.assign({}, f, {
994
+ type: t[f.type] || f.type
995
+ }));
996
+ });
997
+ }
998
+ return c;
999
+ }).then(o, a);
1000
+ };
1001
+ }
1002
+ function ze(r) {
1003
+ if (!(typeof r == "object" && r.RTCPeerConnection && r.RTCRtpSender) || r.RTCRtpSender && "getStats" in r.RTCRtpSender.prototype)
1004
+ return;
1005
+ const e = r.RTCPeerConnection.prototype.getSenders;
1006
+ e && (r.RTCPeerConnection.prototype.getSenders = function() {
1007
+ const i = e.apply(this, []);
1008
+ return i.forEach((s) => s._pc = this), i;
1009
+ });
1010
+ const t = r.RTCPeerConnection.prototype.addTrack;
1011
+ t && (r.RTCPeerConnection.prototype.addTrack = function() {
1012
+ const i = t.apply(this, arguments);
1013
+ return i._pc = this, i;
1014
+ }), r.RTCRtpSender.prototype.getStats = function() {
1015
+ return this.track ? this._pc.getStats(this.track) : Promise.resolve(/* @__PURE__ */ new Map());
1016
+ };
1017
+ }
1018
+ function Ne(r) {
1019
+ if (!(typeof r == "object" && r.RTCPeerConnection && r.RTCRtpSender) || r.RTCRtpSender && "getStats" in r.RTCRtpReceiver.prototype)
1020
+ return;
1021
+ const e = r.RTCPeerConnection.prototype.getReceivers;
1022
+ e && (r.RTCPeerConnection.prototype.getReceivers = function() {
1023
+ const n = e.apply(this, []);
1024
+ return n.forEach((i) => i._pc = this), n;
1025
+ }), x(r, "track", (t) => (t.receiver._pc = t.srcElement, t)), r.RTCRtpReceiver.prototype.getStats = function() {
1026
+ return this._pc.getStats(this.track);
1027
+ };
1028
+ }
1029
+ function Je(r) {
1030
+ !r.RTCPeerConnection || "removeStream" in r.RTCPeerConnection.prototype || (r.RTCPeerConnection.prototype.removeStream = function(t) {
1031
+ pe("removeStream", "removeTrack"), this.getSenders().forEach((n) => {
1032
+ n.track && t.getTracks().includes(n.track) && this.removeTrack(n);
1033
+ });
1034
+ });
1035
+ }
1036
+ function Ge(r) {
1037
+ r.DataChannel && !r.RTCDataChannel && (r.RTCDataChannel = r.DataChannel);
1038
+ }
1039
+ function Ve(r) {
1040
+ if (!(typeof r == "object" && r.RTCPeerConnection))
1041
+ return;
1042
+ const e = r.RTCPeerConnection.prototype.addTransceiver;
1043
+ e && (r.RTCPeerConnection.prototype.addTransceiver = function() {
1044
+ this.setParametersPromises = [];
1045
+ let n = arguments[1] && arguments[1].sendEncodings;
1046
+ n === void 0 && (n = []), n = [...n];
1047
+ const i = n.length > 0;
1048
+ i && n.forEach((o) => {
1049
+ if ("rid" in o && !/^[a-z0-9]{0,16}$/i.test(o.rid))
1050
+ throw new TypeError("Invalid RID value provided.");
1051
+ if ("scaleResolutionDownBy" in o && !(parseFloat(o.scaleResolutionDownBy) >= 1))
1052
+ throw new RangeError("scale_resolution_down_by must be >= 1.0");
1053
+ if ("maxFramerate" in o && !(parseFloat(o.maxFramerate) >= 0))
1054
+ throw new RangeError("max_framerate must be >= 0.0");
1055
+ });
1056
+ const s = e.apply(this, arguments);
1057
+ if (i) {
1058
+ const { sender: o } = s, a = o.getParameters();
1059
+ (!("encodings" in a) || // Avoid being fooled by patched getParameters() below.
1060
+ a.encodings.length === 1 && Object.keys(a.encodings[0]).length === 0) && (a.encodings = n, o.sendEncodings = n, this.setParametersPromises.push(
1061
+ o.setParameters(a).then(() => {
1062
+ delete o.sendEncodings;
1063
+ }).catch(() => {
1064
+ delete o.sendEncodings;
1065
+ })
1066
+ ));
1067
+ }
1068
+ return s;
1069
+ });
1070
+ }
1071
+ function He(r) {
1072
+ if (!(typeof r == "object" && r.RTCRtpSender))
1073
+ return;
1074
+ const e = r.RTCRtpSender.prototype.getParameters;
1075
+ e && (r.RTCRtpSender.prototype.getParameters = function() {
1076
+ const n = e.apply(this, arguments);
1077
+ return "encodings" in n || (n.encodings = [].concat(this.sendEncodings || [{}])), n;
1078
+ });
1079
+ }
1080
+ function Ye(r) {
1081
+ if (!(typeof r == "object" && r.RTCPeerConnection))
1082
+ return;
1083
+ const e = r.RTCPeerConnection.prototype.createOffer;
1084
+ r.RTCPeerConnection.prototype.createOffer = function() {
1085
+ return this.setParametersPromises && this.setParametersPromises.length ? Promise.all(this.setParametersPromises).then(() => e.apply(this, arguments)).finally(() => {
1086
+ this.setParametersPromises = [];
1087
+ }) : e.apply(this, arguments);
1088
+ };
1089
+ }
1090
+ function Ke(r) {
1091
+ if (!(typeof r == "object" && r.RTCPeerConnection))
1092
+ return;
1093
+ const e = r.RTCPeerConnection.prototype.createAnswer;
1094
+ r.RTCPeerConnection.prototype.createAnswer = function() {
1095
+ return this.setParametersPromises && this.setParametersPromises.length ? Promise.all(this.setParametersPromises).then(() => e.apply(this, arguments)).finally(() => {
1096
+ this.setParametersPromises = [];
1097
+ }) : e.apply(this, arguments);
1098
+ };
1099
+ }
1100
+ const ye = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1101
+ __proto__: null,
1102
+ shimAddTransceiver: Ve,
1103
+ shimCreateAnswer: Ke,
1104
+ shimCreateOffer: Ye,
1105
+ shimGetDisplayMedia: Rt,
1106
+ shimGetParameters: He,
1107
+ shimGetUserMedia: Fe,
1108
+ shimOnTrack: Ue,
1109
+ shimPeerConnection: ee,
1110
+ shimRTCDataChannel: Ge,
1111
+ shimReceiverGetStats: Ne,
1112
+ shimRemoveStream: Je,
1113
+ shimSenderGetStats: ze
1114
+ }, Symbol.toStringTag, { value: "Module" }));
1115
+ function qe(r) {
1116
+ if (!(typeof r != "object" || !r.RTCPeerConnection)) {
1117
+ if ("getLocalStreams" in r.RTCPeerConnection.prototype || (r.RTCPeerConnection.prototype.getLocalStreams = function() {
1118
+ return this._localStreams || (this._localStreams = []), this._localStreams;
1119
+ }), !("addStream" in r.RTCPeerConnection.prototype)) {
1120
+ const e = r.RTCPeerConnection.prototype.addTrack;
1121
+ r.RTCPeerConnection.prototype.addStream = function(n) {
1122
+ this._localStreams || (this._localStreams = []), this._localStreams.includes(n) || this._localStreams.push(n), n.getAudioTracks().forEach((i) => e.call(
1123
+ this,
1124
+ i,
1125
+ n
1126
+ )), n.getVideoTracks().forEach((i) => e.call(
1127
+ this,
1128
+ i,
1129
+ n
1130
+ ));
1131
+ }, r.RTCPeerConnection.prototype.addTrack = function(n, ...i) {
1132
+ return i && i.forEach((s) => {
1133
+ this._localStreams ? this._localStreams.includes(s) || this._localStreams.push(s) : this._localStreams = [s];
1134
+ }), e.apply(this, arguments);
1135
+ };
1136
+ }
1137
+ "removeStream" in r.RTCPeerConnection.prototype || (r.RTCPeerConnection.prototype.removeStream = function(t) {
1138
+ this._localStreams || (this._localStreams = []);
1139
+ const n = this._localStreams.indexOf(t);
1140
+ if (n === -1)
1141
+ return;
1142
+ this._localStreams.splice(n, 1);
1143
+ const i = t.getTracks();
1144
+ this.getSenders().forEach((s) => {
1145
+ i.includes(s.track) && this.removeTrack(s);
1146
+ });
1147
+ });
1148
+ }
1149
+ }
1150
+ function We(r) {
1151
+ if (!(typeof r != "object" || !r.RTCPeerConnection) && ("getRemoteStreams" in r.RTCPeerConnection.prototype || (r.RTCPeerConnection.prototype.getRemoteStreams = function() {
1152
+ return this._remoteStreams ? this._remoteStreams : [];
1153
+ }), !("onaddstream" in r.RTCPeerConnection.prototype))) {
1154
+ Object.defineProperty(r.RTCPeerConnection.prototype, "onaddstream", {
1155
+ get() {
1156
+ return this._onaddstream;
1157
+ },
1158
+ set(t) {
1159
+ this._onaddstream && (this.removeEventListener("addstream", this._onaddstream), this.removeEventListener("track", this._onaddstreampoly)), this.addEventListener("addstream", this._onaddstream = t), this.addEventListener("track", this._onaddstreampoly = (n) => {
1160
+ n.streams.forEach((i) => {
1161
+ if (this._remoteStreams || (this._remoteStreams = []), this._remoteStreams.includes(i))
1162
+ return;
1163
+ this._remoteStreams.push(i);
1164
+ const s = new Event("addstream");
1165
+ s.stream = i, this.dispatchEvent(s);
1166
+ });
1167
+ });
1168
+ }
1169
+ });
1170
+ const e = r.RTCPeerConnection.prototype.setRemoteDescription;
1171
+ r.RTCPeerConnection.prototype.setRemoteDescription = function() {
1172
+ const n = this;
1173
+ return this._onaddstreampoly || this.addEventListener("track", this._onaddstreampoly = function(i) {
1174
+ i.streams.forEach((s) => {
1175
+ if (n._remoteStreams || (n._remoteStreams = []), n._remoteStreams.indexOf(s) >= 0)
1176
+ return;
1177
+ n._remoteStreams.push(s);
1178
+ const o = new Event("addstream");
1179
+ o.stream = s, n.dispatchEvent(o);
1180
+ });
1181
+ }), e.apply(n, arguments);
1182
+ };
1183
+ }
1184
+ }
1185
+ function Xe(r) {
1186
+ if (typeof r != "object" || !r.RTCPeerConnection)
1187
+ return;
1188
+ const e = r.RTCPeerConnection.prototype, t = e.createOffer, n = e.createAnswer, i = e.setLocalDescription, s = e.setRemoteDescription, o = e.addIceCandidate;
1189
+ e.createOffer = function(p, f) {
1190
+ const h = arguments.length >= 2 ? arguments[2] : arguments[0], l = t.apply(this, [h]);
1191
+ return f ? (l.then(p, f), Promise.resolve()) : l;
1192
+ }, e.createAnswer = function(p, f) {
1193
+ const h = arguments.length >= 2 ? arguments[2] : arguments[0], l = n.apply(this, [h]);
1194
+ return f ? (l.then(p, f), Promise.resolve()) : l;
1195
+ };
1196
+ let a = function(c, p, f) {
1197
+ const h = i.apply(this, [c]);
1198
+ return f ? (h.then(p, f), Promise.resolve()) : h;
1199
+ };
1200
+ e.setLocalDescription = a, a = function(c, p, f) {
1201
+ const h = s.apply(this, [c]);
1202
+ return f ? (h.then(p, f), Promise.resolve()) : h;
1203
+ }, e.setRemoteDescription = a, a = function(c, p, f) {
1204
+ const h = o.apply(this, [c]);
1205
+ return f ? (h.then(p, f), Promise.resolve()) : h;
1206
+ }, e.addIceCandidate = a;
1207
+ }
1208
+ function Qe(r) {
1209
+ const e = r && r.navigator;
1210
+ if (e.mediaDevices && e.mediaDevices.getUserMedia) {
1211
+ const t = e.mediaDevices, n = t.getUserMedia.bind(t);
1212
+ e.mediaDevices.getUserMedia = (i) => n(Ze(i));
1213
+ }
1214
+ !e.getUserMedia && e.mediaDevices && e.mediaDevices.getUserMedia && (e.getUserMedia = (function(n, i, s) {
1215
+ e.mediaDevices.getUserMedia(n).then(i, s);
1216
+ }).bind(e));
1217
+ }
1218
+ function Ze(r) {
1219
+ return r && r.video !== void 0 ? Object.assign(
1220
+ {},
1221
+ r,
1222
+ { video: De(r.video) }
1223
+ ) : r;
1224
+ }
1225
+ function we(r) {
1226
+ if (!r.RTCPeerConnection)
1227
+ return;
1228
+ const e = r.RTCPeerConnection;
1229
+ r.RTCPeerConnection = function(n, i) {
1230
+ if (n && n.iceServers) {
1231
+ const s = [];
1232
+ for (let o = 0; o < n.iceServers.length; o++) {
1233
+ let a = n.iceServers[o];
1234
+ a.urls === void 0 && a.url ? (pe("RTCIceServer.url", "RTCIceServer.urls"), a = JSON.parse(JSON.stringify(a)), a.urls = a.url, delete a.url, s.push(a)) : s.push(n.iceServers[o]);
1235
+ }
1236
+ n.iceServers = s;
1237
+ }
1238
+ return new e(n, i);
1239
+ }, r.RTCPeerConnection.prototype = e.prototype, "generateCertificate" in e && Object.defineProperty(r.RTCPeerConnection, "generateCertificate", {
1240
+ get() {
1241
+ return e.generateCertificate;
1242
+ }
1243
+ });
1244
+ }
1245
+ function et(r) {
1246
+ typeof r == "object" && r.RTCTrackEvent && "receiver" in r.RTCTrackEvent.prototype && !("transceiver" in r.RTCTrackEvent.prototype) && Object.defineProperty(r.RTCTrackEvent.prototype, "transceiver", {
1247
+ get() {
1248
+ return { receiver: this.receiver };
1249
+ }
1250
+ });
1251
+ }
1252
+ function tt(r) {
1253
+ const e = r.RTCPeerConnection.prototype.createOffer;
1254
+ r.RTCPeerConnection.prototype.createOffer = function(n) {
1255
+ if (n) {
1256
+ typeof n.offerToReceiveAudio < "u" && (n.offerToReceiveAudio = !!n.offerToReceiveAudio);
1257
+ const i = this.getTransceivers().find((o) => o.receiver.track.kind === "audio");
1258
+ n.offerToReceiveAudio === !1 && i ? i.direction === "sendrecv" ? i.setDirection ? i.setDirection("sendonly") : i.direction = "sendonly" : i.direction === "recvonly" && (i.setDirection ? i.setDirection("inactive") : i.direction = "inactive") : n.offerToReceiveAudio === !0 && !i && this.addTransceiver("audio", { direction: "recvonly" }), typeof n.offerToReceiveVideo < "u" && (n.offerToReceiveVideo = !!n.offerToReceiveVideo);
1259
+ const s = this.getTransceivers().find((o) => o.receiver.track.kind === "video");
1260
+ n.offerToReceiveVideo === !1 && s ? s.direction === "sendrecv" ? s.setDirection ? s.setDirection("sendonly") : s.direction = "sendonly" : s.direction === "recvonly" && (s.setDirection ? s.setDirection("inactive") : s.direction = "inactive") : n.offerToReceiveVideo === !0 && !s && this.addTransceiver("video", { direction: "recvonly" });
1261
+ }
1262
+ return e.apply(this, arguments);
1263
+ };
1264
+ }
1265
+ function nt(r) {
1266
+ typeof r != "object" || r.AudioContext || (r.AudioContext = r.webkitAudioContext);
1267
+ }
1268
+ const _e = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1269
+ __proto__: null,
1270
+ shimAudioContext: nt,
1271
+ shimCallbacksAPI: Xe,
1272
+ shimConstraints: Ze,
1273
+ shimCreateOfferLegacy: tt,
1274
+ shimGetUserMedia: Qe,
1275
+ shimLocalStreamsAPI: qe,
1276
+ shimRTCIceServerUrls: we,
1277
+ shimRemoteStreamsAPI: We,
1278
+ shimTrackEventTransceiver: et
1279
+ }, Symbol.toStringTag, { value: "Module" }));
1280
+ var W = { exports: {} }, Ce;
1281
+ function xt() {
1282
+ return Ce || (Ce = 1, function(r) {
1283
+ const e = {};
1284
+ e.generateIdentifier = function() {
1285
+ return Math.random().toString(36).substring(2, 12);
1286
+ }, e.localCName = e.generateIdentifier(), e.splitLines = function(t) {
1287
+ return t.trim().split(`
1288
+ `).map((n) => n.trim());
1289
+ }, e.splitSections = function(t) {
1290
+ return t.split(`
1291
+ m=`).map((i, s) => (s > 0 ? "m=" + i : i).trim() + `\r
1292
+ `);
1293
+ }, e.getDescription = function(t) {
1294
+ const n = e.splitSections(t);
1295
+ return n && n[0];
1296
+ }, e.getMediaSections = function(t) {
1297
+ const n = e.splitSections(t);
1298
+ return n.shift(), n;
1299
+ }, e.matchPrefix = function(t, n) {
1300
+ return e.splitLines(t).filter((i) => i.indexOf(n) === 0);
1301
+ }, e.parseCandidate = function(t) {
1302
+ let n;
1303
+ t.indexOf("a=candidate:") === 0 ? n = t.substring(12).split(" ") : n = t.substring(10).split(" ");
1304
+ const i = {
1305
+ foundation: n[0],
1306
+ component: { 1: "rtp", 2: "rtcp" }[n[1]] || n[1],
1307
+ protocol: n[2].toLowerCase(),
1308
+ priority: parseInt(n[3], 10),
1309
+ ip: n[4],
1310
+ address: n[4],
1311
+ // address is an alias for ip.
1312
+ port: parseInt(n[5], 10),
1313
+ // skip parts[6] == 'typ'
1314
+ type: n[7]
1315
+ };
1316
+ for (let s = 8; s < n.length; s += 2)
1317
+ switch (n[s]) {
1318
+ case "raddr":
1319
+ i.relatedAddress = n[s + 1];
1320
+ break;
1321
+ case "rport":
1322
+ i.relatedPort = parseInt(n[s + 1], 10);
1323
+ break;
1324
+ case "tcptype":
1325
+ i.tcpType = n[s + 1];
1326
+ break;
1327
+ case "ufrag":
1328
+ i.ufrag = n[s + 1], i.usernameFragment = n[s + 1];
1329
+ break;
1330
+ default:
1331
+ i[n[s]] === void 0 && (i[n[s]] = n[s + 1]);
1332
+ break;
1333
+ }
1334
+ return i;
1335
+ }, e.writeCandidate = function(t) {
1336
+ const n = [];
1337
+ n.push(t.foundation);
1338
+ const i = t.component;
1339
+ i === "rtp" ? n.push(1) : i === "rtcp" ? n.push(2) : n.push(i), n.push(t.protocol.toUpperCase()), n.push(t.priority), n.push(t.address || t.ip), n.push(t.port);
1340
+ const s = t.type;
1341
+ return n.push("typ"), n.push(s), s !== "host" && t.relatedAddress && t.relatedPort && (n.push("raddr"), n.push(t.relatedAddress), n.push("rport"), n.push(t.relatedPort)), t.tcpType && t.protocol.toLowerCase() === "tcp" && (n.push("tcptype"), n.push(t.tcpType)), (t.usernameFragment || t.ufrag) && (n.push("ufrag"), n.push(t.usernameFragment || t.ufrag)), "candidate:" + n.join(" ");
1342
+ }, e.parseIceOptions = function(t) {
1343
+ return t.substring(14).split(" ");
1344
+ }, e.parseRtpMap = function(t) {
1345
+ let n = t.substring(9).split(" ");
1346
+ const i = {
1347
+ payloadType: parseInt(n.shift(), 10)
1348
+ // was: id
1349
+ };
1350
+ return n = n[0].split("/"), i.name = n[0], i.clockRate = parseInt(n[1], 10), i.channels = n.length === 3 ? parseInt(n[2], 10) : 1, i.numChannels = i.channels, i;
1351
+ }, e.writeRtpMap = function(t) {
1352
+ let n = t.payloadType;
1353
+ t.preferredPayloadType !== void 0 && (n = t.preferredPayloadType);
1354
+ const i = t.channels || t.numChannels || 1;
1355
+ return "a=rtpmap:" + n + " " + t.name + "/" + t.clockRate + (i !== 1 ? "/" + i : "") + `\r
1356
+ `;
1357
+ }, e.parseExtmap = function(t) {
1358
+ const n = t.substring(9).split(" ");
1359
+ return {
1360
+ id: parseInt(n[0], 10),
1361
+ direction: n[0].indexOf("/") > 0 ? n[0].split("/")[1] : "sendrecv",
1362
+ uri: n[1],
1363
+ attributes: n.slice(2).join(" ")
1364
+ };
1365
+ }, e.writeExtmap = function(t) {
1366
+ return "a=extmap:" + (t.id || t.preferredId) + (t.direction && t.direction !== "sendrecv" ? "/" + t.direction : "") + " " + t.uri + (t.attributes ? " " + t.attributes : "") + `\r
1367
+ `;
1368
+ }, e.parseFmtp = function(t) {
1369
+ const n = {};
1370
+ let i;
1371
+ const s = t.substring(t.indexOf(" ") + 1).split(";");
1372
+ for (let o = 0; o < s.length; o++)
1373
+ i = s[o].trim().split("="), n[i[0].trim()] = i[1];
1374
+ return n;
1375
+ }, e.writeFmtp = function(t) {
1376
+ let n = "", i = t.payloadType;
1377
+ if (t.preferredPayloadType !== void 0 && (i = t.preferredPayloadType), t.parameters && Object.keys(t.parameters).length) {
1378
+ const s = [];
1379
+ Object.keys(t.parameters).forEach((o) => {
1380
+ t.parameters[o] !== void 0 ? s.push(o + "=" + t.parameters[o]) : s.push(o);
1381
+ }), n += "a=fmtp:" + i + " " + s.join(";") + `\r
1382
+ `;
1383
+ }
1384
+ return n;
1385
+ }, e.parseRtcpFb = function(t) {
1386
+ const n = t.substring(t.indexOf(" ") + 1).split(" ");
1387
+ return {
1388
+ type: n.shift(),
1389
+ parameter: n.join(" ")
1390
+ };
1391
+ }, e.writeRtcpFb = function(t) {
1392
+ let n = "", i = t.payloadType;
1393
+ return t.preferredPayloadType !== void 0 && (i = t.preferredPayloadType), t.rtcpFeedback && t.rtcpFeedback.length && t.rtcpFeedback.forEach((s) => {
1394
+ n += "a=rtcp-fb:" + i + " " + s.type + (s.parameter && s.parameter.length ? " " + s.parameter : "") + `\r
1395
+ `;
1396
+ }), n;
1397
+ }, e.parseSsrcMedia = function(t) {
1398
+ const n = t.indexOf(" "), i = {
1399
+ ssrc: parseInt(t.substring(7, n), 10)
1400
+ }, s = t.indexOf(":", n);
1401
+ return s > -1 ? (i.attribute = t.substring(n + 1, s), i.value = t.substring(s + 1)) : i.attribute = t.substring(n + 1), i;
1402
+ }, e.parseSsrcGroup = function(t) {
1403
+ const n = t.substring(13).split(" ");
1404
+ return {
1405
+ semantics: n.shift(),
1406
+ ssrcs: n.map((i) => parseInt(i, 10))
1407
+ };
1408
+ }, e.getMid = function(t) {
1409
+ const n = e.matchPrefix(t, "a=mid:")[0];
1410
+ if (n)
1411
+ return n.substring(6);
1412
+ }, e.parseFingerprint = function(t) {
1413
+ const n = t.substring(14).split(" ");
1414
+ return {
1415
+ algorithm: n[0].toLowerCase(),
1416
+ // algorithm is case-sensitive in Edge.
1417
+ value: n[1].toUpperCase()
1418
+ // the definition is upper-case in RFC 4572.
1419
+ };
1420
+ }, e.getDtlsParameters = function(t, n) {
1421
+ return {
1422
+ role: "auto",
1423
+ fingerprints: e.matchPrefix(
1424
+ t + n,
1425
+ "a=fingerprint:"
1426
+ ).map(e.parseFingerprint)
1427
+ };
1428
+ }, e.writeDtlsParameters = function(t, n) {
1429
+ let i = "a=setup:" + n + `\r
1430
+ `;
1431
+ return t.fingerprints.forEach((s) => {
1432
+ i += "a=fingerprint:" + s.algorithm + " " + s.value + `\r
1433
+ `;
1434
+ }), i;
1435
+ }, e.parseCryptoLine = function(t) {
1436
+ const n = t.substring(9).split(" ");
1437
+ return {
1438
+ tag: parseInt(n[0], 10),
1439
+ cryptoSuite: n[1],
1440
+ keyParams: n[2],
1441
+ sessionParams: n.slice(3)
1442
+ };
1443
+ }, e.writeCryptoLine = function(t) {
1444
+ return "a=crypto:" + t.tag + " " + t.cryptoSuite + " " + (typeof t.keyParams == "object" ? e.writeCryptoKeyParams(t.keyParams) : t.keyParams) + (t.sessionParams ? " " + t.sessionParams.join(" ") : "") + `\r
1445
+ `;
1446
+ }, e.parseCryptoKeyParams = function(t) {
1447
+ if (t.indexOf("inline:") !== 0)
1448
+ return null;
1449
+ const n = t.substring(7).split("|");
1450
+ return {
1451
+ keyMethod: "inline",
1452
+ keySalt: n[0],
1453
+ lifeTime: n[1],
1454
+ mkiValue: n[2] ? n[2].split(":")[0] : void 0,
1455
+ mkiLength: n[2] ? n[2].split(":")[1] : void 0
1456
+ };
1457
+ }, e.writeCryptoKeyParams = function(t) {
1458
+ return t.keyMethod + ":" + t.keySalt + (t.lifeTime ? "|" + t.lifeTime : "") + (t.mkiValue && t.mkiLength ? "|" + t.mkiValue + ":" + t.mkiLength : "");
1459
+ }, e.getCryptoParameters = function(t, n) {
1460
+ return e.matchPrefix(
1461
+ t + n,
1462
+ "a=crypto:"
1463
+ ).map(e.parseCryptoLine);
1464
+ }, e.getIceParameters = function(t, n) {
1465
+ const i = e.matchPrefix(
1466
+ t + n,
1467
+ "a=ice-ufrag:"
1468
+ )[0], s = e.matchPrefix(
1469
+ t + n,
1470
+ "a=ice-pwd:"
1471
+ )[0];
1472
+ return i && s ? {
1473
+ usernameFragment: i.substring(12),
1474
+ password: s.substring(10)
1475
+ } : null;
1476
+ }, e.writeIceParameters = function(t) {
1477
+ let n = "a=ice-ufrag:" + t.usernameFragment + `\r
1478
+ a=ice-pwd:` + t.password + `\r
1479
+ `;
1480
+ return t.iceLite && (n += `a=ice-lite\r
1481
+ `), n;
1482
+ }, e.parseRtpParameters = function(t) {
1483
+ const n = {
1484
+ codecs: [],
1485
+ headerExtensions: [],
1486
+ fecMechanisms: [],
1487
+ rtcp: []
1488
+ }, s = e.splitLines(t)[0].split(" ");
1489
+ n.profile = s[2];
1490
+ for (let a = 3; a < s.length; a++) {
1491
+ const c = s[a], p = e.matchPrefix(
1492
+ t,
1493
+ "a=rtpmap:" + c + " "
1494
+ )[0];
1495
+ if (p) {
1496
+ const f = e.parseRtpMap(p), h = e.matchPrefix(
1497
+ t,
1498
+ "a=fmtp:" + c + " "
1499
+ );
1500
+ switch (f.parameters = h.length ? e.parseFmtp(h[0]) : {}, f.rtcpFeedback = e.matchPrefix(
1501
+ t,
1502
+ "a=rtcp-fb:" + c + " "
1503
+ ).map(e.parseRtcpFb), n.codecs.push(f), f.name.toUpperCase()) {
1504
+ case "RED":
1505
+ case "ULPFEC":
1506
+ n.fecMechanisms.push(f.name.toUpperCase());
1507
+ break;
1508
+ }
1509
+ }
1510
+ }
1511
+ e.matchPrefix(t, "a=extmap:").forEach((a) => {
1512
+ n.headerExtensions.push(e.parseExtmap(a));
1513
+ });
1514
+ const o = e.matchPrefix(t, "a=rtcp-fb:* ").map(e.parseRtcpFb);
1515
+ return n.codecs.forEach((a) => {
1516
+ o.forEach((c) => {
1517
+ a.rtcpFeedback.find((f) => f.type === c.type && f.parameter === c.parameter) || a.rtcpFeedback.push(c);
1518
+ });
1519
+ }), n;
1520
+ }, e.writeRtpDescription = function(t, n) {
1521
+ let i = "";
1522
+ i += "m=" + t + " ", i += n.codecs.length > 0 ? "9" : "0", i += " " + (n.profile || "UDP/TLS/RTP/SAVPF") + " ", i += n.codecs.map((o) => o.preferredPayloadType !== void 0 ? o.preferredPayloadType : o.payloadType).join(" ") + `\r
1523
+ `, i += `c=IN IP4 0.0.0.0\r
1524
+ `, i += `a=rtcp:9 IN IP4 0.0.0.0\r
1525
+ `, n.codecs.forEach((o) => {
1526
+ i += e.writeRtpMap(o), i += e.writeFmtp(o), i += e.writeRtcpFb(o);
1527
+ });
1528
+ let s = 0;
1529
+ return n.codecs.forEach((o) => {
1530
+ o.maxptime > s && (s = o.maxptime);
1531
+ }), s > 0 && (i += "a=maxptime:" + s + `\r
1532
+ `), n.headerExtensions && n.headerExtensions.forEach((o) => {
1533
+ i += e.writeExtmap(o);
1534
+ }), i;
1535
+ }, e.parseRtpEncodingParameters = function(t) {
1536
+ const n = [], i = e.parseRtpParameters(t), s = i.fecMechanisms.indexOf("RED") !== -1, o = i.fecMechanisms.indexOf("ULPFEC") !== -1, a = e.matchPrefix(t, "a=ssrc:").map((l) => e.parseSsrcMedia(l)).filter((l) => l.attribute === "cname"), c = a.length > 0 && a[0].ssrc;
1537
+ let p;
1538
+ const f = e.matchPrefix(t, "a=ssrc-group:FID").map((l) => l.substring(17).split(" ").map((y) => parseInt(y, 10)));
1539
+ f.length > 0 && f[0].length > 1 && f[0][0] === c && (p = f[0][1]), i.codecs.forEach((l) => {
1540
+ if (l.name.toUpperCase() === "RTX" && l.parameters.apt) {
1541
+ let d = {
1542
+ ssrc: c,
1543
+ codecPayloadType: parseInt(l.parameters.apt, 10)
1544
+ };
1545
+ c && p && (d.rtx = { ssrc: p }), n.push(d), s && (d = JSON.parse(JSON.stringify(d)), d.fec = {
1546
+ ssrc: c,
1547
+ mechanism: o ? "red+ulpfec" : "red"
1548
+ }, n.push(d));
1549
+ }
1550
+ }), n.length === 0 && c && n.push({
1551
+ ssrc: c
1552
+ });
1553
+ let h = e.matchPrefix(t, "b=");
1554
+ return h.length && (h[0].indexOf("b=TIAS:") === 0 ? h = parseInt(h[0].substring(7), 10) : h[0].indexOf("b=AS:") === 0 ? h = parseInt(h[0].substring(5), 10) * 1e3 * 0.95 - 50 * 40 * 8 : h = void 0, n.forEach((l) => {
1555
+ l.maxBitrate = h;
1556
+ })), n;
1557
+ }, e.parseRtcpParameters = function(t) {
1558
+ const n = {}, i = e.matchPrefix(t, "a=ssrc:").map((a) => e.parseSsrcMedia(a)).filter((a) => a.attribute === "cname")[0];
1559
+ i && (n.cname = i.value, n.ssrc = i.ssrc);
1560
+ const s = e.matchPrefix(t, "a=rtcp-rsize");
1561
+ n.reducedSize = s.length > 0, n.compound = s.length === 0;
1562
+ const o = e.matchPrefix(t, "a=rtcp-mux");
1563
+ return n.mux = o.length > 0, n;
1564
+ }, e.writeRtcpParameters = function(t) {
1565
+ let n = "";
1566
+ return t.reducedSize && (n += `a=rtcp-rsize\r
1567
+ `), t.mux && (n += `a=rtcp-mux\r
1568
+ `), t.ssrc !== void 0 && t.cname && (n += "a=ssrc:" + t.ssrc + " cname:" + t.cname + `\r
1569
+ `), n;
1570
+ }, e.parseMsid = function(t) {
1571
+ let n;
1572
+ const i = e.matchPrefix(t, "a=msid:");
1573
+ if (i.length === 1)
1574
+ return n = i[0].substring(7).split(" "), { stream: n[0], track: n[1] };
1575
+ const s = e.matchPrefix(t, "a=ssrc:").map((o) => e.parseSsrcMedia(o)).filter((o) => o.attribute === "msid");
1576
+ if (s.length > 0)
1577
+ return n = s[0].value.split(" "), { stream: n[0], track: n[1] };
1578
+ }, e.parseSctpDescription = function(t) {
1579
+ const n = e.parseMLine(t), i = e.matchPrefix(t, "a=max-message-size:");
1580
+ let s;
1581
+ i.length > 0 && (s = parseInt(i[0].substring(19), 10)), isNaN(s) && (s = 65536);
1582
+ const o = e.matchPrefix(t, "a=sctp-port:");
1583
+ if (o.length > 0)
1584
+ return {
1585
+ port: parseInt(o[0].substring(12), 10),
1586
+ protocol: n.fmt,
1587
+ maxMessageSize: s
1588
+ };
1589
+ const a = e.matchPrefix(t, "a=sctpmap:");
1590
+ if (a.length > 0) {
1591
+ const c = a[0].substring(10).split(" ");
1592
+ return {
1593
+ port: parseInt(c[0], 10),
1594
+ protocol: c[1],
1595
+ maxMessageSize: s
1596
+ };
1597
+ }
1598
+ }, e.writeSctpDescription = function(t, n) {
1599
+ let i = [];
1600
+ return t.protocol !== "DTLS/SCTP" ? i = [
1601
+ "m=" + t.kind + " 9 " + t.protocol + " " + n.protocol + `\r
1602
+ `,
1603
+ `c=IN IP4 0.0.0.0\r
1604
+ `,
1605
+ "a=sctp-port:" + n.port + `\r
1606
+ `
1607
+ ] : i = [
1608
+ "m=" + t.kind + " 9 " + t.protocol + " " + n.port + `\r
1609
+ `,
1610
+ `c=IN IP4 0.0.0.0\r
1611
+ `,
1612
+ "a=sctpmap:" + n.port + " " + n.protocol + ` 65535\r
1613
+ `
1614
+ ], n.maxMessageSize !== void 0 && i.push("a=max-message-size:" + n.maxMessageSize + `\r
1615
+ `), i.join("");
1616
+ }, e.generateSessionId = function() {
1617
+ return Math.random().toString().substr(2, 22);
1618
+ }, e.writeSessionBoilerplate = function(t, n, i) {
1619
+ let s;
1620
+ const o = n !== void 0 ? n : 2;
1621
+ return t ? s = t : s = e.generateSessionId(), `v=0\r
1622
+ o=` + (i || "thisisadapterortc") + " " + s + " " + o + ` IN IP4 127.0.0.1\r
1623
+ s=-\r
1624
+ t=0 0\r
1625
+ `;
1626
+ }, e.getDirection = function(t, n) {
1627
+ const i = e.splitLines(t);
1628
+ for (let s = 0; s < i.length; s++)
1629
+ switch (i[s]) {
1630
+ case "a=sendrecv":
1631
+ case "a=sendonly":
1632
+ case "a=recvonly":
1633
+ case "a=inactive":
1634
+ return i[s].substring(2);
1635
+ }
1636
+ return n ? e.getDirection(n) : "sendrecv";
1637
+ }, e.getKind = function(t) {
1638
+ return e.splitLines(t)[0].split(" ")[0].substring(2);
1639
+ }, e.isRejected = function(t) {
1640
+ return t.split(" ", 2)[1] === "0";
1641
+ }, e.parseMLine = function(t) {
1642
+ const i = e.splitLines(t)[0].substring(2).split(" ");
1643
+ return {
1644
+ kind: i[0],
1645
+ port: parseInt(i[1], 10),
1646
+ protocol: i[2],
1647
+ fmt: i.slice(3).join(" ")
1648
+ };
1649
+ }, e.parseOLine = function(t) {
1650
+ const i = e.matchPrefix(t, "o=")[0].substring(2).split(" ");
1651
+ return {
1652
+ username: i[0],
1653
+ sessionId: i[1],
1654
+ sessionVersion: parseInt(i[2], 10),
1655
+ netType: i[3],
1656
+ addressType: i[4],
1657
+ address: i[5]
1658
+ };
1659
+ }, e.isValidSDP = function(t) {
1660
+ if (typeof t != "string" || t.length === 0)
1661
+ return !1;
1662
+ const n = e.splitLines(t);
1663
+ for (let i = 0; i < n.length; i++)
1664
+ if (n[i].length < 2 || n[i].charAt(1) !== "=")
1665
+ return !1;
1666
+ return !0;
1667
+ }, r.exports = e;
1668
+ }(W)), W.exports;
1669
+ }
1670
+ var rt = xt();
1671
+ const D = /* @__PURE__ */ ut(rt), Pt = /* @__PURE__ */ yt({
1672
+ __proto__: null,
1673
+ default: D
1674
+ }, [rt]);
1675
+ function z(r) {
1676
+ if (!r.RTCIceCandidate || r.RTCIceCandidate && "foundation" in r.RTCIceCandidate.prototype)
1677
+ return;
1678
+ const e = r.RTCIceCandidate;
1679
+ r.RTCIceCandidate = function(n) {
1680
+ if (typeof n == "object" && n.candidate && n.candidate.indexOf("a=") === 0 && (n = JSON.parse(JSON.stringify(n)), n.candidate = n.candidate.substring(2)), n.candidate && n.candidate.length) {
1681
+ const i = new e(n), s = D.parseCandidate(n.candidate);
1682
+ for (const o in s)
1683
+ o in i || Object.defineProperty(
1684
+ i,
1685
+ o,
1686
+ { value: s[o] }
1687
+ );
1688
+ return i.toJSON = function() {
1689
+ return {
1690
+ candidate: i.candidate,
1691
+ sdpMid: i.sdpMid,
1692
+ sdpMLineIndex: i.sdpMLineIndex,
1693
+ usernameFragment: i.usernameFragment
1694
+ };
1695
+ }, i;
1696
+ }
1697
+ return new e(n);
1698
+ }, r.RTCIceCandidate.prototype = e.prototype, x(r, "icecandidate", (t) => (t.candidate && Object.defineProperty(t, "candidate", {
1699
+ value: new r.RTCIceCandidate(t.candidate),
1700
+ writable: "false"
1701
+ }), t));
1702
+ }
1703
+ function te(r) {
1704
+ !r.RTCIceCandidate || r.RTCIceCandidate && "relayProtocol" in r.RTCIceCandidate.prototype || x(r, "icecandidate", (e) => {
1705
+ if (e.candidate) {
1706
+ const t = D.parseCandidate(e.candidate.candidate);
1707
+ t.type === "relay" && (e.candidate.relayProtocol = {
1708
+ 0: "tls",
1709
+ 1: "tcp",
1710
+ 2: "udp"
1711
+ }[t.priority >> 24]);
1712
+ }
1713
+ return e;
1714
+ });
1715
+ }
1716
+ function N(r, e) {
1717
+ if (!r.RTCPeerConnection)
1718
+ return;
1719
+ "sctp" in r.RTCPeerConnection.prototype || Object.defineProperty(r.RTCPeerConnection.prototype, "sctp", {
1720
+ get() {
1721
+ return typeof this._sctp > "u" ? null : this._sctp;
1722
+ }
1723
+ });
1724
+ const t = function(a) {
1725
+ if (!a || !a.sdp)
1726
+ return !1;
1727
+ const c = D.splitSections(a.sdp);
1728
+ return c.shift(), c.some((p) => {
1729
+ const f = D.parseMLine(p);
1730
+ return f && f.kind === "application" && f.protocol.indexOf("SCTP") !== -1;
1731
+ });
1732
+ }, n = function(a) {
1733
+ const c = a.sdp.match(/mozilla...THIS_IS_SDPARTA-(\d+)/);
1734
+ if (c === null || c.length < 2)
1735
+ return -1;
1736
+ const p = parseInt(c[1], 10);
1737
+ return p !== p ? -1 : p;
1738
+ }, i = function(a) {
1739
+ let c = 65536;
1740
+ return e.browser === "firefox" && (e.version < 57 ? a === -1 ? c = 16384 : c = 2147483637 : e.version < 60 ? c = e.version === 57 ? 65535 : 65536 : c = 2147483637), c;
1741
+ }, s = function(a, c) {
1742
+ let p = 65536;
1743
+ e.browser === "firefox" && e.version === 57 && (p = 65535);
1744
+ const f = D.matchPrefix(
1745
+ a.sdp,
1746
+ "a=max-message-size:"
1747
+ );
1748
+ return f.length > 0 ? p = parseInt(f[0].substring(19), 10) : e.browser === "firefox" && c !== -1 && (p = 2147483637), p;
1749
+ }, o = r.RTCPeerConnection.prototype.setRemoteDescription;
1750
+ r.RTCPeerConnection.prototype.setRemoteDescription = function() {
1751
+ if (this._sctp = null, e.browser === "chrome" && e.version >= 76) {
1752
+ const { sdpSemantics: c } = this.getConfiguration();
1753
+ c === "plan-b" && Object.defineProperty(this, "sctp", {
1754
+ get() {
1755
+ return typeof this._sctp > "u" ? null : this._sctp;
1756
+ },
1757
+ enumerable: !0,
1758
+ configurable: !0
1759
+ });
1760
+ }
1761
+ if (t(arguments[0])) {
1762
+ const c = n(arguments[0]), p = i(c), f = s(arguments[0], c);
1763
+ let h;
1764
+ p === 0 && f === 0 ? h = Number.POSITIVE_INFINITY : p === 0 || f === 0 ? h = Math.max(p, f) : h = Math.min(p, f);
1765
+ const l = {};
1766
+ Object.defineProperty(l, "maxMessageSize", {
1767
+ get() {
1768
+ return h;
1769
+ }
1770
+ }), this._sctp = l;
1771
+ }
1772
+ return o.apply(this, arguments);
1773
+ };
1774
+ }
1775
+ function J(r) {
1776
+ if (!(r.RTCPeerConnection && "createDataChannel" in r.RTCPeerConnection.prototype))
1777
+ return;
1778
+ function e(n, i) {
1779
+ const s = n.send;
1780
+ n.send = function() {
1781
+ const a = arguments[0], c = a.length || a.size || a.byteLength;
1782
+ if (n.readyState === "open" && i.sctp && c > i.sctp.maxMessageSize)
1783
+ throw new TypeError("Message too large (can send a maximum of " + i.sctp.maxMessageSize + " bytes)");
1784
+ return s.apply(n, arguments);
1785
+ };
1786
+ }
1787
+ const t = r.RTCPeerConnection.prototype.createDataChannel;
1788
+ r.RTCPeerConnection.prototype.createDataChannel = function() {
1789
+ const i = t.apply(this, arguments);
1790
+ return e(i, this), i;
1791
+ }, x(r, "datachannel", (n) => (e(n.channel, n.target), n));
1792
+ }
1793
+ function ne(r) {
1794
+ if (!r.RTCPeerConnection || "connectionState" in r.RTCPeerConnection.prototype)
1795
+ return;
1796
+ const e = r.RTCPeerConnection.prototype;
1797
+ Object.defineProperty(e, "connectionState", {
1798
+ get() {
1799
+ return {
1800
+ completed: "connected",
1801
+ checking: "connecting"
1802
+ }[this.iceConnectionState] || this.iceConnectionState;
1803
+ },
1804
+ enumerable: !0,
1805
+ configurable: !0
1806
+ }), Object.defineProperty(e, "onconnectionstatechange", {
1807
+ get() {
1808
+ return this._onconnectionstatechange || null;
1809
+ },
1810
+ set(t) {
1811
+ this._onconnectionstatechange && (this.removeEventListener(
1812
+ "connectionstatechange",
1813
+ this._onconnectionstatechange
1814
+ ), delete this._onconnectionstatechange), t && this.addEventListener(
1815
+ "connectionstatechange",
1816
+ this._onconnectionstatechange = t
1817
+ );
1818
+ },
1819
+ enumerable: !0,
1820
+ configurable: !0
1821
+ }), ["setLocalDescription", "setRemoteDescription"].forEach((t) => {
1822
+ const n = e[t];
1823
+ e[t] = function() {
1824
+ return this._connectionstatechangepoly || (this._connectionstatechangepoly = (i) => {
1825
+ const s = i.target;
1826
+ if (s._lastConnectionState !== s.connectionState) {
1827
+ s._lastConnectionState = s.connectionState;
1828
+ const o = new Event("connectionstatechange", i);
1829
+ s.dispatchEvent(o);
1830
+ }
1831
+ return i;
1832
+ }, this.addEventListener(
1833
+ "iceconnectionstatechange",
1834
+ this._connectionstatechangepoly
1835
+ )), n.apply(this, arguments);
1836
+ };
1837
+ });
1838
+ }
1839
+ function re(r, e) {
1840
+ if (!r.RTCPeerConnection || e.browser === "chrome" && e.version >= 71 || e.browser === "safari" && e.version >= 605)
1841
+ return;
1842
+ const t = r.RTCPeerConnection.prototype.setRemoteDescription;
1843
+ r.RTCPeerConnection.prototype.setRemoteDescription = function(i) {
1844
+ if (i && i.sdp && i.sdp.indexOf(`
1845
+ a=extmap-allow-mixed`) !== -1) {
1846
+ const s = i.sdp.split(`
1847
+ `).filter((o) => o.trim() !== "a=extmap-allow-mixed").join(`
1848
+ `);
1849
+ r.RTCSessionDescription && i instanceof r.RTCSessionDescription ? arguments[0] = new r.RTCSessionDescription({
1850
+ type: i.type,
1851
+ sdp: s
1852
+ }) : i.sdp = s;
1853
+ }
1854
+ return t.apply(this, arguments);
1855
+ };
1856
+ }
1857
+ function G(r, e) {
1858
+ if (!(r.RTCPeerConnection && r.RTCPeerConnection.prototype))
1859
+ return;
1860
+ const t = r.RTCPeerConnection.prototype.addIceCandidate;
1861
+ !t || t.length === 0 || (r.RTCPeerConnection.prototype.addIceCandidate = function() {
1862
+ return arguments[0] ? (e.browser === "chrome" && e.version < 78 || e.browser === "firefox" && e.version < 68 || e.browser === "safari") && arguments[0] && arguments[0].candidate === "" ? Promise.resolve() : t.apply(this, arguments) : (arguments[1] && arguments[1].apply(null), Promise.resolve());
1863
+ });
1864
+ }
1865
+ function V(r, e) {
1866
+ if (!(r.RTCPeerConnection && r.RTCPeerConnection.prototype))
1867
+ return;
1868
+ const t = r.RTCPeerConnection.prototype.setLocalDescription;
1869
+ !t || t.length === 0 || (r.RTCPeerConnection.prototype.setLocalDescription = function() {
1870
+ let i = arguments[0] || {};
1871
+ if (typeof i != "object" || i.type && i.sdp)
1872
+ return t.apply(this, arguments);
1873
+ if (i = { type: i.type, sdp: i.sdp }, !i.type)
1874
+ switch (this.signalingState) {
1875
+ case "stable":
1876
+ case "have-local-offer":
1877
+ case "have-remote-pranswer":
1878
+ i.type = "offer";
1879
+ break;
1880
+ default:
1881
+ i.type = "answer";
1882
+ break;
1883
+ }
1884
+ return i.sdp || i.type !== "offer" && i.type !== "answer" ? t.apply(this, [i]) : (i.type === "offer" ? this.createOffer : this.createAnswer).apply(this).then((o) => t.apply(this, [o]));
1885
+ });
1886
+ }
1887
+ const Et = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1888
+ __proto__: null,
1889
+ removeExtmapAllowMixed: re,
1890
+ shimAddIceCandidateNullOrEmpty: G,
1891
+ shimConnectionState: ne,
1892
+ shimMaxMessageSize: N,
1893
+ shimParameterlessSetLocalDescription: V,
1894
+ shimRTCIceCandidate: z,
1895
+ shimRTCIceCandidateRelayProtocol: te,
1896
+ shimSendThrowTypeError: J
1897
+ }, Symbol.toStringTag, { value: "Module" }));
1898
+ function Dt({ window: r } = {}, e = {
1899
+ shimChrome: !0,
1900
+ shimFirefox: !0,
1901
+ shimSafari: !0
1902
+ }) {
1903
+ const t = Ee, n = Tt(r), i = {
1904
+ browserDetails: n,
1905
+ commonShim: Et,
1906
+ extractVersion: U,
1907
+ disableLog: kt,
1908
+ disableWarnings: St,
1909
+ // Expose sdp as a convenience. For production apps include directly.
1910
+ sdp: Pt
1911
+ };
1912
+ switch (n.browser) {
1913
+ case "chrome":
1914
+ if (!ge || !w || !e.shimChrome)
1915
+ return t("Chrome shim is not included in this adapter release."), i;
1916
+ if (n.version === null)
1917
+ return t("Chrome shim can not determine version, not shimming."), i;
1918
+ t("adapter.js shimming chrome."), i.browserShim = ge, G(r, n), V(r), Ie(r, n), Me(r), w(r, n), Oe(r), Le(r, n), Ae(r), $e(r), Be(r, n), z(r), te(r), ne(r), N(r, n), J(r), re(r, n);
1919
+ break;
1920
+ case "firefox":
1921
+ if (!ye || !ee || !e.shimFirefox)
1922
+ return t("Firefox shim is not included in this adapter release."), i;
1923
+ t("adapter.js shimming firefox."), i.browserShim = ye, G(r, n), V(r), Fe(r, n), ee(r, n), Ue(r), Je(r), ze(r), Ne(r), Ge(r), Ve(r), He(r), Ye(r), Ke(r), z(r), ne(r), N(r, n), J(r);
1924
+ break;
1925
+ case "safari":
1926
+ if (!_e || !e.shimSafari)
1927
+ return t("Safari shim is not included in this adapter release."), i;
1928
+ t("adapter.js shimming safari."), i.browserShim = _e, G(r, n), V(r), we(r), tt(r), Xe(r), qe(r), We(r), et(r), Qe(r), nt(r), z(r), te(r), N(r, n), J(r), re(r, n);
1929
+ break;
1930
+ default:
1931
+ t("Unsupported browser!");
1932
+ break;
1933
+ }
1934
+ return i;
1935
+ }
1936
+ const be = Dt({ window: typeof window > "u" ? void 0 : window });
1937
+ function P(r, e, t, n) {
1938
+ Object.defineProperty(r, e, { get: t, set: n, enumerable: !0, configurable: !0 });
1939
+ }
1940
+ class it {
1941
+ constructor() {
1942
+ this.chunkedMTU = 16300, this._dataCount = 1, this.chunk = (e) => {
1943
+ const t = [], n = e.byteLength, i = Math.ceil(n / this.chunkedMTU);
1944
+ let s = 0, o = 0;
1945
+ for (; o < n; ) {
1946
+ const a = Math.min(n, o + this.chunkedMTU), c = e.slice(o, a), p = {
1947
+ __peerData: this._dataCount,
1948
+ n: s,
1949
+ data: c,
1950
+ total: i
1951
+ };
1952
+ t.push(p), o = a, s++;
1953
+ }
1954
+ return this._dataCount++, t;
1955
+ };
1956
+ }
1957
+ }
1958
+ function It(r) {
1959
+ let e = 0;
1960
+ for (const i of r) e += i.byteLength;
1961
+ const t = new Uint8Array(e);
1962
+ let n = 0;
1963
+ for (const i of r)
1964
+ t.set(i, n), n += i.byteLength;
1965
+ return t;
1966
+ }
1967
+ const X = (
1968
+ //@ts-ignore
1969
+ be.default || be
1970
+ ), O = new class {
1971
+ isWebRTCSupported() {
1972
+ return typeof RTCPeerConnection < "u";
1973
+ }
1974
+ isBrowserSupported() {
1975
+ const r = this.getBrowser(), e = this.getVersion();
1976
+ return this.supportedBrowsers.includes(r) ? r === "chrome" ? e >= this.minChromeVersion : r === "firefox" ? e >= this.minFirefoxVersion : r === "safari" ? !this.isIOS && e >= this.minSafariVersion : !1 : !1;
1977
+ }
1978
+ getBrowser() {
1979
+ return X.browserDetails.browser;
1980
+ }
1981
+ getVersion() {
1982
+ return X.browserDetails.version || 0;
1983
+ }
1984
+ isUnifiedPlanSupported() {
1985
+ const r = this.getBrowser(), e = X.browserDetails.version || 0;
1986
+ if (r === "chrome" && e < this.minChromeVersion) return !1;
1987
+ if (r === "firefox" && e >= this.minFirefoxVersion) return !0;
1988
+ if (!window.RTCRtpTransceiver || !("currentDirection" in RTCRtpTransceiver.prototype)) return !1;
1989
+ let t, n = !1;
1990
+ try {
1991
+ t = new RTCPeerConnection(), t.addTransceiver("audio"), n = !0;
1992
+ } catch {
1993
+ } finally {
1994
+ t && t.close();
1995
+ }
1996
+ return n;
1997
+ }
1998
+ toString() {
1999
+ return `Supports:
2000
+ browser:${this.getBrowser()}
2001
+ version:${this.getVersion()}
2002
+ isIOS:${this.isIOS}
2003
+ isWebRTCSupported:${this.isWebRTCSupported()}
2004
+ isBrowserSupported:${this.isBrowserSupported()}
2005
+ isUnifiedPlanSupported:${this.isUnifiedPlanSupported()}`;
2006
+ }
2007
+ constructor() {
2008
+ this.isIOS = typeof navigator < "u" ? [
2009
+ "iPad",
2010
+ "iPhone",
2011
+ "iPod"
2012
+ ].includes(navigator.platform) : !1, this.supportedBrowsers = [
2013
+ "firefox",
2014
+ "chrome",
2015
+ "safari"
2016
+ ], this.minFirefoxVersion = 59, this.minChromeVersion = 72, this.minSafariVersion = 605;
2017
+ }
2018
+ }(), Mt = (r) => !r || /^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(r), st = () => Math.random().toString(36).slice(2), ve = {
2019
+ iceServers: [
2020
+ {
2021
+ urls: "stun:stun.l.google.com:19302"
2022
+ },
2023
+ {
2024
+ urls: [
2025
+ "turn:eu-0.turn.peerjs.com:3478",
2026
+ "turn:us-0.turn.peerjs.com:3478"
2027
+ ],
2028
+ username: "peerjs",
2029
+ credential: "peerjsp"
2030
+ }
2031
+ ],
2032
+ sdpSemantics: "unified-plan"
2033
+ };
2034
+ class Ot extends it {
2035
+ noop() {
2036
+ }
2037
+ blobToArrayBuffer(e, t) {
2038
+ const n = new FileReader();
2039
+ return n.onload = function(i) {
2040
+ i.target && t(i.target.result);
2041
+ }, n.readAsArrayBuffer(e), n;
2042
+ }
2043
+ binaryStringToArrayBuffer(e) {
2044
+ const t = new Uint8Array(e.length);
2045
+ for (let n = 0; n < e.length; n++) t[n] = e.charCodeAt(n) & 255;
2046
+ return t.buffer;
2047
+ }
2048
+ isSecure() {
2049
+ return location.protocol === "https:";
2050
+ }
2051
+ constructor(...e) {
2052
+ super(...e), this.CLOUD_HOST = "0.peerjs.com", this.CLOUD_PORT = 443, this.chunkedBrowsers = {
2053
+ Chrome: 1,
2054
+ chrome: 1
2055
+ }, this.defaultConfig = ve, this.browser = O.getBrowser(), this.browserVersion = O.getVersion(), this.pack = Re, this.unpack = Te, this.supports = function() {
2056
+ const t = {
2057
+ browser: O.isBrowserSupported(),
2058
+ webRTC: O.isWebRTCSupported(),
2059
+ audioVideo: !1,
2060
+ data: !1,
2061
+ binaryBlob: !1,
2062
+ reliable: !1
2063
+ };
2064
+ if (!t.webRTC) return t;
2065
+ let n;
2066
+ try {
2067
+ n = new RTCPeerConnection(ve), t.audioVideo = !0;
2068
+ let i;
2069
+ try {
2070
+ i = n.createDataChannel("_PEERJSTEST", {
2071
+ ordered: !0
2072
+ }), t.data = !0, t.reliable = !!i.ordered;
2073
+ try {
2074
+ i.binaryType = "blob", t.binaryBlob = !O.isIOS;
2075
+ } catch {
2076
+ }
2077
+ } catch {
2078
+ } finally {
2079
+ i && i.close();
2080
+ }
2081
+ } catch {
2082
+ } finally {
2083
+ n && n.close();
2084
+ }
2085
+ return t;
2086
+ }(), this.validateId = Mt, this.randomToken = st;
2087
+ }
2088
+ }
2089
+ const k = new Ot(), At = "PeerJS: ";
2090
+ var ke;
2091
+ (function(r) {
2092
+ r[r.Disabled = 0] = "Disabled", r[r.Errors = 1] = "Errors", r[r.Warnings = 2] = "Warnings", r[r.All = 3] = "All";
2093
+ })(ke || (ke = {}));
2094
+ class $t {
2095
+ get logLevel() {
2096
+ return this._logLevel;
2097
+ }
2098
+ set logLevel(e) {
2099
+ this._logLevel = e;
2100
+ }
2101
+ log(...e) {
2102
+ this._logLevel >= 3 && this._print(3, ...e);
2103
+ }
2104
+ warn(...e) {
2105
+ this._logLevel >= 2 && this._print(2, ...e);
2106
+ }
2107
+ error(...e) {
2108
+ this._logLevel >= 1 && this._print(1, ...e);
2109
+ }
2110
+ setLogFunction(e) {
2111
+ this._print = e;
2112
+ }
2113
+ _print(e, ...t) {
2114
+ const n = [
2115
+ At,
2116
+ ...t
2117
+ ];
2118
+ for (const i in n) n[i] instanceof Error && (n[i] = "(" + n[i].name + ") " + n[i].message);
2119
+ e >= 3 ? console.log(...n) : e >= 2 ? console.warn("WARNING", ...n) : e >= 1 && console.error("ERROR", ...n);
2120
+ }
2121
+ constructor() {
2122
+ this._logLevel = 0;
2123
+ }
2124
+ }
2125
+ var u = new $t(), fe = {}, jt = Object.prototype.hasOwnProperty, v = "~";
2126
+ function j() {
2127
+ }
2128
+ Object.create && (j.prototype = /* @__PURE__ */ Object.create(null), new j().__proto__ || (v = !1));
2129
+ function Lt(r, e, t) {
2130
+ this.fn = r, this.context = e, this.once = t || !1;
2131
+ }
2132
+ function ot(r, e, t, n, i) {
2133
+ if (typeof t != "function") throw new TypeError("The listener must be a function");
2134
+ var s = new Lt(t, n || r, i), o = v ? v + e : e;
2135
+ return r._events[o] ? r._events[o].fn ? r._events[o] = [
2136
+ r._events[o],
2137
+ s
2138
+ ] : r._events[o].push(s) : (r._events[o] = s, r._eventsCount++), r;
2139
+ }
2140
+ function H(r, e) {
2141
+ --r._eventsCount === 0 ? r._events = new j() : delete r._events[e];
2142
+ }
2143
+ function C() {
2144
+ this._events = new j(), this._eventsCount = 0;
2145
+ }
2146
+ C.prototype.eventNames = function() {
2147
+ var e = [], t, n;
2148
+ if (this._eventsCount === 0) return e;
2149
+ for (n in t = this._events) jt.call(t, n) && e.push(v ? n.slice(1) : n);
2150
+ return Object.getOwnPropertySymbols ? e.concat(Object.getOwnPropertySymbols(t)) : e;
2151
+ };
2152
+ C.prototype.listeners = function(e) {
2153
+ var t = v ? v + e : e, n = this._events[t];
2154
+ if (!n) return [];
2155
+ if (n.fn) return [
2156
+ n.fn
2157
+ ];
2158
+ for (var i = 0, s = n.length, o = new Array(s); i < s; i++) o[i] = n[i].fn;
2159
+ return o;
2160
+ };
2161
+ C.prototype.listenerCount = function(e) {
2162
+ var t = v ? v + e : e, n = this._events[t];
2163
+ return n ? n.fn ? 1 : n.length : 0;
2164
+ };
2165
+ C.prototype.emit = function(e, t, n, i, s, o) {
2166
+ var a = v ? v + e : e;
2167
+ if (!this._events[a]) return !1;
2168
+ var c = this._events[a], p = arguments.length, f, h;
2169
+ if (c.fn) {
2170
+ switch (c.once && this.removeListener(e, c.fn, void 0, !0), p) {
2171
+ case 1:
2172
+ return c.fn.call(c.context), !0;
2173
+ case 2:
2174
+ return c.fn.call(c.context, t), !0;
2175
+ case 3:
2176
+ return c.fn.call(c.context, t, n), !0;
2177
+ case 4:
2178
+ return c.fn.call(c.context, t, n, i), !0;
2179
+ case 5:
2180
+ return c.fn.call(c.context, t, n, i, s), !0;
2181
+ case 6:
2182
+ return c.fn.call(c.context, t, n, i, s, o), !0;
2183
+ }
2184
+ for (h = 1, f = new Array(p - 1); h < p; h++) f[h - 1] = arguments[h];
2185
+ c.fn.apply(c.context, f);
2186
+ } else {
2187
+ var l = c.length, d;
2188
+ for (h = 0; h < l; h++)
2189
+ switch (c[h].once && this.removeListener(e, c[h].fn, void 0, !0), p) {
2190
+ case 1:
2191
+ c[h].fn.call(c[h].context);
2192
+ break;
2193
+ case 2:
2194
+ c[h].fn.call(c[h].context, t);
2195
+ break;
2196
+ case 3:
2197
+ c[h].fn.call(c[h].context, t, n);
2198
+ break;
2199
+ case 4:
2200
+ c[h].fn.call(c[h].context, t, n, i);
2201
+ break;
2202
+ default:
2203
+ if (!f) for (d = 1, f = new Array(p - 1); d < p; d++) f[d - 1] = arguments[d];
2204
+ c[h].fn.apply(c[h].context, f);
2205
+ }
2206
+ }
2207
+ return !0;
2208
+ };
2209
+ C.prototype.on = function(e, t, n) {
2210
+ return ot(this, e, t, n, !1);
2211
+ };
2212
+ C.prototype.once = function(e, t, n) {
2213
+ return ot(this, e, t, n, !0);
2214
+ };
2215
+ C.prototype.removeListener = function(e, t, n, i) {
2216
+ var s = v ? v + e : e;
2217
+ if (!this._events[s]) return this;
2218
+ if (!t)
2219
+ return H(this, s), this;
2220
+ var o = this._events[s];
2221
+ if (o.fn)
2222
+ o.fn === t && (!i || o.once) && (!n || o.context === n) && H(this, s);
2223
+ else {
2224
+ for (var a = 0, c = [], p = o.length; a < p; a++) (o[a].fn !== t || i && !o[a].once || n && o[a].context !== n) && c.push(o[a]);
2225
+ c.length ? this._events[s] = c.length === 1 ? c[0] : c : H(this, s);
2226
+ }
2227
+ return this;
2228
+ };
2229
+ C.prototype.removeAllListeners = function(e) {
2230
+ var t;
2231
+ return e ? (t = v ? v + e : e, this._events[t] && H(this, t)) : (this._events = new j(), this._eventsCount = 0), this;
2232
+ };
2233
+ C.prototype.off = C.prototype.removeListener;
2234
+ C.prototype.addListener = C.prototype.on;
2235
+ C.prefixed = v;
2236
+ C.EventEmitter = C;
2237
+ fe = C;
2238
+ var E = {};
2239
+ P(E, "ConnectionType", () => T);
2240
+ P(E, "PeerErrorType", () => g);
2241
+ P(E, "BaseConnectionErrorType", () => L);
2242
+ P(E, "DataConnectionErrorType", () => B);
2243
+ P(E, "SerializationType", () => I);
2244
+ P(E, "SocketEventType", () => S);
2245
+ P(E, "ServerMessageType", () => _);
2246
+ var T;
2247
+ (function(r) {
2248
+ r.Data = "data", r.Media = "media";
2249
+ })(T || (T = {}));
2250
+ var g;
2251
+ (function(r) {
2252
+ r.BrowserIncompatible = "browser-incompatible", r.Disconnected = "disconnected", r.InvalidID = "invalid-id", r.InvalidKey = "invalid-key", r.Network = "network", r.PeerUnavailable = "peer-unavailable", r.SslUnavailable = "ssl-unavailable", r.ServerError = "server-error", r.SocketError = "socket-error", r.SocketClosed = "socket-closed", r.UnavailableID = "unavailable-id", r.WebRTC = "webrtc";
2253
+ })(g || (g = {}));
2254
+ var L;
2255
+ (function(r) {
2256
+ r.NegotiationFailed = "negotiation-failed", r.ConnectionClosed = "connection-closed";
2257
+ })(L || (L = {}));
2258
+ var B;
2259
+ (function(r) {
2260
+ r.NotOpenYet = "not-open-yet", r.MessageToBig = "message-too-big";
2261
+ })(B || (B = {}));
2262
+ var I;
2263
+ (function(r) {
2264
+ r.Binary = "binary", r.BinaryUTF8 = "binary-utf8", r.JSON = "json", r.None = "raw";
2265
+ })(I || (I = {}));
2266
+ var S;
2267
+ (function(r) {
2268
+ r.Message = "message", r.Disconnected = "disconnected", r.Error = "error", r.Close = "close";
2269
+ })(S || (S = {}));
2270
+ var _;
2271
+ (function(r) {
2272
+ r.Heartbeat = "HEARTBEAT", r.Candidate = "CANDIDATE", r.Offer = "OFFER", r.Answer = "ANSWER", r.Open = "OPEN", r.Error = "ERROR", r.IdTaken = "ID-TAKEN", r.InvalidKey = "INVALID-KEY", r.Leave = "LEAVE", r.Expire = "EXPIRE";
2273
+ })(_ || (_ = {}));
2274
+ var he = {};
2275
+ he = JSON.parse('{"name":"peerjs","version":"1.5.4","keywords":["peerjs","webrtc","p2p","rtc"],"description":"PeerJS client","homepage":"https://peerjs.com","bugs":{"url":"https://github.com/peers/peerjs/issues"},"repository":{"type":"git","url":"https://github.com/peers/peerjs"},"license":"MIT","contributors":["Michelle Bu <michelle@michellebu.com>","afrokick <devbyru@gmail.com>","ericz <really.ez@gmail.com>","Jairo <kidandcat@gmail.com>","Jonas Gloning <34194370+jonasgloning@users.noreply.github.com>","Jairo Caro-Accino Viciana <jairo@galax.be>","Carlos Caballero <carlos.caballero.gonzalez@gmail.com>","hc <hheennrryy@gmail.com>","Muhammad Asif <capripio@gmail.com>","PrashoonB <prashoonbhattacharjee@gmail.com>","Harsh Bardhan Mishra <47351025+HarshCasper@users.noreply.github.com>","akotynski <aleksanderkotbury@gmail.com>","lmb <i@lmb.io>","Jairooo <jairocaro@msn.com>","Moritz Stückler <moritz.stueckler@gmail.com>","Simon <crydotsnakegithub@gmail.com>","Denis Lukov <denismassters@gmail.com>","Philipp Hancke <fippo@andyet.net>","Hans Oksendahl <hansoksendahl@gmail.com>","Jess <jessachandler@gmail.com>","khankuan <khankuan@gmail.com>","DUODVK <kurmanov.work@gmail.com>","XiZhao <kwang1imsa@gmail.com>","Matthias Lohr <matthias@lohr.me>","=frank tree <=frnktrb@googlemail.com>","Andre Eckardt <aeckardt@outlook.com>","Chris Cowan <agentme49@gmail.com>","Alex Chuev <alex@chuev.com>","alxnull <alxnull@e.mail.de>","Yemel Jardi <angel.jardi@gmail.com>","Ben Parnell <benjaminparnell.94@gmail.com>","Benny Lichtner <bennlich@gmail.com>","fresheneesz <bitetrudpublic@gmail.com>","bob.barstead@exaptive.com <bob.barstead@exaptive.com>","chandika <chandika@gmail.com>","emersion <contact@emersion.fr>","Christopher Van <cvan@users.noreply.github.com>","eddieherm <edhermoso@gmail.com>","Eduardo Pinho <enet4mikeenet@gmail.com>","Evandro Zanatta <ezanatta@tray.net.br>","Gardner Bickford <gardner@users.noreply.github.com>","Gian Luca <gianluca.cecchi@cynny.com>","PatrickJS <github@gdi2290.com>","jonnyf <github@jonathanfoss.co.uk>","Hizkia Felix <hizkifw@gmail.com>","Hristo Oskov <hristo.oskov@gmail.com>","Isaac Madwed <i.madwed@gmail.com>","Ilya Konanykhin <ilya.konanykhin@gmail.com>","jasonbarry <jasbarry@me.com>","Jonathan Burke <jonathan.burke.1311@googlemail.com>","Josh Hamit <josh.hamit@gmail.com>","Jordan Austin <jrax86@gmail.com>","Joel Wetzell <jwetzell@yahoo.com>","xizhao <kevin.wang@cloudera.com>","Alberto Torres <kungfoobar@gmail.com>","Jonathan Mayol <mayoljonathan@gmail.com>","Jefferson Felix <me@jsfelix.dev>","Rolf Erik Lekang <me@rolflekang.com>","Kevin Mai-Husan Chia <mhchia@users.noreply.github.com>","Pepijn de Vos <pepijndevos@gmail.com>","JooYoung <qkdlql@naver.com>","Tobias Speicher <rootcommander@gmail.com>","Steve Blaurock <sblaurock@gmail.com>","Kyrylo Shegeda <shegeda@ualberta.ca>","Diwank Singh Tomer <singh@diwank.name>","Sören Balko <Soeren.Balko@gmail.com>","Arpit Solanki <solankiarpit1997@gmail.com>","Yuki Ito <yuki@gnnk.net>","Artur Zayats <zag2art@gmail.com>"],"funding":{"type":"opencollective","url":"https://opencollective.com/peer"},"collective":{"type":"opencollective","url":"https://opencollective.com/peer"},"files":["dist/*"],"sideEffects":["lib/global.ts","lib/supports.ts"],"main":"dist/bundler.cjs","module":"dist/bundler.mjs","browser-minified":"dist/peerjs.min.js","browser-unminified":"dist/peerjs.js","browser-minified-msgpack":"dist/serializer.msgpack.mjs","types":"dist/types.d.ts","engines":{"node":">= 14"},"targets":{"types":{"source":"lib/exports.ts"},"main":{"source":"lib/exports.ts","sourceMap":{"inlineSources":true}},"module":{"source":"lib/exports.ts","includeNodeModules":["eventemitter3"],"sourceMap":{"inlineSources":true}},"browser-minified":{"context":"browser","outputFormat":"global","optimize":true,"engines":{"browsers":"chrome >= 83, edge >= 83, firefox >= 80, safari >= 15"},"source":"lib/global.ts"},"browser-unminified":{"context":"browser","outputFormat":"global","optimize":false,"engines":{"browsers":"chrome >= 83, edge >= 83, firefox >= 80, safari >= 15"},"source":"lib/global.ts"},"browser-minified-msgpack":{"context":"browser","outputFormat":"esmodule","isLibrary":true,"optimize":true,"engines":{"browsers":"chrome >= 83, edge >= 83, firefox >= 102, safari >= 15"},"source":"lib/dataconnection/StreamConnection/MsgPack.ts"}},"scripts":{"contributors":"git-authors-cli --print=false && prettier --write package.json && git add package.json package-lock.json && git commit -m \\"chore(contributors): update and sort contributors list\\"","check":"tsc --noEmit && tsc -p e2e/tsconfig.json --noEmit","watch":"parcel watch","build":"rm -rf dist && parcel build","prepublishOnly":"npm run build","test":"jest","test:watch":"jest --watch","coverage":"jest --coverage --collectCoverageFrom=\\"./lib/**\\"","format":"prettier --write .","format:check":"prettier --check .","semantic-release":"semantic-release","e2e":"wdio run e2e/wdio.local.conf.ts","e2e:bstack":"wdio run e2e/wdio.bstack.conf.ts"},"devDependencies":{"@parcel/config-default":"^2.9.3","@parcel/packager-ts":"^2.9.3","@parcel/transformer-typescript-tsc":"^2.9.3","@parcel/transformer-typescript-types":"^2.9.3","@semantic-release/changelog":"^6.0.1","@semantic-release/git":"^10.0.1","@swc/core":"^1.3.27","@swc/jest":"^0.2.24","@types/jasmine":"^4.3.4","@wdio/browserstack-service":"^8.11.2","@wdio/cli":"^8.11.2","@wdio/globals":"^8.11.2","@wdio/jasmine-framework":"^8.11.2","@wdio/local-runner":"^8.11.2","@wdio/spec-reporter":"^8.11.2","@wdio/types":"^8.10.4","http-server":"^14.1.1","jest":"^29.3.1","jest-environment-jsdom":"^29.3.1","mock-socket":"^9.0.0","parcel":"^2.9.3","prettier":"^3.0.0","semantic-release":"^21.0.0","ts-node":"^10.9.1","typescript":"^5.0.0","wdio-geckodriver-service":"^5.0.1"},"dependencies":{"@msgpack/msgpack":"^2.8.0","eventemitter3":"^4.0.7","peerjs-js-binarypack":"^2.1.0","webrtc-adapter":"^9.0.0"},"alias":{"process":false,"buffer":false}}');
2276
+ class Bt extends fe.EventEmitter {
2277
+ constructor(e, t, n, i, s, o = 5e3) {
2278
+ super(), this.pingInterval = o, this._disconnected = !0, this._messagesQueue = [];
2279
+ const a = e ? "wss://" : "ws://";
2280
+ this._baseUrl = a + t + ":" + n + i + "peerjs?key=" + s;
2281
+ }
2282
+ start(e, t) {
2283
+ this._id = e;
2284
+ const n = `${this._baseUrl}&id=${e}&token=${t}`;
2285
+ this._socket || !this._disconnected || (this._socket = new WebSocket(n + "&version=" + he.version), this._disconnected = !1, this._socket.onmessage = (i) => {
2286
+ let s;
2287
+ try {
2288
+ s = JSON.parse(i.data), u.log("Server message received:", s);
2289
+ } catch {
2290
+ u.log("Invalid server message", i.data);
2291
+ return;
2292
+ }
2293
+ this.emit(S.Message, s);
2294
+ }, this._socket.onclose = (i) => {
2295
+ this._disconnected || (u.log("Socket closed.", i), this._cleanup(), this._disconnected = !0, this.emit(S.Disconnected));
2296
+ }, this._socket.onopen = () => {
2297
+ this._disconnected || (this._sendQueuedMessages(), u.log("Socket open"), this._scheduleHeartbeat());
2298
+ });
2299
+ }
2300
+ _scheduleHeartbeat() {
2301
+ this._wsPingTimer = setTimeout(() => {
2302
+ this._sendHeartbeat();
2303
+ }, this.pingInterval);
2304
+ }
2305
+ _sendHeartbeat() {
2306
+ if (!this._wsOpen()) {
2307
+ u.log("Cannot send heartbeat, because socket closed");
2308
+ return;
2309
+ }
2310
+ const e = JSON.stringify({
2311
+ type: _.Heartbeat
2312
+ });
2313
+ this._socket.send(e), this._scheduleHeartbeat();
2314
+ }
2315
+ /** Is the websocket currently open? */
2316
+ _wsOpen() {
2317
+ return !!this._socket && this._socket.readyState === 1;
2318
+ }
2319
+ /** Send queued messages. */
2320
+ _sendQueuedMessages() {
2321
+ const e = [
2322
+ ...this._messagesQueue
2323
+ ];
2324
+ this._messagesQueue = [];
2325
+ for (const t of e) this.send(t);
2326
+ }
2327
+ /** Exposed send for DC & Peer. */
2328
+ send(e) {
2329
+ if (this._disconnected) return;
2330
+ if (!this._id) {
2331
+ this._messagesQueue.push(e);
2332
+ return;
2333
+ }
2334
+ if (!e.type) {
2335
+ this.emit(S.Error, "Invalid message");
2336
+ return;
2337
+ }
2338
+ if (!this._wsOpen()) return;
2339
+ const t = JSON.stringify(e);
2340
+ this._socket.send(t);
2341
+ }
2342
+ close() {
2343
+ this._disconnected || (this._cleanup(), this._disconnected = !0);
2344
+ }
2345
+ _cleanup() {
2346
+ this._socket && (this._socket.onopen = this._socket.onmessage = this._socket.onclose = null, this._socket.close(), this._socket = void 0), clearTimeout(this._wsPingTimer);
2347
+ }
2348
+ }
2349
+ class at {
2350
+ constructor(e) {
2351
+ this.connection = e;
2352
+ }
2353
+ /** Returns a PeerConnection object set up correctly (for data, media). */
2354
+ startConnection(e) {
2355
+ const t = this._startPeerConnection();
2356
+ if (this.connection.peerConnection = t, this.connection.type === T.Media && e._stream && this._addTracksToConnection(e._stream, t), e.originator) {
2357
+ const n = this.connection, i = {
2358
+ ordered: !!e.reliable
2359
+ }, s = t.createDataChannel(n.label, i);
2360
+ n._initializeDataChannel(s), this._makeOffer();
2361
+ } else this.handleSDP("OFFER", e.sdp);
2362
+ }
2363
+ /** Start a PC. */
2364
+ _startPeerConnection() {
2365
+ u.log("Creating RTCPeerConnection.");
2366
+ const e = new RTCPeerConnection(this.connection.provider.options.config);
2367
+ return this._setupListeners(e), e;
2368
+ }
2369
+ /** Set up various WebRTC listeners. */
2370
+ _setupListeners(e) {
2371
+ const t = this.connection.peer, n = this.connection.connectionId, i = this.connection.type, s = this.connection.provider;
2372
+ u.log("Listening for ICE candidates."), e.onicecandidate = (o) => {
2373
+ !o.candidate || !o.candidate.candidate || (u.log(`Received ICE candidates for ${t}:`, o.candidate), s.socket.send({
2374
+ type: _.Candidate,
2375
+ payload: {
2376
+ candidate: o.candidate,
2377
+ type: i,
2378
+ connectionId: n
2379
+ },
2380
+ dst: t
2381
+ }));
2382
+ }, e.oniceconnectionstatechange = () => {
2383
+ switch (e.iceConnectionState) {
2384
+ case "failed":
2385
+ u.log("iceConnectionState is failed, closing connections to " + t), this.connection.emitError(L.NegotiationFailed, "Negotiation of connection to " + t + " failed."), this.connection.close();
2386
+ break;
2387
+ case "closed":
2388
+ u.log("iceConnectionState is closed, closing connections to " + t), this.connection.emitError(L.ConnectionClosed, "Connection to " + t + " closed."), this.connection.close();
2389
+ break;
2390
+ case "disconnected":
2391
+ u.log("iceConnectionState changed to disconnected on the connection with " + t);
2392
+ break;
2393
+ case "completed":
2394
+ e.onicecandidate = () => {
2395
+ };
2396
+ break;
2397
+ }
2398
+ this.connection.emit("iceStateChanged", e.iceConnectionState);
2399
+ }, u.log("Listening for data channel"), e.ondatachannel = (o) => {
2400
+ u.log("Received data channel");
2401
+ const a = o.channel;
2402
+ s.getConnection(t, n)._initializeDataChannel(a);
2403
+ }, u.log("Listening for remote stream"), e.ontrack = (o) => {
2404
+ u.log("Received remote stream");
2405
+ const a = o.streams[0], c = s.getConnection(t, n);
2406
+ if (c.type === T.Media) {
2407
+ const p = c;
2408
+ this._addStreamToMediaConnection(a, p);
2409
+ }
2410
+ };
2411
+ }
2412
+ cleanup() {
2413
+ u.log("Cleaning up PeerConnection to " + this.connection.peer);
2414
+ const e = this.connection.peerConnection;
2415
+ if (!e) return;
2416
+ this.connection.peerConnection = null, e.onicecandidate = e.oniceconnectionstatechange = e.ondatachannel = e.ontrack = () => {
2417
+ };
2418
+ const t = e.signalingState !== "closed";
2419
+ let n = !1;
2420
+ const i = this.connection.dataChannel;
2421
+ i && (n = !!i.readyState && i.readyState !== "closed"), (t || n) && e.close();
2422
+ }
2423
+ async _makeOffer() {
2424
+ const e = this.connection.peerConnection, t = this.connection.provider;
2425
+ try {
2426
+ const n = await e.createOffer(this.connection.options.constraints);
2427
+ u.log("Created offer."), this.connection.options.sdpTransform && typeof this.connection.options.sdpTransform == "function" && (n.sdp = this.connection.options.sdpTransform(n.sdp) || n.sdp);
2428
+ try {
2429
+ await e.setLocalDescription(n), u.log("Set localDescription:", n, `for:${this.connection.peer}`);
2430
+ let i = {
2431
+ sdp: n,
2432
+ type: this.connection.type,
2433
+ connectionId: this.connection.connectionId,
2434
+ metadata: this.connection.metadata
2435
+ };
2436
+ if (this.connection.type === T.Data) {
2437
+ const s = this.connection;
2438
+ i = {
2439
+ ...i,
2440
+ label: s.label,
2441
+ reliable: s.reliable,
2442
+ serialization: s.serialization
2443
+ };
2444
+ }
2445
+ t.socket.send({
2446
+ type: _.Offer,
2447
+ payload: i,
2448
+ dst: this.connection.peer
2449
+ });
2450
+ } catch (i) {
2451
+ i != "OperationError: Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer" && (t.emitError(g.WebRTC, i), u.log("Failed to setLocalDescription, ", i));
2452
+ }
2453
+ } catch (n) {
2454
+ t.emitError(g.WebRTC, n), u.log("Failed to createOffer, ", n);
2455
+ }
2456
+ }
2457
+ async _makeAnswer() {
2458
+ const e = this.connection.peerConnection, t = this.connection.provider;
2459
+ try {
2460
+ const n = await e.createAnswer();
2461
+ u.log("Created answer."), this.connection.options.sdpTransform && typeof this.connection.options.sdpTransform == "function" && (n.sdp = this.connection.options.sdpTransform(n.sdp) || n.sdp);
2462
+ try {
2463
+ await e.setLocalDescription(n), u.log("Set localDescription:", n, `for:${this.connection.peer}`), t.socket.send({
2464
+ type: _.Answer,
2465
+ payload: {
2466
+ sdp: n,
2467
+ type: this.connection.type,
2468
+ connectionId: this.connection.connectionId
2469
+ },
2470
+ dst: this.connection.peer
2471
+ });
2472
+ } catch (i) {
2473
+ t.emitError(g.WebRTC, i), u.log("Failed to setLocalDescription, ", i);
2474
+ }
2475
+ } catch (n) {
2476
+ t.emitError(g.WebRTC, n), u.log("Failed to create answer, ", n);
2477
+ }
2478
+ }
2479
+ /** Handle an SDP. */
2480
+ async handleSDP(e, t) {
2481
+ t = new RTCSessionDescription(t);
2482
+ const n = this.connection.peerConnection, i = this.connection.provider;
2483
+ u.log("Setting remote description", t);
2484
+ const s = this;
2485
+ try {
2486
+ await n.setRemoteDescription(t), u.log(`Set remoteDescription:${e} for:${this.connection.peer}`), e === "OFFER" && await s._makeAnswer();
2487
+ } catch (o) {
2488
+ i.emitError(g.WebRTC, o), u.log("Failed to setRemoteDescription, ", o);
2489
+ }
2490
+ }
2491
+ /** Handle a candidate. */
2492
+ async handleCandidate(e) {
2493
+ u.log("handleCandidate:", e);
2494
+ try {
2495
+ await this.connection.peerConnection.addIceCandidate(e), u.log(`Added ICE candidate for:${this.connection.peer}`);
2496
+ } catch (t) {
2497
+ this.connection.provider.emitError(g.WebRTC, t), u.log("Failed to handleCandidate, ", t);
2498
+ }
2499
+ }
2500
+ _addTracksToConnection(e, t) {
2501
+ if (u.log(`add tracks from stream ${e.id} to peer connection`), !t.addTrack) return u.error("Your browser does't support RTCPeerConnection#addTrack. Ignored.");
2502
+ e.getTracks().forEach((n) => {
2503
+ t.addTrack(n, e);
2504
+ });
2505
+ }
2506
+ _addStreamToMediaConnection(e, t) {
2507
+ u.log(`add stream ${e.id} to media connection ${t.connectionId}`), t.addStream(e);
2508
+ }
2509
+ }
2510
+ class ct extends fe.EventEmitter {
2511
+ /**
2512
+ * Emits a typed error message.
2513
+ *
2514
+ * @internal
2515
+ */
2516
+ emitError(e, t) {
2517
+ u.error("Error:", t), this.emit("error", new Ft(`${e}`, t));
2518
+ }
2519
+ }
2520
+ class Ft extends Error {
2521
+ /**
2522
+ * @internal
2523
+ */
2524
+ constructor(e, t) {
2525
+ typeof t == "string" ? super(t) : (super(), Object.assign(this, t)), this.type = e;
2526
+ }
2527
+ }
2528
+ class pt extends ct {
2529
+ /**
2530
+ * Whether the media connection is active (e.g. your call has been answered).
2531
+ * You can check this if you want to set a maximum wait time for a one-sided call.
2532
+ */
2533
+ get open() {
2534
+ return this._open;
2535
+ }
2536
+ constructor(e, t, n) {
2537
+ super(), this.peer = e, this.provider = t, this.options = n, this._open = !1, this.metadata = n.metadata;
2538
+ }
2539
+ }
2540
+ var se;
2541
+ const A = class A extends pt {
2542
+ /**
2543
+ * For media connections, this is always 'media'.
2544
+ */
2545
+ get type() {
2546
+ return T.Media;
2547
+ }
2548
+ get localStream() {
2549
+ return this._localStream;
2550
+ }
2551
+ get remoteStream() {
2552
+ return this._remoteStream;
2553
+ }
2554
+ constructor(e, t, n) {
2555
+ super(e, t, n), this._localStream = this.options._stream, this.connectionId = this.options.connectionId || A.ID_PREFIX + k.randomToken(), this._negotiator = new at(this), this._localStream && this._negotiator.startConnection({
2556
+ _stream: this._localStream,
2557
+ originator: !0
2558
+ });
2559
+ }
2560
+ /** Called by the Negotiator when the DataChannel is ready. */
2561
+ _initializeDataChannel(e) {
2562
+ this.dataChannel = e, this.dataChannel.onopen = () => {
2563
+ u.log(`DC#${this.connectionId} dc connection success`), this.emit("willCloseOnRemote");
2564
+ }, this.dataChannel.onclose = () => {
2565
+ u.log(`DC#${this.connectionId} dc closed for:`, this.peer), this.close();
2566
+ };
2567
+ }
2568
+ addStream(e) {
2569
+ u.log("Receiving stream", e), this._remoteStream = e, super.emit("stream", e);
2570
+ }
2571
+ /**
2572
+ * @internal
2573
+ */
2574
+ handleMessage(e) {
2575
+ const t = e.type, n = e.payload;
2576
+ switch (e.type) {
2577
+ case _.Answer:
2578
+ this._negotiator.handleSDP(t, n.sdp), this._open = !0;
2579
+ break;
2580
+ case _.Candidate:
2581
+ this._negotiator.handleCandidate(n.candidate);
2582
+ break;
2583
+ default:
2584
+ u.warn(`Unrecognized message type:${t} from peer:${this.peer}`);
2585
+ break;
2586
+ }
2587
+ }
2588
+ /**
2589
+ * When receiving a {@apilink PeerEvents | `call`} event on a peer, you can call
2590
+ * `answer` on the media connection provided by the callback to accept the call
2591
+ * and optionally send your own media stream.
2592
+
2593
+ *
2594
+ * @param stream A WebRTC media stream.
2595
+ * @param options
2596
+ * @returns
2597
+ */
2598
+ answer(e, t = {}) {
2599
+ if (this._localStream) {
2600
+ u.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");
2601
+ return;
2602
+ }
2603
+ this._localStream = e, t && t.sdpTransform && (this.options.sdpTransform = t.sdpTransform), this._negotiator.startConnection({
2604
+ ...this.options._payload,
2605
+ _stream: e
2606
+ });
2607
+ const n = this.provider._getMessages(this.connectionId);
2608
+ for (const i of n) this.handleMessage(i);
2609
+ this._open = !0;
2610
+ }
2611
+ /**
2612
+ * Exposed functionality for users.
2613
+ */
2614
+ /**
2615
+ * Closes the media connection.
2616
+ */
2617
+ close() {
2618
+ this._negotiator && (this._negotiator.cleanup(), this._negotiator = null), this._localStream = null, this._remoteStream = null, this.provider && (this.provider._removeConnection(this), this.provider = null), this.options && this.options._stream && (this.options._stream = null), this.open && (this._open = !1, super.emit("close"));
2619
+ }
2620
+ };
2621
+ se = new WeakMap(), M(A, se, A.ID_PREFIX = "mc_");
2622
+ let Y = A;
2623
+ class Ut {
2624
+ constructor(e) {
2625
+ this._options = e;
2626
+ }
2627
+ _buildRequest(e) {
2628
+ const t = this._options.secure ? "https" : "http", { host: n, port: i, path: s, key: o } = this._options, a = new URL(`${t}://${n}:${i}${s}${o}/${e}`);
2629
+ return a.searchParams.set("ts", `${Date.now()}${Math.random()}`), a.searchParams.set("version", he.version), fetch(a.href, {
2630
+ referrerPolicy: this._options.referrerPolicy
2631
+ });
2632
+ }
2633
+ /** Get a unique ID from the server via XHR and initialize with it. */
2634
+ async retrieveId() {
2635
+ try {
2636
+ const e = await this._buildRequest("id");
2637
+ if (e.status !== 200) throw new Error(`Error. Status:${e.status}`);
2638
+ return e.text();
2639
+ } catch (e) {
2640
+ u.error("Error retrieving ID", e);
2641
+ let t = "";
2642
+ throw this._options.path === "/" && this._options.host !== k.CLOUD_HOST && (t = " If you passed in a `path` to your self-hosted PeerServer, you'll also need to pass in that same path when creating a new Peer."), new Error("Could not get an ID from the server." + t);
2643
+ }
2644
+ }
2645
+ /** @deprecated */
2646
+ async listAllPeers() {
2647
+ try {
2648
+ const e = await this._buildRequest("peers");
2649
+ if (e.status !== 200) {
2650
+ if (e.status === 401) {
2651
+ let t = "";
2652
+ throw this._options.host === k.CLOUD_HOST ? t = "It looks like you're using the cloud server. You can email team@peerjs.com to enable peer listing for your API key." : t = "You need to enable `allow_discovery` on your self-hosted PeerServer to use this feature.", new Error("It doesn't look like you have permission to list peers IDs. " + t);
2653
+ }
2654
+ throw new Error(`Error. Status:${e.status}`);
2655
+ }
2656
+ return e.json();
2657
+ } catch (e) {
2658
+ throw u.error("Error retrieving list peers", e), new Error("Could not get list peers from the server." + e);
2659
+ }
2660
+ }
2661
+ }
2662
+ var oe, ae;
2663
+ const R = class R extends pt {
2664
+ get type() {
2665
+ return T.Data;
2666
+ }
2667
+ constructor(e, t, n) {
2668
+ super(e, t, n), this.connectionId = this.options.connectionId || R.ID_PREFIX + st(), this.label = this.options.label || this.connectionId, this.reliable = !!this.options.reliable, this._negotiator = new at(this), this._negotiator.startConnection(this.options._payload || {
2669
+ originator: !0,
2670
+ reliable: this.reliable
2671
+ });
2672
+ }
2673
+ /** Called by the Negotiator when the DataChannel is ready. */
2674
+ _initializeDataChannel(e) {
2675
+ this.dataChannel = e, this.dataChannel.onopen = () => {
2676
+ u.log(`DC#${this.connectionId} dc connection success`), this._open = !0, this.emit("open");
2677
+ }, this.dataChannel.onmessage = (t) => {
2678
+ u.log(`DC#${this.connectionId} dc onmessage:`, t.data);
2679
+ }, this.dataChannel.onclose = () => {
2680
+ u.log(`DC#${this.connectionId} dc closed for:`, this.peer), this.close();
2681
+ };
2682
+ }
2683
+ /**
2684
+ * Exposed functionality for users.
2685
+ */
2686
+ /** Allows user to close connection. */
2687
+ close(e) {
2688
+ if (e != null && e.flush) {
2689
+ this.send({
2690
+ __peerData: {
2691
+ type: "close"
2692
+ }
2693
+ });
2694
+ return;
2695
+ }
2696
+ this._negotiator && (this._negotiator.cleanup(), this._negotiator = null), this.provider && (this.provider._removeConnection(this), this.provider = null), this.dataChannel && (this.dataChannel.onopen = null, this.dataChannel.onmessage = null, this.dataChannel.onclose = null, this.dataChannel = null), this.open && (this._open = !1, super.emit("close"));
2697
+ }
2698
+ /** Allows user to send data. */
2699
+ send(e, t = !1) {
2700
+ if (!this.open) {
2701
+ this.emitError(B.NotOpenYet, "Connection is not open. You should listen for the `open` event before sending messages.");
2702
+ return;
2703
+ }
2704
+ return this._send(e, t);
2705
+ }
2706
+ async handleMessage(e) {
2707
+ const t = e.payload;
2708
+ switch (e.type) {
2709
+ case _.Answer:
2710
+ await this._negotiator.handleSDP(e.type, t.sdp);
2711
+ break;
2712
+ case _.Candidate:
2713
+ await this._negotiator.handleCandidate(t.candidate);
2714
+ break;
2715
+ default:
2716
+ u.warn("Unrecognized message type:", e.type, "from peer:", this.peer);
2717
+ break;
2718
+ }
2719
+ }
2720
+ };
2721
+ oe = new WeakMap(), ae = new WeakMap(), M(R, oe, R.ID_PREFIX = "dc_"), M(R, ae, R.MAX_BUFFERED_AMOUNT = 8388608);
2722
+ let K = R;
2723
+ class le extends K {
2724
+ get bufferSize() {
2725
+ return this._bufferSize;
2726
+ }
2727
+ _initializeDataChannel(e) {
2728
+ super._initializeDataChannel(e), this.dataChannel.binaryType = "arraybuffer", this.dataChannel.addEventListener("message", (t) => this._handleDataMessage(t));
2729
+ }
2730
+ _bufferedSend(e) {
2731
+ (this._buffering || !this._trySend(e)) && (this._buffer.push(e), this._bufferSize = this._buffer.length);
2732
+ }
2733
+ // Returns true if the send succeeds.
2734
+ _trySend(e) {
2735
+ if (!this.open) return !1;
2736
+ if (this.dataChannel.bufferedAmount > K.MAX_BUFFERED_AMOUNT)
2737
+ return this._buffering = !0, setTimeout(() => {
2738
+ this._buffering = !1, this._tryBuffer();
2739
+ }, 50), !1;
2740
+ try {
2741
+ this.dataChannel.send(e);
2742
+ } catch (t) {
2743
+ return u.error(`DC#:${this.connectionId} Error when sending:`, t), this._buffering = !0, this.close(), !1;
2744
+ }
2745
+ return !0;
2746
+ }
2747
+ // Try to send the first message in the buffer.
2748
+ _tryBuffer() {
2749
+ if (!this.open || this._buffer.length === 0) return;
2750
+ const e = this._buffer[0];
2751
+ this._trySend(e) && (this._buffer.shift(), this._bufferSize = this._buffer.length, this._tryBuffer());
2752
+ }
2753
+ close(e) {
2754
+ if (e != null && e.flush) {
2755
+ this.send({
2756
+ __peerData: {
2757
+ type: "close"
2758
+ }
2759
+ });
2760
+ return;
2761
+ }
2762
+ this._buffer = [], this._bufferSize = 0, super.close();
2763
+ }
2764
+ constructor(...e) {
2765
+ super(...e), this._buffer = [], this._bufferSize = 0, this._buffering = !1;
2766
+ }
2767
+ }
2768
+ class Q extends le {
2769
+ close(e) {
2770
+ super.close(e), this._chunkedData = {};
2771
+ }
2772
+ constructor(e, t, n) {
2773
+ super(e, t, n), this.chunker = new it(), this.serialization = I.Binary, this._chunkedData = {};
2774
+ }
2775
+ // Handles a DataChannel message.
2776
+ _handleDataMessage({ data: e }) {
2777
+ const t = Te(e), n = t.__peerData;
2778
+ if (n) {
2779
+ if (n.type === "close") {
2780
+ this.close();
2781
+ return;
2782
+ }
2783
+ this._handleChunk(t);
2784
+ return;
2785
+ }
2786
+ this.emit("data", t);
2787
+ }
2788
+ _handleChunk(e) {
2789
+ const t = e.__peerData, n = this._chunkedData[t] || {
2790
+ data: [],
2791
+ count: 0,
2792
+ total: e.total
2793
+ };
2794
+ if (n.data[e.n] = new Uint8Array(e.data), n.count++, this._chunkedData[t] = n, n.total === n.count) {
2795
+ delete this._chunkedData[t];
2796
+ const i = It(n.data);
2797
+ this._handleDataMessage({
2798
+ data: i
2799
+ });
2800
+ }
2801
+ }
2802
+ _send(e, t) {
2803
+ const n = Re(e);
2804
+ if (n instanceof Promise) return this._send_blob(n);
2805
+ if (!t && n.byteLength > this.chunker.chunkedMTU) {
2806
+ this._sendChunks(n);
2807
+ return;
2808
+ }
2809
+ this._bufferedSend(n);
2810
+ }
2811
+ async _send_blob(e) {
2812
+ const t = await e;
2813
+ if (t.byteLength > this.chunker.chunkedMTU) {
2814
+ this._sendChunks(t);
2815
+ return;
2816
+ }
2817
+ this._bufferedSend(t);
2818
+ }
2819
+ _sendChunks(e) {
2820
+ const t = this.chunker.chunk(e);
2821
+ u.log(`DC#${this.connectionId} Try to send ${t.length} chunks...`);
2822
+ for (const n of t) this.send(n, !0);
2823
+ }
2824
+ }
2825
+ class zt extends le {
2826
+ _handleDataMessage({ data: e }) {
2827
+ super.emit("data", e);
2828
+ }
2829
+ _send(e, t) {
2830
+ this._bufferedSend(e);
2831
+ }
2832
+ constructor(...e) {
2833
+ super(...e), this.serialization = I.None;
2834
+ }
2835
+ }
2836
+ class Nt extends le {
2837
+ // Handles a DataChannel message.
2838
+ _handleDataMessage({ data: e }) {
2839
+ const t = this.parse(this.decoder.decode(e)), n = t.__peerData;
2840
+ if (n && n.type === "close") {
2841
+ this.close();
2842
+ return;
2843
+ }
2844
+ this.emit("data", t);
2845
+ }
2846
+ _send(e, t) {
2847
+ const n = this.encoder.encode(this.stringify(e));
2848
+ if (n.byteLength >= k.chunkedMTU) {
2849
+ this.emitError(B.MessageToBig, "Message too big for JSON channel");
2850
+ return;
2851
+ }
2852
+ this._bufferedSend(n);
2853
+ }
2854
+ constructor(...e) {
2855
+ super(...e), this.serialization = I.JSON, this.encoder = new TextEncoder(), this.decoder = new TextDecoder(), this.stringify = JSON.stringify, this.parse = JSON.parse;
2856
+ }
2857
+ }
2858
+ var ce;
2859
+ const $ = class $ extends ct {
2860
+ /**
2861
+ * The brokering ID of this peer
2862
+ *
2863
+ * If no ID was specified in {@apilink Peer | the constructor},
2864
+ * this will be `undefined` until the {@apilink PeerEvents | `open`} event is emitted.
2865
+ */
2866
+ get id() {
2867
+ return this._id;
2868
+ }
2869
+ get options() {
2870
+ return this._options;
2871
+ }
2872
+ get open() {
2873
+ return this._open;
2874
+ }
2875
+ /**
2876
+ * @internal
2877
+ */
2878
+ get socket() {
2879
+ return this._socket;
2880
+ }
2881
+ /**
2882
+ * A hash of all connections associated with this peer, keyed by the remote peer's ID.
2883
+ * @deprecated
2884
+ * Return type will change from Object to Map<string,[]>
2885
+ */
2886
+ get connections() {
2887
+ const e = /* @__PURE__ */ Object.create(null);
2888
+ for (const [t, n] of this._connections) e[t] = n;
2889
+ return e;
2890
+ }
2891
+ /**
2892
+ * true if this peer and all of its connections can no longer be used.
2893
+ */
2894
+ get destroyed() {
2895
+ return this._destroyed;
2896
+ }
2897
+ /**
2898
+ * false if there is an active connection to the PeerServer.
2899
+ */
2900
+ get disconnected() {
2901
+ return this._disconnected;
2902
+ }
2903
+ constructor(e, t) {
2904
+ super(), this._serializers = {
2905
+ raw: zt,
2906
+ json: Nt,
2907
+ binary: Q,
2908
+ "binary-utf8": Q,
2909
+ default: Q
2910
+ }, this._id = null, this._lastServerId = null, this._destroyed = !1, this._disconnected = !1, this._open = !1, this._connections = /* @__PURE__ */ new Map(), this._lostMessages = /* @__PURE__ */ new Map();
2911
+ let n;
2912
+ if (e && e.constructor == Object ? t = e : e && (n = e.toString()), t = {
2913
+ debug: 0,
2914
+ host: k.CLOUD_HOST,
2915
+ port: k.CLOUD_PORT,
2916
+ path: "/",
2917
+ key: $.DEFAULT_KEY,
2918
+ token: k.randomToken(),
2919
+ config: k.defaultConfig,
2920
+ referrerPolicy: "strict-origin-when-cross-origin",
2921
+ serializers: {},
2922
+ ...t
2923
+ }, this._options = t, this._serializers = {
2924
+ ...this._serializers,
2925
+ ...this.options.serializers
2926
+ }, this._options.host === "/" && (this._options.host = window.location.hostname), this._options.path && (this._options.path[0] !== "/" && (this._options.path = "/" + this._options.path), this._options.path[this._options.path.length - 1] !== "/" && (this._options.path += "/")), this._options.secure === void 0 && this._options.host !== k.CLOUD_HOST ? this._options.secure = k.isSecure() : this._options.host == k.CLOUD_HOST && (this._options.secure = !0), this._options.logFunction && u.setLogFunction(this._options.logFunction), u.logLevel = this._options.debug || 0, this._api = new Ut(t), this._socket = this._createServerConnection(), !k.supports.audioVideo && !k.supports.data) {
2927
+ this._delayedAbort(g.BrowserIncompatible, "The current browser does not support WebRTC");
2928
+ return;
2929
+ }
2930
+ if (n && !k.validateId(n)) {
2931
+ this._delayedAbort(g.InvalidID, `ID "${n}" is invalid`);
2932
+ return;
2933
+ }
2934
+ n ? this._initialize(n) : this._api.retrieveId().then((i) => this._initialize(i)).catch((i) => this._abort(g.ServerError, i));
2935
+ }
2936
+ _createServerConnection() {
2937
+ const e = new Bt(this._options.secure, this._options.host, this._options.port, this._options.path, this._options.key, this._options.pingInterval);
2938
+ return e.on(S.Message, (t) => {
2939
+ this._handleMessage(t);
2940
+ }), e.on(S.Error, (t) => {
2941
+ this._abort(g.SocketError, t);
2942
+ }), e.on(S.Disconnected, () => {
2943
+ this.disconnected || (this.emitError(g.Network, "Lost connection to server."), this.disconnect());
2944
+ }), e.on(S.Close, () => {
2945
+ this.disconnected || this._abort(g.SocketClosed, "Underlying socket is already closed.");
2946
+ }), e;
2947
+ }
2948
+ /** Initialize a connection with the server. */
2949
+ _initialize(e) {
2950
+ this._id = e, this.socket.start(e, this._options.token);
2951
+ }
2952
+ /** Handles messages from the server. */
2953
+ _handleMessage(e) {
2954
+ const t = e.type, n = e.payload, i = e.src;
2955
+ switch (t) {
2956
+ case _.Open:
2957
+ this._lastServerId = this.id, this._open = !0, this.emit("open", this.id);
2958
+ break;
2959
+ case _.Error:
2960
+ this._abort(g.ServerError, n.msg);
2961
+ break;
2962
+ case _.IdTaken:
2963
+ this._abort(g.UnavailableID, `ID "${this.id}" is taken`);
2964
+ break;
2965
+ case _.InvalidKey:
2966
+ this._abort(g.InvalidKey, `API KEY "${this._options.key}" is invalid`);
2967
+ break;
2968
+ case _.Leave:
2969
+ u.log(`Received leave message from ${i}`), this._cleanupPeer(i), this._connections.delete(i);
2970
+ break;
2971
+ case _.Expire:
2972
+ this.emitError(g.PeerUnavailable, `Could not connect to peer ${i}`);
2973
+ break;
2974
+ case _.Offer: {
2975
+ const s = n.connectionId;
2976
+ let o = this.getConnection(i, s);
2977
+ if (o && (o.close(), u.warn(`Offer received for existing Connection ID:${s}`)), n.type === T.Media) {
2978
+ const c = new Y(i, this, {
2979
+ connectionId: s,
2980
+ _payload: n,
2981
+ metadata: n.metadata
2982
+ });
2983
+ o = c, this._addConnection(i, o), this.emit("call", c);
2984
+ } else if (n.type === T.Data) {
2985
+ const c = new this._serializers[n.serialization](i, this, {
2986
+ connectionId: s,
2987
+ _payload: n,
2988
+ metadata: n.metadata,
2989
+ label: n.label,
2990
+ serialization: n.serialization,
2991
+ reliable: n.reliable
2992
+ });
2993
+ o = c, this._addConnection(i, o), this.emit("connection", c);
2994
+ } else {
2995
+ u.warn(`Received malformed connection type:${n.type}`);
2996
+ return;
2997
+ }
2998
+ const a = this._getMessages(s);
2999
+ for (const c of a) o.handleMessage(c);
3000
+ break;
3001
+ }
3002
+ default: {
3003
+ if (!n) {
3004
+ u.warn(`You received a malformed message from ${i} of type ${t}`);
3005
+ return;
3006
+ }
3007
+ const s = n.connectionId, o = this.getConnection(i, s);
3008
+ o && o.peerConnection ? o.handleMessage(e) : s ? this._storeMessage(s, e) : u.warn("You received an unrecognized message:", e);
3009
+ break;
3010
+ }
3011
+ }
3012
+ }
3013
+ /** Stores messages without a set up connection, to be claimed later. */
3014
+ _storeMessage(e, t) {
3015
+ this._lostMessages.has(e) || this._lostMessages.set(e, []), this._lostMessages.get(e).push(t);
3016
+ }
3017
+ /**
3018
+ * Retrieve messages from lost message store
3019
+ * @internal
3020
+ */
3021
+ //TODO Change it to private
3022
+ _getMessages(e) {
3023
+ const t = this._lostMessages.get(e);
3024
+ return t ? (this._lostMessages.delete(e), t) : [];
3025
+ }
3026
+ /**
3027
+ * Connects to the remote peer specified by id and returns a data connection.
3028
+ * @param peer The brokering ID of the remote peer (their {@apilink Peer.id}).
3029
+ * @param options for specifying details about Peer Connection
3030
+ */
3031
+ connect(e, t = {}) {
3032
+ if (t = {
3033
+ serialization: "default",
3034
+ ...t
3035
+ }, this.disconnected) {
3036
+ u.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect, or call reconnect on this peer if you believe its ID to still be available."), this.emitError(g.Disconnected, "Cannot connect to new Peer after disconnecting from server.");
3037
+ return;
3038
+ }
3039
+ const n = new this._serializers[t.serialization](e, this, t);
3040
+ return this._addConnection(e, n), n;
3041
+ }
3042
+ /**
3043
+ * Calls the remote peer specified by id and returns a media connection.
3044
+ * @param peer The brokering ID of the remote peer (their peer.id).
3045
+ * @param stream The caller's media stream
3046
+ * @param options Metadata associated with the connection, passed in by whoever initiated the connection.
3047
+ */
3048
+ call(e, t, n = {}) {
3049
+ if (this.disconnected) {
3050
+ u.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect."), this.emitError(g.Disconnected, "Cannot connect to new Peer after disconnecting from server.");
3051
+ return;
3052
+ }
3053
+ if (!t) {
3054
+ u.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");
3055
+ return;
3056
+ }
3057
+ const i = new Y(e, this, {
3058
+ ...n,
3059
+ _stream: t
3060
+ });
3061
+ return this._addConnection(e, i), i;
3062
+ }
3063
+ /** Add a data/media connection to this peer. */
3064
+ _addConnection(e, t) {
3065
+ u.log(`add connection ${t.type}:${t.connectionId} to peerId:${e}`), this._connections.has(e) || this._connections.set(e, []), this._connections.get(e).push(t);
3066
+ }
3067
+ //TODO should be private
3068
+ _removeConnection(e) {
3069
+ const t = this._connections.get(e.peer);
3070
+ if (t) {
3071
+ const n = t.indexOf(e);
3072
+ n !== -1 && t.splice(n, 1);
3073
+ }
3074
+ this._lostMessages.delete(e.connectionId);
3075
+ }
3076
+ /** Retrieve a data/media connection for this peer. */
3077
+ getConnection(e, t) {
3078
+ const n = this._connections.get(e);
3079
+ if (!n) return null;
3080
+ for (const i of n)
3081
+ if (i.connectionId === t) return i;
3082
+ return null;
3083
+ }
3084
+ _delayedAbort(e, t) {
3085
+ setTimeout(() => {
3086
+ this._abort(e, t);
3087
+ }, 0);
3088
+ }
3089
+ /**
3090
+ * Emits an error message and destroys the Peer.
3091
+ * The Peer is not destroyed if it's in a disconnected state, in which case
3092
+ * it retains its disconnected state and its existing connections.
3093
+ */
3094
+ _abort(e, t) {
3095
+ u.error("Aborting!"), this.emitError(e, t), this._lastServerId ? this.disconnect() : this.destroy();
3096
+ }
3097
+ /**
3098
+ * Destroys the Peer: closes all active connections as well as the connection
3099
+ * to the server.
3100
+ *
3101
+ * :::caution
3102
+ * This cannot be undone; the respective peer object will no longer be able
3103
+ * to create or receive any connections, its ID will be forfeited on the server,
3104
+ * and all of its data and media connections will be closed.
3105
+ * :::
3106
+ */
3107
+ destroy() {
3108
+ this.destroyed || (u.log(`Destroy peer with ID:${this.id}`), this.disconnect(), this._cleanup(), this._destroyed = !0, this.emit("close"));
3109
+ }
3110
+ /** Disconnects every connection on this peer. */
3111
+ _cleanup() {
3112
+ for (const e of this._connections.keys())
3113
+ this._cleanupPeer(e), this._connections.delete(e);
3114
+ this.socket.removeAllListeners();
3115
+ }
3116
+ /** Closes all connections to this peer. */
3117
+ _cleanupPeer(e) {
3118
+ const t = this._connections.get(e);
3119
+ if (t)
3120
+ for (const n of t) n.close();
3121
+ }
3122
+ /**
3123
+ * Disconnects the Peer's connection to the PeerServer. Does not close any
3124
+ * active connections.
3125
+ * Warning: The peer can no longer create or accept connections after being
3126
+ * disconnected. It also cannot reconnect to the server.
3127
+ */
3128
+ disconnect() {
3129
+ if (this.disconnected) return;
3130
+ const e = this.id;
3131
+ u.log(`Disconnect peer with ID:${e}`), this._disconnected = !0, this._open = !1, this.socket.close(), this._lastServerId = e, this._id = null, this.emit("disconnected", e);
3132
+ }
3133
+ /** Attempts to reconnect with the same ID.
3134
+ *
3135
+ * Only {@apilink Peer.disconnect | disconnected peers} can be reconnected.
3136
+ * Destroyed peers cannot be reconnected.
3137
+ * If the connection fails (as an example, if the peer's old ID is now taken),
3138
+ * the peer's existing connections will not close, but any associated errors events will fire.
3139
+ */
3140
+ reconnect() {
3141
+ if (this.disconnected && !this.destroyed)
3142
+ u.log(`Attempting reconnection to server with ID ${this._lastServerId}`), this._disconnected = !1, this._initialize(this._lastServerId);
3143
+ else {
3144
+ if (this.destroyed) throw new Error("This peer cannot reconnect to the server. It has already been destroyed.");
3145
+ if (!this.disconnected && !this.open)
3146
+ u.error("In a hurry? We're still trying to make the initial connection!");
3147
+ else throw new Error(`Peer ${this.id} cannot reconnect because it is not disconnected from the server!`);
3148
+ }
3149
+ }
3150
+ /**
3151
+ * Get a list of available peer IDs. If you're running your own server, you'll
3152
+ * want to set allow_discovery: true in the PeerServer options. If you're using
3153
+ * the cloud server, email team@peerjs.com to get the functionality enabled for
3154
+ * your key.
3155
+ */
3156
+ listAllPeers(e = (t) => {
3157
+ }) {
3158
+ this._api.listAllPeers().then((t) => e(t)).catch((t) => this._abort(g.ServerError, t));
3159
+ }
3160
+ };
3161
+ ce = new WeakMap(), M($, ce, $.DEFAULT_KEY = "peerjs");
3162
+ let ie = $;
3163
+ const Jt = 3, Gt = 1e3, Vt = 1e4, Ht = 20, Yt = 30;
3164
+ function F(r) {
3165
+ return Math.pow(2, Math.min(r, Jt)) * Gt;
3166
+ }
3167
+ function Se(r) {
3168
+ return typeof r.event == "string";
3169
+ }
3170
+ class wt {
3171
+ constructor(e, t, n, i, s, o, a, c, p) {
3172
+ m(this, "emitter", new dt());
3173
+ m(this, "peer");
3174
+ m(this, "connections", /* @__PURE__ */ new Map());
3175
+ m(this, "heatbeatTimeout", -1);
3176
+ m(this, "retryTimeout", -1);
3177
+ m(this, "status", "connecting");
3178
+ m(this, "connRetryCount", 0);
3179
+ m(this, "isRelay", !1);
3180
+ m(this, "error", "none");
3181
+ m(this, "peerRetryCount", 0);
3182
+ m(this, "idRetryCount", 0);
3183
+ m(this, "server");
3184
+ m(this, "host");
3185
+ m(this, "secure");
3186
+ m(this, "port");
3187
+ m(this, "key");
3188
+ m(this, "ice");
3189
+ m(this, "relay");
3190
+ m(this, "code");
3191
+ m(this, "_quality", 0);
3192
+ m(this, "options");
3193
+ m(this, "boundSendAll");
3194
+ m(this, "failed", !1);
3195
+ this.server = c, this.code = e, this.host = t, this.secure = n, this.key = i || "peerjs", this.port = s || 443, this.ice = o, this.relay = a, this.options = p, this.peer = this.createPeerServer(), this.boundSendAll = this.sendAll.bind(this);
3196
+ }
3197
+ get quality() {
3198
+ return this._quality;
3199
+ }
3200
+ get size() {
3201
+ return this.connections.size;
3202
+ }
3203
+ update() {
3204
+ if (!this.peer.open || this.peer.disconnected || this.peer.destroyed)
3205
+ this._quality = 0, this.status = this.failed ? "failed" : "connecting";
3206
+ else if (this.server) {
3207
+ const e = this.connections.get(this.server);
3208
+ this._quality = (e == null ? void 0 : e.connection.quality) || 0, this.status = (e == null ? void 0 : e.status) || "connecting";
3209
+ } else {
3210
+ let e = this._quality;
3211
+ this.connections.forEach((t) => {
3212
+ t.connection.open && (e = Math.max(e, t.connection.quality));
3213
+ }), this._quality = Math.max(e, 1), this.status = "ready";
3214
+ }
3215
+ this.emit("quality", this._quality), this.emit("status", this.status);
3216
+ }
3217
+ emit(e, ...t) {
3218
+ this.emitter.emit(e, ...t);
3219
+ }
3220
+ on(e, t) {
3221
+ this.emitter.on(e, t);
3222
+ }
3223
+ off(e, t) {
3224
+ this.emitter.off(e, t);
3225
+ }
3226
+ createPeerServer() {
3227
+ var t;
3228
+ const e = new ie(this.code, {
3229
+ host: this.host,
3230
+ secure: this.secure,
3231
+ key: this.key,
3232
+ port: this.port,
3233
+ debug: 0,
3234
+ config: {
3235
+ iceServers: [this.ice.iceServers[0]],
3236
+ sdpSemantics: "unified-plan",
3237
+ iceTransportPolicy: this.relay || (t = this.options) != null && t.forceTURN ? "relay" : void 0
3238
+ }
3239
+ });
3240
+ return e.on("open", () => this.onOpen()), e.on("connection", (n) => this.onConnection(new q(n.peer, this.peer, !1, n))), e.on("error", (n) => this.onError(n)), e.on("close", () => {
3241
+ this.update();
3242
+ }), e.on("disconnected", () => {
3243
+ this.heatbeatTimeout >= 0 && clearTimeout(this.heatbeatTimeout), this.update();
3244
+ }), e;
3245
+ }
3246
+ /** Completely restart the connection from scratch. */
3247
+ reset() {
3248
+ this.destroy(), this.emit("retry"), this.peer = this.createPeerServer();
3249
+ }
3250
+ destroy() {
3251
+ this.connections.forEach((e) => {
3252
+ e.removeAllListeners(), e.close();
3253
+ }), this.connections.clear(), this.heatbeatTimeout >= 0 && clearTimeout(this.heatbeatTimeout), this.retryTimeout >= 0 && clearTimeout(this.retryTimeout), this.peer.removeAllListeners(), this.peer.destroy(), this.update();
3254
+ }
3255
+ setError(e) {
3256
+ this.update(), this.error = e, e !== "none" && this.emit("error", e);
3257
+ }
3258
+ retryConnection(e, t) {
3259
+ const n = this.connections.get(e);
3260
+ this.connections.delete(e), n && n.close(), setTimeout(() => {
3261
+ this.peer.destroyed || this.createPeer(e, t);
3262
+ }, F(this.connRetryCount++));
3263
+ }
3264
+ /** Initiate a connection to a peer */
3265
+ createPeer(e, t) {
3266
+ const n = new q(
3267
+ e,
3268
+ this.peer,
3269
+ !0,
3270
+ t ? void 0 : this.peer.connect(e, { reliable: !0 })
3271
+ ), i = this.connections.get(e);
3272
+ i && (console.warn("Connection already existed when creating peer:", e), i.close());
3273
+ const s = new mt(n);
3274
+ this.connections.set(n.peer, s), s.on("retry", () => {
3275
+ this.update();
3276
+ }), s.on("connect", () => {
3277
+ this.update(), this.setError("none"), this.emit("connect", s.connection);
3278
+ }), s.on("data", async (o) => {
3279
+ Se(o) && (o.event === "eter:connect" ? this.createPeer(o.code) : this.emit("data", o, s.connection));
3280
+ }), s.on("close", () => {
3281
+ this.connections.delete(s.connection.peer), this.update(), this.emit("close", s.connection);
3282
+ });
3283
+ }
3284
+ retry() {
3285
+ this.heatbeatTimeout >= 0 && clearTimeout(this.heatbeatTimeout), this.heatbeatTimeout = window.setTimeout(() => {
3286
+ document.hidden ? this.retry() : (this.heatbeatTimeout = -1, this.reset());
3287
+ }, Vt);
3288
+ }
3289
+ onOpen() {
3290
+ var e;
3291
+ this.peerRetryCount = 0, this.idRetryCount = 0, this.peer.socket.addListener("message", (t) => {
3292
+ if (t.type === "HEARTBEAT")
3293
+ this.heatbeatTimeout >= 0 && clearTimeout(this.heatbeatTimeout), this.retry();
3294
+ else if (t.type === "KEY") {
3295
+ const n = this.connections.get(t.src);
3296
+ if (!n || n.connection.connectionType !== "server") {
3297
+ const i = new q(t.src, this.peer, !1);
3298
+ if (this.onConnection(i), t.payload) {
3299
+ const s = t.payload;
3300
+ i.setKey(s);
3301
+ }
3302
+ }
3303
+ }
3304
+ }), this.retry(), this.update(), this.emit("open"), this.server ? this.connections.has(this.server) ? this.setError("none") : this.createPeer(this.server, !!((e = this.options) != null && e.forceWebsocket)) : this.setError("none");
3305
+ }
3306
+ getConnection(e) {
3307
+ return this.connections.get(e);
3308
+ }
3309
+ onConnection(e) {
3310
+ if (this.connections.has(e.peer)) {
3311
+ const n = this.connections.get(e.peer);
3312
+ n && (n.close(), console.warn("Connection already existed", n));
3313
+ }
3314
+ const t = new gt(e);
3315
+ this.connections.set(e.peer, t), t.on("data", async (n) => {
3316
+ Se(n) && (n.event === "eter:connect" ? this.createPeer(n.code) : n.event === "ping" ? t.connection.send({ event: "ping", ok: !0 }) : this.emit("data", n, t.connection));
3317
+ }), t.on("connect", () => {
3318
+ this.connRetryCount = 0, this.update(), this.emit("connect", t.connection);
3319
+ }), t.on("close", () => {
3320
+ this.connections.delete(t.connection.peer), this.update(), this.emit("close", t.connection);
3321
+ });
3322
+ }
3323
+ onError(e) {
3324
+ const t = e.type;
3325
+ switch (console.warn("Peer-error:", t), t) {
3326
+ case "disconnected":
3327
+ case "network":
3328
+ case "server-error":
3329
+ clearTimeout(this.retryTimeout), this.retryTimeout = window.setTimeout(() => {
3330
+ try {
3331
+ this.peer.reconnect();
3332
+ } catch {
3333
+ this.setError("peer-not-found");
3334
+ }
3335
+ }, F(this.peerRetryCount++));
3336
+ break;
3337
+ case "unavailable-id":
3338
+ this.idRetryCount < Ht ? (clearTimeout(this.retryTimeout), this.retryTimeout = window.setTimeout(() => {
3339
+ this.reset();
3340
+ }, F(this.idRetryCount++))) : (this.peer.destroy(), this.setError("id-in-use"));
3341
+ break;
3342
+ case "browser-incompatible":
3343
+ this.setError("bad-browser");
3344
+ break;
3345
+ case "peer-unavailable":
3346
+ this.server && (this.connRetryCount < Yt ? this.retryConnection(this.server) : this.setError("peer-not-found"));
3347
+ break;
3348
+ case "webrtc":
3349
+ break;
3350
+ default:
3351
+ clearTimeout(this.retryTimeout), this.retryTimeout = window.setTimeout(() => {
3352
+ this.reset();
3353
+ }, F(this.peerRetryCount++));
3354
+ }
3355
+ this.update();
3356
+ }
3357
+ sendAll(e, t) {
3358
+ if (this.status === "ready") {
3359
+ const n = t ? new Set(t) : void 0;
3360
+ for (const i of this.connections.values())
3361
+ n != null && n.has(i.connection.connectionId) || i.connection.open && i.connection.send(e);
3362
+ }
3363
+ }
3364
+ }
3365
+ export {
3366
+ wt as default
3367
+ };