topazcube 0.1.18 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/server.js CHANGED
@@ -1,3 +1,1432 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined") return require.apply(this, arguments);
11
+ throw Error('Dynamic require of "' + x + '" is not supported');
12
+ });
13
+ var __commonJS = (cb, mod) => function __require2() {
14
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
25
+ // If the importer is in node compatibility mode or this is not an ESM
26
+ // file that has been converted to a CommonJS file using a Babel-
27
+ // compatible transform (i.e. "__esModule" has not been set), then set
28
+ // "default" to the CommonJS "module.exports" for node compatibility.
29
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
30
+ mod
31
+ ));
32
+
33
+ // node_modules/@roamhq/wrtc/lib/binding.js
34
+ var require_binding = __commonJS({
35
+ "node_modules/@roamhq/wrtc/lib/binding.js"(exports, module) {
36
+ "use strict";
37
+ var os = __require("os");
38
+ var triple = `${os.platform()}-${os.arch()}`;
39
+ var pathsToTry = [
40
+ `../build-${triple}/wrtc.node`,
41
+ `../build-${triple}/Debug/wrtc.node`,
42
+ `../build-${triple}/Release/wrtc.node`,
43
+ `@roamhq/wrtc-${triple}`,
44
+ // For installations that can't resolve node_modules directly, like AWS Lambda
45
+ `./node_modules/@roamhq/wrtc-${triple}`,
46
+ `./node_modules/@roamhq/wrtc-${triple}/wrtc.node`
47
+ ];
48
+ var succeeded = false;
49
+ for (const path of pathsToTry) {
50
+ try {
51
+ module.exports = __require(path);
52
+ succeeded = true;
53
+ break;
54
+ } catch (error) {
55
+ void error;
56
+ }
57
+ }
58
+ if (!succeeded) {
59
+ throw new Error(
60
+ `Could not find wrtc binary on any of the paths: ${pathsToTry}`
61
+ );
62
+ }
63
+ }
64
+ });
65
+
66
+ // node_modules/@roamhq/wrtc/lib/eventtarget.js
67
+ var require_eventtarget = __commonJS({
68
+ "node_modules/@roamhq/wrtc/lib/eventtarget.js"(exports, module) {
69
+ "use strict";
70
+ function EventTarget() {
71
+ this._listeners = {};
72
+ }
73
+ EventTarget.prototype.addEventListener = function addEventListener(type, listener) {
74
+ const listeners = this._listeners = this._listeners || {};
75
+ if (!listeners[type]) {
76
+ listeners[type] = /* @__PURE__ */ new Set();
77
+ }
78
+ listeners[type].add(listener);
79
+ };
80
+ EventTarget.prototype.dispatchEvent = function dispatchEvent(event) {
81
+ let listeners = this._listeners = this._listeners || {};
82
+ process.nextTick(() => {
83
+ listeners = new Set(listeners[event.type] || []);
84
+ const dummyListener = this["on" + event.type];
85
+ if (typeof dummyListener === "function") {
86
+ listeners.add(dummyListener);
87
+ }
88
+ listeners.forEach((listener) => {
89
+ if (typeof listener === "object" && typeof listener.handleEvent === "function") {
90
+ listener.handleEvent(event);
91
+ } else {
92
+ listener.call(this, event);
93
+ }
94
+ });
95
+ });
96
+ };
97
+ EventTarget.prototype.removeEventListener = function removeEventListener(type, listener) {
98
+ const listeners = this._listeners = this._listeners || {};
99
+ if (listeners[type]) {
100
+ listeners[type].delete(listener);
101
+ }
102
+ };
103
+ module.exports = EventTarget;
104
+ }
105
+ });
106
+
107
+ // node_modules/@roamhq/wrtc/lib/mediadevices.js
108
+ var require_mediadevices = __commonJS({
109
+ "node_modules/@roamhq/wrtc/lib/mediadevices.js"(exports, module) {
110
+ "use strict";
111
+ var inherits = __require("util").inherits;
112
+ var { getDisplayMedia, getUserMedia } = require_binding();
113
+ var EventTarget = require_eventtarget();
114
+ function MediaDevices() {
115
+ }
116
+ inherits(MediaDevices, EventTarget);
117
+ MediaDevices.prototype.enumerateDevices = function enumerateDevices() {
118
+ throw new Error(
119
+ "Not yet implemented; file a feature request against node-webrtc"
120
+ );
121
+ };
122
+ MediaDevices.prototype.getSupportedConstraints = function getSupportedConstraints() {
123
+ return {
124
+ width: true,
125
+ height: true
126
+ };
127
+ };
128
+ MediaDevices.prototype.getDisplayMedia = getDisplayMedia;
129
+ MediaDevices.prototype.getUserMedia = getUserMedia;
130
+ module.exports = MediaDevices;
131
+ }
132
+ });
133
+
134
+ // node_modules/webidl-conversions/lib/index.js
135
+ var require_lib = __commonJS({
136
+ "node_modules/webidl-conversions/lib/index.js"(exports) {
137
+ "use strict";
138
+ function makeException(ErrorType, message, options) {
139
+ if (options.globals) {
140
+ ErrorType = options.globals[ErrorType.name];
141
+ }
142
+ return new ErrorType(`${options.context ? options.context : "Value"} ${message}.`);
143
+ }
144
+ function toNumber(value, options) {
145
+ if (typeof value === "bigint") {
146
+ throw makeException(TypeError, "is a BigInt which cannot be converted to a number", options);
147
+ }
148
+ if (!options.globals) {
149
+ return Number(value);
150
+ }
151
+ return options.globals.Number(value);
152
+ }
153
+ function evenRound(x) {
154
+ if (x > 0 && x % 1 === 0.5 && (x & 1) === 0 || x < 0 && x % 1 === -0.5 && (x & 1) === 1) {
155
+ return censorNegativeZero(Math.floor(x));
156
+ }
157
+ return censorNegativeZero(Math.round(x));
158
+ }
159
+ function integerPart(n) {
160
+ return censorNegativeZero(Math.trunc(n));
161
+ }
162
+ function sign(x) {
163
+ return x < 0 ? -1 : 1;
164
+ }
165
+ function modulo(x, y) {
166
+ const signMightNotMatch = x % y;
167
+ if (sign(y) !== sign(signMightNotMatch)) {
168
+ return signMightNotMatch + y;
169
+ }
170
+ return signMightNotMatch;
171
+ }
172
+ function censorNegativeZero(x) {
173
+ return x === 0 ? 0 : x;
174
+ }
175
+ function createIntegerConversion(bitLength, { unsigned }) {
176
+ let lowerBound, upperBound;
177
+ if (unsigned) {
178
+ lowerBound = 0;
179
+ upperBound = 2 ** bitLength - 1;
180
+ } else {
181
+ lowerBound = -(2 ** (bitLength - 1));
182
+ upperBound = 2 ** (bitLength - 1) - 1;
183
+ }
184
+ const twoToTheBitLength = 2 ** bitLength;
185
+ const twoToOneLessThanTheBitLength = 2 ** (bitLength - 1);
186
+ return (value, options = {}) => {
187
+ let x = toNumber(value, options);
188
+ x = censorNegativeZero(x);
189
+ if (options.enforceRange) {
190
+ if (!Number.isFinite(x)) {
191
+ throw makeException(TypeError, "is not a finite number", options);
192
+ }
193
+ x = integerPart(x);
194
+ if (x < lowerBound || x > upperBound) {
195
+ throw makeException(
196
+ TypeError,
197
+ `is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`,
198
+ options
199
+ );
200
+ }
201
+ return x;
202
+ }
203
+ if (!Number.isNaN(x) && options.clamp) {
204
+ x = Math.min(Math.max(x, lowerBound), upperBound);
205
+ x = evenRound(x);
206
+ return x;
207
+ }
208
+ if (!Number.isFinite(x) || x === 0) {
209
+ return 0;
210
+ }
211
+ x = integerPart(x);
212
+ if (x >= lowerBound && x <= upperBound) {
213
+ return x;
214
+ }
215
+ x = modulo(x, twoToTheBitLength);
216
+ if (!unsigned && x >= twoToOneLessThanTheBitLength) {
217
+ return x - twoToTheBitLength;
218
+ }
219
+ return x;
220
+ };
221
+ }
222
+ function createLongLongConversion(bitLength, { unsigned }) {
223
+ const upperBound = Number.MAX_SAFE_INTEGER;
224
+ const lowerBound = unsigned ? 0 : Number.MIN_SAFE_INTEGER;
225
+ const asBigIntN = unsigned ? BigInt.asUintN : BigInt.asIntN;
226
+ return (value, options = {}) => {
227
+ let x = toNumber(value, options);
228
+ x = censorNegativeZero(x);
229
+ if (options.enforceRange) {
230
+ if (!Number.isFinite(x)) {
231
+ throw makeException(TypeError, "is not a finite number", options);
232
+ }
233
+ x = integerPart(x);
234
+ if (x < lowerBound || x > upperBound) {
235
+ throw makeException(
236
+ TypeError,
237
+ `is outside the accepted range of ${lowerBound} to ${upperBound}, inclusive`,
238
+ options
239
+ );
240
+ }
241
+ return x;
242
+ }
243
+ if (!Number.isNaN(x) && options.clamp) {
244
+ x = Math.min(Math.max(x, lowerBound), upperBound);
245
+ x = evenRound(x);
246
+ return x;
247
+ }
248
+ if (!Number.isFinite(x) || x === 0) {
249
+ return 0;
250
+ }
251
+ let xBigInt = BigInt(integerPart(x));
252
+ xBigInt = asBigIntN(bitLength, xBigInt);
253
+ return Number(xBigInt);
254
+ };
255
+ }
256
+ exports.any = (value) => {
257
+ return value;
258
+ };
259
+ exports.undefined = () => {
260
+ return void 0;
261
+ };
262
+ exports.boolean = (value) => {
263
+ return Boolean(value);
264
+ };
265
+ exports.byte = createIntegerConversion(8, { unsigned: false });
266
+ exports.octet = createIntegerConversion(8, { unsigned: true });
267
+ exports.short = createIntegerConversion(16, { unsigned: false });
268
+ exports["unsigned short"] = createIntegerConversion(16, { unsigned: true });
269
+ exports.long = createIntegerConversion(32, { unsigned: false });
270
+ exports["unsigned long"] = createIntegerConversion(32, { unsigned: true });
271
+ exports["long long"] = createLongLongConversion(64, { unsigned: false });
272
+ exports["unsigned long long"] = createLongLongConversion(64, { unsigned: true });
273
+ exports.double = (value, options = {}) => {
274
+ const x = toNumber(value, options);
275
+ if (!Number.isFinite(x)) {
276
+ throw makeException(TypeError, "is not a finite floating-point value", options);
277
+ }
278
+ return x;
279
+ };
280
+ exports["unrestricted double"] = (value, options = {}) => {
281
+ const x = toNumber(value, options);
282
+ return x;
283
+ };
284
+ exports.float = (value, options = {}) => {
285
+ const x = toNumber(value, options);
286
+ if (!Number.isFinite(x)) {
287
+ throw makeException(TypeError, "is not a finite floating-point value", options);
288
+ }
289
+ if (Object.is(x, -0)) {
290
+ return x;
291
+ }
292
+ const y = Math.fround(x);
293
+ if (!Number.isFinite(y)) {
294
+ throw makeException(TypeError, "is outside the range of a single-precision floating-point value", options);
295
+ }
296
+ return y;
297
+ };
298
+ exports["unrestricted float"] = (value, options = {}) => {
299
+ const x = toNumber(value, options);
300
+ if (isNaN(x)) {
301
+ return x;
302
+ }
303
+ if (Object.is(x, -0)) {
304
+ return x;
305
+ }
306
+ return Math.fround(x);
307
+ };
308
+ exports.DOMString = (value, options = {}) => {
309
+ if (options.treatNullAsEmptyString && value === null) {
310
+ return "";
311
+ }
312
+ if (typeof value === "symbol") {
313
+ throw makeException(TypeError, "is a symbol, which cannot be converted to a string", options);
314
+ }
315
+ const StringCtor = options.globals ? options.globals.String : String;
316
+ return StringCtor(value);
317
+ };
318
+ exports.ByteString = (value, options = {}) => {
319
+ const x = exports.DOMString(value, options);
320
+ let c;
321
+ for (let i = 0; (c = x.codePointAt(i)) !== void 0; ++i) {
322
+ if (c > 255) {
323
+ throw makeException(TypeError, "is not a valid ByteString", options);
324
+ }
325
+ }
326
+ return x;
327
+ };
328
+ exports.USVString = (value, options = {}) => {
329
+ const S = exports.DOMString(value, options);
330
+ const n = S.length;
331
+ const U = [];
332
+ for (let i = 0; i < n; ++i) {
333
+ const c = S.charCodeAt(i);
334
+ if (c < 55296 || c > 57343) {
335
+ U.push(String.fromCodePoint(c));
336
+ } else if (56320 <= c && c <= 57343) {
337
+ U.push(String.fromCodePoint(65533));
338
+ } else if (i === n - 1) {
339
+ U.push(String.fromCodePoint(65533));
340
+ } else {
341
+ const d = S.charCodeAt(i + 1);
342
+ if (56320 <= d && d <= 57343) {
343
+ const a = c & 1023;
344
+ const b = d & 1023;
345
+ U.push(String.fromCodePoint((2 << 15) + (2 << 9) * a + b));
346
+ ++i;
347
+ } else {
348
+ U.push(String.fromCodePoint(65533));
349
+ }
350
+ }
351
+ }
352
+ return U.join("");
353
+ };
354
+ exports.object = (value, options = {}) => {
355
+ if (value === null || typeof value !== "object" && typeof value !== "function") {
356
+ throw makeException(TypeError, "is not an object", options);
357
+ }
358
+ return value;
359
+ };
360
+ var abByteLengthGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
361
+ var sabByteLengthGetter = typeof SharedArrayBuffer === "function" ? Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength").get : null;
362
+ function isNonSharedArrayBuffer(value) {
363
+ try {
364
+ abByteLengthGetter.call(value);
365
+ return true;
366
+ } catch {
367
+ return false;
368
+ }
369
+ }
370
+ function isSharedArrayBuffer(value) {
371
+ try {
372
+ sabByteLengthGetter.call(value);
373
+ return true;
374
+ } catch {
375
+ return false;
376
+ }
377
+ }
378
+ function isArrayBufferDetached(value) {
379
+ try {
380
+ new Uint8Array(value);
381
+ return false;
382
+ } catch {
383
+ return true;
384
+ }
385
+ }
386
+ exports.ArrayBuffer = (value, options = {}) => {
387
+ if (!isNonSharedArrayBuffer(value)) {
388
+ if (options.allowShared && !isSharedArrayBuffer(value)) {
389
+ throw makeException(TypeError, "is not an ArrayBuffer or SharedArrayBuffer", options);
390
+ }
391
+ throw makeException(TypeError, "is not an ArrayBuffer", options);
392
+ }
393
+ if (isArrayBufferDetached(value)) {
394
+ throw makeException(TypeError, "is a detached ArrayBuffer", options);
395
+ }
396
+ return value;
397
+ };
398
+ var dvByteLengthGetter = Object.getOwnPropertyDescriptor(DataView.prototype, "byteLength").get;
399
+ exports.DataView = (value, options = {}) => {
400
+ try {
401
+ dvByteLengthGetter.call(value);
402
+ } catch (e) {
403
+ throw makeException(TypeError, "is not a DataView", options);
404
+ }
405
+ if (!options.allowShared && isSharedArrayBuffer(value.buffer)) {
406
+ throw makeException(TypeError, "is backed by a SharedArrayBuffer, which is not allowed", options);
407
+ }
408
+ if (isArrayBufferDetached(value.buffer)) {
409
+ throw makeException(TypeError, "is backed by a detached ArrayBuffer", options);
410
+ }
411
+ return value;
412
+ };
413
+ var typedArrayNameGetter = Object.getOwnPropertyDescriptor(
414
+ Object.getPrototypeOf(Uint8Array).prototype,
415
+ Symbol.toStringTag
416
+ ).get;
417
+ [
418
+ Int8Array,
419
+ Int16Array,
420
+ Int32Array,
421
+ Uint8Array,
422
+ Uint16Array,
423
+ Uint32Array,
424
+ Uint8ClampedArray,
425
+ Float32Array,
426
+ Float64Array
427
+ ].forEach((func) => {
428
+ const { name } = func;
429
+ const article = /^[AEIOU]/u.test(name) ? "an" : "a";
430
+ exports[name] = (value, options = {}) => {
431
+ if (!ArrayBuffer.isView(value) || typedArrayNameGetter.call(value) !== name) {
432
+ throw makeException(TypeError, `is not ${article} ${name} object`, options);
433
+ }
434
+ if (!options.allowShared && isSharedArrayBuffer(value.buffer)) {
435
+ throw makeException(TypeError, "is a view on a SharedArrayBuffer, which is not allowed", options);
436
+ }
437
+ if (isArrayBufferDetached(value.buffer)) {
438
+ throw makeException(TypeError, "is a view on a detached ArrayBuffer", options);
439
+ }
440
+ return value;
441
+ };
442
+ });
443
+ exports.ArrayBufferView = (value, options = {}) => {
444
+ if (!ArrayBuffer.isView(value)) {
445
+ throw makeException(TypeError, "is not a view on an ArrayBuffer or SharedArrayBuffer", options);
446
+ }
447
+ if (!options.allowShared && isSharedArrayBuffer(value.buffer)) {
448
+ throw makeException(TypeError, "is a view on a SharedArrayBuffer, which is not allowed", options);
449
+ }
450
+ if (isArrayBufferDetached(value.buffer)) {
451
+ throw makeException(TypeError, "is a view on a detached ArrayBuffer", options);
452
+ }
453
+ return value;
454
+ };
455
+ exports.BufferSource = (value, options = {}) => {
456
+ if (ArrayBuffer.isView(value)) {
457
+ if (!options.allowShared && isSharedArrayBuffer(value.buffer)) {
458
+ throw makeException(TypeError, "is a view on a SharedArrayBuffer, which is not allowed", options);
459
+ }
460
+ if (isArrayBufferDetached(value.buffer)) {
461
+ throw makeException(TypeError, "is a view on a detached ArrayBuffer", options);
462
+ }
463
+ return value;
464
+ }
465
+ if (!options.allowShared && !isNonSharedArrayBuffer(value)) {
466
+ throw makeException(TypeError, "is not an ArrayBuffer or a view on one", options);
467
+ }
468
+ if (options.allowShared && !isSharedArrayBuffer(value) && !isNonSharedArrayBuffer(value)) {
469
+ throw makeException(TypeError, "is not an ArrayBuffer, SharedArrayBuffer, or a view on one", options);
470
+ }
471
+ if (isArrayBufferDetached(value)) {
472
+ throw makeException(TypeError, "is a detached ArrayBuffer", options);
473
+ }
474
+ return value;
475
+ };
476
+ exports.DOMTimeStamp = exports["unsigned long long"];
477
+ }
478
+ });
479
+
480
+ // node_modules/domexception/lib/utils.js
481
+ var require_utils = __commonJS({
482
+ "node_modules/domexception/lib/utils.js"(exports, module) {
483
+ "use strict";
484
+ function isObject(value) {
485
+ return typeof value === "object" && value !== null || typeof value === "function";
486
+ }
487
+ var hasOwn = Function.prototype.call.bind(Object.prototype.hasOwnProperty);
488
+ function define(target, source) {
489
+ for (const key of Reflect.ownKeys(source)) {
490
+ const descriptor = Reflect.getOwnPropertyDescriptor(source, key);
491
+ if (descriptor && !Reflect.defineProperty(target, key, descriptor)) {
492
+ throw new TypeError(`Cannot redefine property: ${String(key)}`);
493
+ }
494
+ }
495
+ }
496
+ function newObjectInRealm(globalObject, object) {
497
+ const ctorRegistry = initCtorRegistry(globalObject);
498
+ return Object.defineProperties(
499
+ Object.create(ctorRegistry["%Object.prototype%"]),
500
+ Object.getOwnPropertyDescriptors(object)
501
+ );
502
+ }
503
+ var wrapperSymbol = Symbol("wrapper");
504
+ var implSymbol = Symbol("impl");
505
+ var sameObjectCaches = Symbol("SameObject caches");
506
+ var ctorRegistrySymbol = Symbol.for("[webidl2js] constructor registry");
507
+ var AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {
508
+ }).prototype);
509
+ function initCtorRegistry(globalObject) {
510
+ if (hasOwn(globalObject, ctorRegistrySymbol)) {
511
+ return globalObject[ctorRegistrySymbol];
512
+ }
513
+ const ctorRegistry = /* @__PURE__ */ Object.create(null);
514
+ ctorRegistry["%Object.prototype%"] = globalObject.Object.prototype;
515
+ ctorRegistry["%IteratorPrototype%"] = Object.getPrototypeOf(
516
+ Object.getPrototypeOf(new globalObject.Array()[Symbol.iterator]())
517
+ );
518
+ try {
519
+ ctorRegistry["%AsyncIteratorPrototype%"] = Object.getPrototypeOf(
520
+ Object.getPrototypeOf(
521
+ globalObject.eval("(async function* () {})").prototype
522
+ )
523
+ );
524
+ } catch {
525
+ ctorRegistry["%AsyncIteratorPrototype%"] = AsyncIteratorPrototype;
526
+ }
527
+ globalObject[ctorRegistrySymbol] = ctorRegistry;
528
+ return ctorRegistry;
529
+ }
530
+ function getSameObject(wrapper, prop, creator) {
531
+ if (!wrapper[sameObjectCaches]) {
532
+ wrapper[sameObjectCaches] = /* @__PURE__ */ Object.create(null);
533
+ }
534
+ if (prop in wrapper[sameObjectCaches]) {
535
+ return wrapper[sameObjectCaches][prop];
536
+ }
537
+ wrapper[sameObjectCaches][prop] = creator();
538
+ return wrapper[sameObjectCaches][prop];
539
+ }
540
+ function wrapperForImpl(impl) {
541
+ return impl ? impl[wrapperSymbol] : null;
542
+ }
543
+ function implForWrapper(wrapper) {
544
+ return wrapper ? wrapper[implSymbol] : null;
545
+ }
546
+ function tryWrapperForImpl(impl) {
547
+ const wrapper = wrapperForImpl(impl);
548
+ return wrapper ? wrapper : impl;
549
+ }
550
+ function tryImplForWrapper(wrapper) {
551
+ const impl = implForWrapper(wrapper);
552
+ return impl ? impl : wrapper;
553
+ }
554
+ var iterInternalSymbol = Symbol("internal");
555
+ function isArrayIndexPropName(P) {
556
+ if (typeof P !== "string") {
557
+ return false;
558
+ }
559
+ const i = P >>> 0;
560
+ if (i === 2 ** 32 - 1) {
561
+ return false;
562
+ }
563
+ const s = `${i}`;
564
+ if (P !== s) {
565
+ return false;
566
+ }
567
+ return true;
568
+ }
569
+ var byteLengthGetter = Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
570
+ function isArrayBuffer(value) {
571
+ try {
572
+ byteLengthGetter.call(value);
573
+ return true;
574
+ } catch (e) {
575
+ return false;
576
+ }
577
+ }
578
+ function iteratorResult([key, value], kind) {
579
+ let result;
580
+ switch (kind) {
581
+ case "key":
582
+ result = key;
583
+ break;
584
+ case "value":
585
+ result = value;
586
+ break;
587
+ case "key+value":
588
+ result = [key, value];
589
+ break;
590
+ }
591
+ return { value: result, done: false };
592
+ }
593
+ var supportsPropertyIndex = Symbol("supports property index");
594
+ var supportedPropertyIndices = Symbol("supported property indices");
595
+ var supportsPropertyName = Symbol("supports property name");
596
+ var supportedPropertyNames = Symbol("supported property names");
597
+ var indexedGet = Symbol("indexed property get");
598
+ var indexedSetNew = Symbol("indexed property set new");
599
+ var indexedSetExisting = Symbol("indexed property set existing");
600
+ var namedGet = Symbol("named property get");
601
+ var namedSetNew = Symbol("named property set new");
602
+ var namedSetExisting = Symbol("named property set existing");
603
+ var namedDelete = Symbol("named property delete");
604
+ var asyncIteratorNext = Symbol("async iterator get the next iteration result");
605
+ var asyncIteratorReturn = Symbol("async iterator return steps");
606
+ var asyncIteratorInit = Symbol("async iterator initialization steps");
607
+ var asyncIteratorEOI = Symbol("async iterator end of iteration");
608
+ module.exports = exports = {
609
+ isObject,
610
+ hasOwn,
611
+ define,
612
+ newObjectInRealm,
613
+ wrapperSymbol,
614
+ implSymbol,
615
+ getSameObject,
616
+ ctorRegistrySymbol,
617
+ initCtorRegistry,
618
+ wrapperForImpl,
619
+ implForWrapper,
620
+ tryWrapperForImpl,
621
+ tryImplForWrapper,
622
+ iterInternalSymbol,
623
+ isArrayBuffer,
624
+ isArrayIndexPropName,
625
+ supportsPropertyIndex,
626
+ supportedPropertyIndices,
627
+ supportsPropertyName,
628
+ supportedPropertyNames,
629
+ indexedGet,
630
+ indexedSetNew,
631
+ indexedSetExisting,
632
+ namedGet,
633
+ namedSetNew,
634
+ namedSetExisting,
635
+ namedDelete,
636
+ asyncIteratorNext,
637
+ asyncIteratorReturn,
638
+ asyncIteratorInit,
639
+ asyncIteratorEOI,
640
+ iteratorResult
641
+ };
642
+ }
643
+ });
644
+
645
+ // node_modules/domexception/lib/legacy-error-codes.json
646
+ var require_legacy_error_codes = __commonJS({
647
+ "node_modules/domexception/lib/legacy-error-codes.json"(exports, module) {
648
+ module.exports = {
649
+ IndexSizeError: 1,
650
+ HierarchyRequestError: 3,
651
+ WrongDocumentError: 4,
652
+ InvalidCharacterError: 5,
653
+ NoModificationAllowedError: 7,
654
+ NotFoundError: 8,
655
+ NotSupportedError: 9,
656
+ InUseAttributeError: 10,
657
+ InvalidStateError: 11,
658
+ SyntaxError: 12,
659
+ InvalidModificationError: 13,
660
+ NamespaceError: 14,
661
+ InvalidAccessError: 15,
662
+ TypeMismatchError: 17,
663
+ SecurityError: 18,
664
+ NetworkError: 19,
665
+ AbortError: 20,
666
+ URLMismatchError: 21,
667
+ QuotaExceededError: 22,
668
+ TimeoutError: 23,
669
+ InvalidNodeTypeError: 24,
670
+ DataCloneError: 25
671
+ };
672
+ }
673
+ });
674
+
675
+ // node_modules/domexception/lib/DOMException-impl.js
676
+ var require_DOMException_impl = __commonJS({
677
+ "node_modules/domexception/lib/DOMException-impl.js"(exports) {
678
+ "use strict";
679
+ var legacyErrorCodes = require_legacy_error_codes();
680
+ var idlUtils = require_utils();
681
+ exports.implementation = class DOMExceptionImpl {
682
+ constructor(globalObject, [message, name]) {
683
+ this.name = name;
684
+ this.message = message;
685
+ }
686
+ get code() {
687
+ return legacyErrorCodes[this.name] || 0;
688
+ }
689
+ };
690
+ exports.init = (impl) => {
691
+ if (Error.captureStackTrace) {
692
+ const wrapper = idlUtils.wrapperForImpl(impl);
693
+ Error.captureStackTrace(wrapper, wrapper.constructor);
694
+ }
695
+ };
696
+ }
697
+ });
698
+
699
+ // node_modules/domexception/lib/DOMException.js
700
+ var require_DOMException = __commonJS({
701
+ "node_modules/domexception/lib/DOMException.js"(exports) {
702
+ "use strict";
703
+ var conversions = require_lib();
704
+ var utils = require_utils();
705
+ var implSymbol = utils.implSymbol;
706
+ var ctorRegistrySymbol = utils.ctorRegistrySymbol;
707
+ var interfaceName = "DOMException";
708
+ exports.is = (value) => {
709
+ return utils.isObject(value) && utils.hasOwn(value, implSymbol) && value[implSymbol] instanceof Impl.implementation;
710
+ };
711
+ exports.isImpl = (value) => {
712
+ return utils.isObject(value) && value instanceof Impl.implementation;
713
+ };
714
+ exports.convert = (globalObject, value, { context = "The provided value" } = {}) => {
715
+ if (exports.is(value)) {
716
+ return utils.implForWrapper(value);
717
+ }
718
+ throw new globalObject.TypeError(`${context} is not of type 'DOMException'.`);
719
+ };
720
+ function makeWrapper(globalObject, newTarget) {
721
+ let proto;
722
+ if (newTarget !== void 0) {
723
+ proto = newTarget.prototype;
724
+ }
725
+ if (!utils.isObject(proto)) {
726
+ proto = globalObject[ctorRegistrySymbol]["DOMException"].prototype;
727
+ }
728
+ return Object.create(proto);
729
+ }
730
+ exports.create = (globalObject, constructorArgs, privateData) => {
731
+ const wrapper = makeWrapper(globalObject);
732
+ return exports.setup(wrapper, globalObject, constructorArgs, privateData);
733
+ };
734
+ exports.createImpl = (globalObject, constructorArgs, privateData) => {
735
+ const wrapper = exports.create(globalObject, constructorArgs, privateData);
736
+ return utils.implForWrapper(wrapper);
737
+ };
738
+ exports._internalSetup = (wrapper, globalObject) => {
739
+ };
740
+ exports.setup = (wrapper, globalObject, constructorArgs = [], privateData = {}) => {
741
+ privateData.wrapper = wrapper;
742
+ exports._internalSetup(wrapper, globalObject);
743
+ Object.defineProperty(wrapper, implSymbol, {
744
+ value: new Impl.implementation(globalObject, constructorArgs, privateData),
745
+ configurable: true
746
+ });
747
+ wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
748
+ if (Impl.init) {
749
+ Impl.init(wrapper[implSymbol]);
750
+ }
751
+ return wrapper;
752
+ };
753
+ exports.new = (globalObject, newTarget) => {
754
+ const wrapper = makeWrapper(globalObject, newTarget);
755
+ exports._internalSetup(wrapper, globalObject);
756
+ Object.defineProperty(wrapper, implSymbol, {
757
+ value: Object.create(Impl.implementation.prototype),
758
+ configurable: true
759
+ });
760
+ wrapper[implSymbol][utils.wrapperSymbol] = wrapper;
761
+ if (Impl.init) {
762
+ Impl.init(wrapper[implSymbol]);
763
+ }
764
+ return wrapper[implSymbol];
765
+ };
766
+ var exposed = /* @__PURE__ */ new Set(["Window", "Worker"]);
767
+ exports.install = (globalObject, globalNames) => {
768
+ if (!globalNames.some((globalName) => exposed.has(globalName))) {
769
+ return;
770
+ }
771
+ const ctorRegistry = utils.initCtorRegistry(globalObject);
772
+ class DOMException {
773
+ constructor() {
774
+ const args = [];
775
+ {
776
+ let curArg = arguments[0];
777
+ if (curArg !== void 0) {
778
+ curArg = conversions["DOMString"](curArg, {
779
+ context: "Failed to construct 'DOMException': parameter 1",
780
+ globals: globalObject
781
+ });
782
+ } else {
783
+ curArg = "";
784
+ }
785
+ args.push(curArg);
786
+ }
787
+ {
788
+ let curArg = arguments[1];
789
+ if (curArg !== void 0) {
790
+ curArg = conversions["DOMString"](curArg, {
791
+ context: "Failed to construct 'DOMException': parameter 2",
792
+ globals: globalObject
793
+ });
794
+ } else {
795
+ curArg = "Error";
796
+ }
797
+ args.push(curArg);
798
+ }
799
+ return exports.setup(Object.create(new.target.prototype), globalObject, args);
800
+ }
801
+ get name() {
802
+ const esValue = this !== null && this !== void 0 ? this : globalObject;
803
+ if (!exports.is(esValue)) {
804
+ throw new globalObject.TypeError(
805
+ "'get name' called on an object that is not a valid instance of DOMException."
806
+ );
807
+ }
808
+ return esValue[implSymbol]["name"];
809
+ }
810
+ get message() {
811
+ const esValue = this !== null && this !== void 0 ? this : globalObject;
812
+ if (!exports.is(esValue)) {
813
+ throw new globalObject.TypeError(
814
+ "'get message' called on an object that is not a valid instance of DOMException."
815
+ );
816
+ }
817
+ return esValue[implSymbol]["message"];
818
+ }
819
+ get code() {
820
+ const esValue = this !== null && this !== void 0 ? this : globalObject;
821
+ if (!exports.is(esValue)) {
822
+ throw new globalObject.TypeError(
823
+ "'get code' called on an object that is not a valid instance of DOMException."
824
+ );
825
+ }
826
+ return esValue[implSymbol]["code"];
827
+ }
828
+ }
829
+ Object.defineProperties(DOMException.prototype, {
830
+ name: { enumerable: true },
831
+ message: { enumerable: true },
832
+ code: { enumerable: true },
833
+ [Symbol.toStringTag]: { value: "DOMException", configurable: true },
834
+ INDEX_SIZE_ERR: { value: 1, enumerable: true },
835
+ DOMSTRING_SIZE_ERR: { value: 2, enumerable: true },
836
+ HIERARCHY_REQUEST_ERR: { value: 3, enumerable: true },
837
+ WRONG_DOCUMENT_ERR: { value: 4, enumerable: true },
838
+ INVALID_CHARACTER_ERR: { value: 5, enumerable: true },
839
+ NO_DATA_ALLOWED_ERR: { value: 6, enumerable: true },
840
+ NO_MODIFICATION_ALLOWED_ERR: { value: 7, enumerable: true },
841
+ NOT_FOUND_ERR: { value: 8, enumerable: true },
842
+ NOT_SUPPORTED_ERR: { value: 9, enumerable: true },
843
+ INUSE_ATTRIBUTE_ERR: { value: 10, enumerable: true },
844
+ INVALID_STATE_ERR: { value: 11, enumerable: true },
845
+ SYNTAX_ERR: { value: 12, enumerable: true },
846
+ INVALID_MODIFICATION_ERR: { value: 13, enumerable: true },
847
+ NAMESPACE_ERR: { value: 14, enumerable: true },
848
+ INVALID_ACCESS_ERR: { value: 15, enumerable: true },
849
+ VALIDATION_ERR: { value: 16, enumerable: true },
850
+ TYPE_MISMATCH_ERR: { value: 17, enumerable: true },
851
+ SECURITY_ERR: { value: 18, enumerable: true },
852
+ NETWORK_ERR: { value: 19, enumerable: true },
853
+ ABORT_ERR: { value: 20, enumerable: true },
854
+ URL_MISMATCH_ERR: { value: 21, enumerable: true },
855
+ QUOTA_EXCEEDED_ERR: { value: 22, enumerable: true },
856
+ TIMEOUT_ERR: { value: 23, enumerable: true },
857
+ INVALID_NODE_TYPE_ERR: { value: 24, enumerable: true },
858
+ DATA_CLONE_ERR: { value: 25, enumerable: true }
859
+ });
860
+ Object.defineProperties(DOMException, {
861
+ INDEX_SIZE_ERR: { value: 1, enumerable: true },
862
+ DOMSTRING_SIZE_ERR: { value: 2, enumerable: true },
863
+ HIERARCHY_REQUEST_ERR: { value: 3, enumerable: true },
864
+ WRONG_DOCUMENT_ERR: { value: 4, enumerable: true },
865
+ INVALID_CHARACTER_ERR: { value: 5, enumerable: true },
866
+ NO_DATA_ALLOWED_ERR: { value: 6, enumerable: true },
867
+ NO_MODIFICATION_ALLOWED_ERR: { value: 7, enumerable: true },
868
+ NOT_FOUND_ERR: { value: 8, enumerable: true },
869
+ NOT_SUPPORTED_ERR: { value: 9, enumerable: true },
870
+ INUSE_ATTRIBUTE_ERR: { value: 10, enumerable: true },
871
+ INVALID_STATE_ERR: { value: 11, enumerable: true },
872
+ SYNTAX_ERR: { value: 12, enumerable: true },
873
+ INVALID_MODIFICATION_ERR: { value: 13, enumerable: true },
874
+ NAMESPACE_ERR: { value: 14, enumerable: true },
875
+ INVALID_ACCESS_ERR: { value: 15, enumerable: true },
876
+ VALIDATION_ERR: { value: 16, enumerable: true },
877
+ TYPE_MISMATCH_ERR: { value: 17, enumerable: true },
878
+ SECURITY_ERR: { value: 18, enumerable: true },
879
+ NETWORK_ERR: { value: 19, enumerable: true },
880
+ ABORT_ERR: { value: 20, enumerable: true },
881
+ URL_MISMATCH_ERR: { value: 21, enumerable: true },
882
+ QUOTA_EXCEEDED_ERR: { value: 22, enumerable: true },
883
+ TIMEOUT_ERR: { value: 23, enumerable: true },
884
+ INVALID_NODE_TYPE_ERR: { value: 24, enumerable: true },
885
+ DATA_CLONE_ERR: { value: 25, enumerable: true }
886
+ });
887
+ ctorRegistry[interfaceName] = DOMException;
888
+ Object.defineProperty(globalObject, interfaceName, {
889
+ configurable: true,
890
+ writable: true,
891
+ value: DOMException
892
+ });
893
+ };
894
+ var Impl = require_DOMException_impl();
895
+ }
896
+ });
897
+
898
+ // node_modules/domexception/webidl2js-wrapper.js
899
+ var require_webidl2js_wrapper = __commonJS({
900
+ "node_modules/domexception/webidl2js-wrapper.js"(exports, module) {
901
+ "use strict";
902
+ var DOMException = require_DOMException();
903
+ function installOverride(globalObject, globalNames) {
904
+ if (typeof globalObject.Error !== "function") {
905
+ throw new Error("Internal error: Error constructor is not present on the given global object.");
906
+ }
907
+ DOMException.install(globalObject, globalNames);
908
+ Object.setPrototypeOf(globalObject.DOMException.prototype, globalObject.Error.prototype);
909
+ }
910
+ module.exports = { ...DOMException, install: installOverride };
911
+ }
912
+ });
913
+
914
+ // node_modules/domexception/index.js
915
+ var require_domexception = __commonJS({
916
+ "node_modules/domexception/index.js"(exports, module) {
917
+ "use strict";
918
+ var DOMException = require_webidl2js_wrapper();
919
+ var sharedGlobalObject = { Array, Error, Object, Promise, String, TypeError };
920
+ DOMException.install(sharedGlobalObject, ["Window"]);
921
+ module.exports = sharedGlobalObject.DOMException;
922
+ }
923
+ });
924
+
925
+ // node_modules/@roamhq/wrtc/lib/datachannelevent.js
926
+ var require_datachannelevent = __commonJS({
927
+ "node_modules/@roamhq/wrtc/lib/datachannelevent.js"(exports, module) {
928
+ "use strict";
929
+ function RTCDataChannelEvent(type, eventInitDict) {
930
+ Object.defineProperties(this, {
931
+ bubbles: {
932
+ value: false
933
+ },
934
+ cancelable: {
935
+ value: false
936
+ },
937
+ type: {
938
+ value: type,
939
+ enumerable: true
940
+ },
941
+ channel: {
942
+ value: eventInitDict.channel,
943
+ enumerable: true
944
+ },
945
+ target: {
946
+ value: eventInitDict.target,
947
+ enumerable: true
948
+ }
949
+ });
950
+ }
951
+ module.exports = RTCDataChannelEvent;
952
+ }
953
+ });
954
+
955
+ // node_modules/@roamhq/wrtc/lib/icecandidate.js
956
+ var require_icecandidate = __commonJS({
957
+ "node_modules/@roamhq/wrtc/lib/icecandidate.js"(exports, module) {
958
+ "use strict";
959
+ function RTCIceCandidate(candidateInitDict) {
960
+ [
961
+ "candidate",
962
+ "sdpMid",
963
+ "sdpMLineIndex",
964
+ "foundation",
965
+ "component",
966
+ "priority",
967
+ "address",
968
+ "protocol",
969
+ "port",
970
+ "type",
971
+ "tcpType",
972
+ "relatedAddress",
973
+ "relatedPort",
974
+ "usernameFragment"
975
+ ].forEach((property) => {
976
+ if (candidateInitDict && property in candidateInitDict) {
977
+ this[property] = candidateInitDict[property];
978
+ } else {
979
+ this[property] = null;
980
+ }
981
+ });
982
+ this.toJSON = () => {
983
+ const { candidate, sdpMid, sdpMLineIndex, usernameFragment } = this;
984
+ let json = {
985
+ candidate,
986
+ sdpMid,
987
+ sdpMLineIndex
988
+ };
989
+ if (usernameFragment) {
990
+ json.usernameFragment = usernameFragment;
991
+ }
992
+ return json;
993
+ };
994
+ }
995
+ module.exports = RTCIceCandidate;
996
+ }
997
+ });
998
+
999
+ // node_modules/@roamhq/wrtc/lib/rtcpeerconnectioniceevent.js
1000
+ var require_rtcpeerconnectioniceevent = __commonJS({
1001
+ "node_modules/@roamhq/wrtc/lib/rtcpeerconnectioniceevent.js"(exports, module) {
1002
+ "use strict";
1003
+ function RTCPeerConnectionIceEvent(type, eventInitDict) {
1004
+ Object.defineProperties(this, {
1005
+ type: {
1006
+ value: type,
1007
+ enumerable: true
1008
+ },
1009
+ candidate: {
1010
+ value: eventInitDict.candidate,
1011
+ enumerable: true
1012
+ },
1013
+ target: {
1014
+ value: eventInitDict.target,
1015
+ enumerable: true
1016
+ }
1017
+ });
1018
+ }
1019
+ module.exports = RTCPeerConnectionIceEvent;
1020
+ }
1021
+ });
1022
+
1023
+ // node_modules/@roamhq/wrtc/lib/rtcpeerconnectioniceerrorevent.js
1024
+ var require_rtcpeerconnectioniceerrorevent = __commonJS({
1025
+ "node_modules/@roamhq/wrtc/lib/rtcpeerconnectioniceerrorevent.js"(exports, module) {
1026
+ "use strict";
1027
+ function RTCPeerConnectionIceErrorEvent(type, eventInitDict) {
1028
+ Object.defineProperties(this, {
1029
+ type: {
1030
+ value: type,
1031
+ enumerable: true
1032
+ },
1033
+ address: {
1034
+ value: eventInitDict.address,
1035
+ enumerable: true
1036
+ },
1037
+ port: {
1038
+ value: eventInitDict.port,
1039
+ enumerable: true
1040
+ },
1041
+ url: {
1042
+ value: eventInitDict.url,
1043
+ enumerable: true
1044
+ },
1045
+ errorCode: {
1046
+ value: eventInitDict.errorCode,
1047
+ enumerable: true
1048
+ },
1049
+ errorText: {
1050
+ value: eventInitDict.errorText,
1051
+ enumerable: true
1052
+ },
1053
+ target: {
1054
+ value: eventInitDict.target,
1055
+ enumerable: true
1056
+ }
1057
+ });
1058
+ }
1059
+ module.exports = RTCPeerConnectionIceErrorEvent;
1060
+ }
1061
+ });
1062
+
1063
+ // node_modules/@roamhq/wrtc/lib/sessiondescription.js
1064
+ var require_sessiondescription = __commonJS({
1065
+ "node_modules/@roamhq/wrtc/lib/sessiondescription.js"(exports, module) {
1066
+ "use strict";
1067
+ function RTCSessionDescription(descriptionInitDict) {
1068
+ if (descriptionInitDict) {
1069
+ this.type = descriptionInitDict.type;
1070
+ this.sdp = descriptionInitDict.sdp;
1071
+ }
1072
+ this.toJSON = () => {
1073
+ const { sdp, type } = this;
1074
+ return {
1075
+ sdp,
1076
+ type
1077
+ };
1078
+ };
1079
+ }
1080
+ module.exports = RTCSessionDescription;
1081
+ }
1082
+ });
1083
+
1084
+ // node_modules/@roamhq/wrtc/lib/peerconnection.js
1085
+ var require_peerconnection = __commonJS({
1086
+ "node_modules/@roamhq/wrtc/lib/peerconnection.js"(exports, module) {
1087
+ "use strict";
1088
+ var inherits = __require("util").inherits;
1089
+ var _webrtc = require_binding();
1090
+ var EventTarget = require_eventtarget();
1091
+ var RTCDataChannelEvent = require_datachannelevent();
1092
+ var RTCIceCandidate = require_icecandidate();
1093
+ var RTCPeerConnectionIceEvent = require_rtcpeerconnectioniceevent();
1094
+ var RTCPeerConnectionIceErrorEvent = require_rtcpeerconnectioniceerrorevent();
1095
+ var RTCSessionDescription = require_sessiondescription();
1096
+ function RTCPeerConnection() {
1097
+ var self = this;
1098
+ var pc = new _webrtc.RTCPeerConnection(arguments[0] || {});
1099
+ EventTarget.call(this);
1100
+ pc.ontrack = function ontrack(receiver, streams, transceiver) {
1101
+ self.dispatchEvent({
1102
+ type: "track",
1103
+ track: receiver.track,
1104
+ receiver,
1105
+ streams,
1106
+ transceiver,
1107
+ target: self
1108
+ });
1109
+ };
1110
+ pc.onconnectionstatechange = function onconnectionstatechange() {
1111
+ self.dispatchEvent({ type: "connectionstatechange", target: self });
1112
+ };
1113
+ pc.onicecandidate = function onicecandidate(candidate) {
1114
+ var icecandidate = new RTCIceCandidate(candidate);
1115
+ self.dispatchEvent(
1116
+ new RTCPeerConnectionIceEvent("icecandidate", {
1117
+ candidate: icecandidate,
1118
+ target: self
1119
+ })
1120
+ );
1121
+ };
1122
+ pc.onicecandidateerror = function onicecandidateerror(eventInitDict) {
1123
+ eventInitDict.target = self;
1124
+ var icecandidateerror = new RTCPeerConnectionIceErrorEvent(
1125
+ "icecandidateerror",
1126
+ eventInitDict
1127
+ );
1128
+ self.dispatchEvent(icecandidateerror);
1129
+ };
1130
+ pc.onsignalingstatechange = function onsignalingstatechange() {
1131
+ self.dispatchEvent({ type: "signalingstatechange", target: self });
1132
+ };
1133
+ pc.oniceconnectionstatechange = function oniceconnectionstatechange() {
1134
+ self.dispatchEvent({ type: "iceconnectionstatechange", target: self });
1135
+ };
1136
+ pc.onicegatheringstatechange = function onicegatheringstatechange() {
1137
+ self.dispatchEvent({ type: "icegatheringstatechange", target: self });
1138
+ if (self.iceGatheringState === "complete" && self.connectionState !== "closed") {
1139
+ self.dispatchEvent(
1140
+ new RTCPeerConnectionIceEvent("icecandidate", {
1141
+ candidate: null,
1142
+ target: self
1143
+ })
1144
+ );
1145
+ }
1146
+ };
1147
+ pc.onnegotiationneeded = function onnegotiationneeded() {
1148
+ self.dispatchEvent({ type: "negotiationneeded", target: self });
1149
+ };
1150
+ pc.ondatachannel = function ondatachannel(channel) {
1151
+ self.dispatchEvent(
1152
+ new RTCDataChannelEvent("datachannel", { channel, target: self })
1153
+ );
1154
+ };
1155
+ Object.defineProperties(this, {
1156
+ _pc: {
1157
+ value: pc
1158
+ },
1159
+ canTrickleIceCandidates: {
1160
+ get: function getCanTrickleIceCandidates() {
1161
+ return pc.canTrickleIceCandidates;
1162
+ },
1163
+ enumerable: true
1164
+ },
1165
+ connectionState: {
1166
+ get: function getConnectionState() {
1167
+ return pc.connectionState;
1168
+ },
1169
+ enumerable: true
1170
+ },
1171
+ currentLocalDescription: {
1172
+ get: function getCurrentLocalDescription() {
1173
+ return pc.currentLocalDescription ? new RTCSessionDescription(pc.currentLocalDescription) : null;
1174
+ },
1175
+ enumerable: true
1176
+ },
1177
+ localDescription: {
1178
+ get: function getLocalDescription() {
1179
+ return pc.localDescription ? new RTCSessionDescription(pc.localDescription) : null;
1180
+ },
1181
+ enumerable: true
1182
+ },
1183
+ pendingLocalDescription: {
1184
+ get: function getPendingLocalDescription() {
1185
+ return pc.pendingLocalDescription ? new RTCSessionDescription(pc.pendingLocalDescription) : null;
1186
+ },
1187
+ enumerable: true
1188
+ },
1189
+ currentRemoteDescription: {
1190
+ get: function getCurrentRemoteDescription() {
1191
+ return pc.currentRemoteDescription ? new RTCSessionDescription(pc.currentRemoteDescription) : null;
1192
+ },
1193
+ enumerable: true
1194
+ },
1195
+ remoteDescription: {
1196
+ get: function getRemoteDescription() {
1197
+ return pc.remoteDescription ? new RTCSessionDescription(pc.remoteDescription) : null;
1198
+ },
1199
+ enumerable: true
1200
+ },
1201
+ pendingRemoteDescription: {
1202
+ get: function getPendingRemoteDescription() {
1203
+ return pc.pendingRemoteDescription ? new RTCSessionDescription(pc.pendingRemoteDescription) : null;
1204
+ },
1205
+ enumerable: true
1206
+ },
1207
+ signalingState: {
1208
+ get: function getSignalingState() {
1209
+ return pc.signalingState;
1210
+ },
1211
+ enumerable: true
1212
+ },
1213
+ readyState: {
1214
+ get: function getReadyState() {
1215
+ return pc.getReadyState();
1216
+ }
1217
+ },
1218
+ sctp: {
1219
+ get: function() {
1220
+ return pc.sctp;
1221
+ },
1222
+ enumerable: true
1223
+ },
1224
+ iceGatheringState: {
1225
+ get: function getIceGatheringState() {
1226
+ return pc.iceGatheringState;
1227
+ },
1228
+ enumerable: true
1229
+ },
1230
+ iceConnectionState: {
1231
+ get: function getIceConnectionState() {
1232
+ return pc.iceConnectionState;
1233
+ },
1234
+ enumerable: true
1235
+ },
1236
+ onconnectionstatechange: {
1237
+ value: null,
1238
+ writable: true,
1239
+ enumerable: true
1240
+ },
1241
+ ondatachannel: {
1242
+ value: null,
1243
+ writable: true,
1244
+ enumerable: true
1245
+ },
1246
+ oniceconnectionstatechange: {
1247
+ value: null,
1248
+ writable: true,
1249
+ enumerable: true
1250
+ },
1251
+ onicegatheringstatechange: {
1252
+ value: null,
1253
+ writable: true,
1254
+ enumerable: true
1255
+ },
1256
+ onnegotiationneeded: {
1257
+ value: null,
1258
+ writable: true,
1259
+ enumerable: true
1260
+ },
1261
+ onsignalingstatechange: {
1262
+ value: null,
1263
+ writable: true,
1264
+ enumerable: true
1265
+ }
1266
+ });
1267
+ }
1268
+ inherits(RTCPeerConnection, EventTarget);
1269
+ RTCPeerConnection.prototype.ontrack = null;
1270
+ RTCPeerConnection.prototype.addIceCandidate = function addIceCandidate(candidate) {
1271
+ if (!candidate?.candidate) {
1272
+ candidate = void 0;
1273
+ }
1274
+ var promise = this._pc.addIceCandidate(candidate);
1275
+ if (arguments.length === 3) {
1276
+ promise.then(arguments[1], arguments[2]);
1277
+ }
1278
+ return promise;
1279
+ };
1280
+ RTCPeerConnection.prototype.addTransceiver = function addTransceiver() {
1281
+ return this._pc.addTransceiver.apply(this._pc, arguments);
1282
+ };
1283
+ RTCPeerConnection.prototype.addTrack = function addTrack(track, ...streams) {
1284
+ return this._pc.addTrack(track, streams);
1285
+ };
1286
+ RTCPeerConnection.prototype.close = function close() {
1287
+ this._pc.close();
1288
+ };
1289
+ RTCPeerConnection.prototype.createDataChannel = function createDataChannel() {
1290
+ return this._pc.createDataChannel.apply(this._pc, arguments);
1291
+ };
1292
+ RTCPeerConnection.prototype.createOffer = function createOffer() {
1293
+ var options = arguments.length === 3 ? arguments[2] : arguments[0];
1294
+ var promise = this._pc.createOffer(options || {});
1295
+ if (arguments.length >= 2) {
1296
+ promise.then(arguments[0], arguments[1]);
1297
+ }
1298
+ return promise;
1299
+ };
1300
+ RTCPeerConnection.prototype.createAnswer = function createAnswer() {
1301
+ var options = arguments.length === 3 ? arguments[2] : arguments[0];
1302
+ var promise = this._pc.createAnswer(options || {});
1303
+ if (arguments.length >= 2) {
1304
+ promise.then(arguments[0], arguments[1]);
1305
+ }
1306
+ return promise;
1307
+ };
1308
+ RTCPeerConnection.prototype.getConfiguration = function getConfiguration() {
1309
+ return this._pc.getConfiguration();
1310
+ };
1311
+ RTCPeerConnection.prototype.getReceivers = function getReceivers() {
1312
+ return this._pc.getReceivers();
1313
+ };
1314
+ RTCPeerConnection.prototype.getSenders = function getSenders() {
1315
+ return this._pc.getSenders();
1316
+ };
1317
+ RTCPeerConnection.prototype.getTransceivers = function getTransceivers() {
1318
+ return this._pc.getTransceivers();
1319
+ };
1320
+ RTCPeerConnection.prototype.getStats = function getStats() {
1321
+ return this._pc.getStats(arguments[0]);
1322
+ };
1323
+ RTCPeerConnection.prototype.removeTrack = function removeTrack(sender) {
1324
+ this._pc.removeTrack(sender);
1325
+ };
1326
+ RTCPeerConnection.prototype.setConfiguration = function setConfiguration(configuration) {
1327
+ return this._pc.setConfiguration(configuration);
1328
+ };
1329
+ RTCPeerConnection.prototype.setLocalDescription = function setLocalDescription(description) {
1330
+ var promise = this._pc.setLocalDescription(description);
1331
+ if (arguments.length === 3) {
1332
+ promise.then(arguments[1], arguments[2]);
1333
+ }
1334
+ return promise;
1335
+ };
1336
+ RTCPeerConnection.prototype.setRemoteDescription = function setRemoteDescription(description) {
1337
+ var promise = this._pc.setRemoteDescription(description);
1338
+ if (arguments.length === 3) {
1339
+ promise.then(arguments[1], arguments[2]);
1340
+ }
1341
+ return promise;
1342
+ };
1343
+ RTCPeerConnection.prototype.restartIce = function restartIce() {
1344
+ return this._pc.restartIce();
1345
+ };
1346
+ module.exports = RTCPeerConnection;
1347
+ }
1348
+ });
1349
+
1350
+ // node_modules/@roamhq/wrtc/lib/index.js
1351
+ var require_lib2 = __commonJS({
1352
+ "node_modules/@roamhq/wrtc/lib/index.js"(exports, module) {
1353
+ "use strict";
1354
+ var { inherits } = __require("util");
1355
+ var {
1356
+ MediaStream,
1357
+ MediaStreamTrack,
1358
+ RTCAudioSink,
1359
+ RTCAudioSource,
1360
+ RTCDataChannel,
1361
+ RTCDtlsTransport,
1362
+ RTCIceTransport,
1363
+ RTCRtpReceiver,
1364
+ RTCRtpSender,
1365
+ RTCRtpTransceiver,
1366
+ RTCSctpTransport,
1367
+ RTCVideoSink,
1368
+ RTCVideoSource,
1369
+ getUserMedia,
1370
+ i420ToRgba,
1371
+ rgbaToI420,
1372
+ setDOMException
1373
+ } = require_binding();
1374
+ var EventTarget = require_eventtarget();
1375
+ var MediaDevices = require_mediadevices();
1376
+ inherits(MediaStream, EventTarget);
1377
+ inherits(MediaStreamTrack, EventTarget);
1378
+ inherits(RTCAudioSink, EventTarget);
1379
+ inherits(RTCDataChannel, EventTarget);
1380
+ inherits(RTCDtlsTransport, EventTarget);
1381
+ inherits(RTCIceTransport, EventTarget);
1382
+ inherits(RTCSctpTransport, EventTarget);
1383
+ inherits(RTCVideoSink, EventTarget);
1384
+ try {
1385
+ setDOMException(require_domexception());
1386
+ } catch (error) {
1387
+ void error;
1388
+ }
1389
+ RTCDataChannel.prototype.send = function send(data) {
1390
+ const implSymbol = Object.getOwnPropertySymbols(data).find(
1391
+ (symbol) => symbol.toString() === "Symbol(impl)"
1392
+ );
1393
+ if (data[implSymbol] && data[implSymbol]._buffer) {
1394
+ data = data[implSymbol]._buffer;
1395
+ }
1396
+ this._send(data);
1397
+ };
1398
+ var mediaDevices = new MediaDevices();
1399
+ var nonstandard = {
1400
+ i420ToRgba,
1401
+ RTCAudioSink,
1402
+ RTCAudioSource,
1403
+ RTCVideoSink,
1404
+ RTCVideoSource,
1405
+ rgbaToI420
1406
+ };
1407
+ module.exports = {
1408
+ MediaStream,
1409
+ MediaStreamTrack,
1410
+ RTCDataChannel,
1411
+ RTCDataChannelEvent: require_datachannelevent(),
1412
+ RTCDtlsTransport,
1413
+ RTCIceCandidate: require_icecandidate(),
1414
+ RTCIceTransport,
1415
+ RTCPeerConnection: require_peerconnection(),
1416
+ RTCPeerConnectionIceEvent: require_rtcpeerconnectioniceevent(),
1417
+ RTCPeerConnectionIceErrorEvent: require_rtcpeerconnectioniceerrorevent(),
1418
+ RTCRtpReceiver,
1419
+ RTCRtpSender,
1420
+ RTCRtpTransceiver,
1421
+ RTCSctpTransport,
1422
+ RTCSessionDescription: require_sessiondescription(),
1423
+ getUserMedia,
1424
+ mediaDevices,
1425
+ nonstandard
1426
+ };
1427
+ }
1428
+ });
1429
+
1
1430
  // src/server.ts
2
1431
  import * as https from "https";
3
1432
  import * as fs from "fs";
@@ -247,7 +1676,6 @@ import fastjsonpatch from "fast-json-patch";
247
1676
  import { WebSocketServer } from "ws";
248
1677
  import { MongoClient } from "mongodb";
249
1678
  import { glMatrix } from "gl-matrix";
250
- import wrtc from "@roamhq/wrtc";
251
1679
  glMatrix.setMatrixArrayType(Array);
252
1680
  var fastPatchProperties = {
253
1681
  "type": true,
@@ -317,9 +1745,11 @@ var TopazCubeServer = class {
317
1745
  documents = {};
318
1746
  isLoading = {};
319
1747
  _documentChanges = {};
1748
+ _documentChanged = {};
320
1749
  _documentState = {};
321
1750
  update = 0;
322
1751
  lastUpdate = 0;
1752
+ _saveiv = null;
323
1753
  _loopiv = null;
324
1754
  _statsiv = null;
325
1755
  _stillUpdating = false;
@@ -463,6 +1893,7 @@ var TopazCubeServer = class {
463
1893
  );
464
1894
  if (!this._documentChanges[name]) {
465
1895
  this._documentChanges[name] = [];
1896
+ this._documentChanged[name] = false;
466
1897
  }
467
1898
  }
468
1899
  _createEmptyDocument(name) {
@@ -521,6 +1952,9 @@ var TopazCubeServer = class {
521
1952
  this._statsiv = setInterval(() => {
522
1953
  this._doStats();
523
1954
  }, 1e3);
1955
+ this._saveiv = setInterval(() => {
1956
+ this._saveChanges();
1957
+ }, 6e4);
524
1958
  }
525
1959
  _loop() {
526
1960
  let now = Date.now();
@@ -610,12 +2044,14 @@ var TopazCubeServer = class {
610
2044
  let name = message.n;
611
2045
  if (!this._documentChanges[name]) {
612
2046
  this._documentChanges[name] = [];
2047
+ this._documentChanged[name] = false;
613
2048
  }
614
2049
  for (let op of message.p) {
615
2050
  if (!this.canSync(client, name, op)) {
616
2051
  continue;
617
2052
  }
618
2053
  this._documentChanges[name].push(op);
2054
+ this._documentChanged[name] = true;
619
2055
  let dop = msgop(op);
620
2056
  applyOperation(this.documents[name], dop);
621
2057
  }
@@ -631,6 +2067,10 @@ var TopazCubeServer = class {
631
2067
  let ping = time - message.st;
632
2068
  client.ctdiff = message.ct + ping / 2 - time;
633
2069
  client.ping = ping;
2070
+ } else if (message.c == "rtc-offer") {
2071
+ this._processOffer(client, message);
2072
+ } else if (message.c == "rtc-candidate") {
2073
+ this._processICECandidate(client, message);
634
2074
  } else if (message.c == "sub") {
635
2075
  await this._checkDocument(message.n, client);
636
2076
  if (!this.documents[message.n]) {
@@ -907,6 +2347,7 @@ var TopazCubeServer = class {
907
2347
  }
908
2348
  _onDocumentChange(name, op, target, path, value) {
909
2349
  this._documentChanges[name]?.push(opmsg(op, target, path, value));
2350
+ this._documentChanged[name] = true;
910
2351
  }
911
2352
  propertyChange(name, id, property) {
912
2353
  let doc = this.documents[name];
@@ -924,7 +2365,24 @@ var TopazCubeServer = class {
924
2365
  e["__changed_" + property] = true;
925
2366
  }
926
2367
  /*= WEBRTC ===================================================================*/
2368
+ _wrtc = null;
2369
+ async _loadWebRTC() {
2370
+ if (!this._wrtc) {
2371
+ try {
2372
+ this._wrtc = await Promise.resolve().then(() => __toESM(require_lib2(), 1));
2373
+ } catch (error) {
2374
+ this.error("WebRTC module not available:", error);
2375
+ throw new Error("WebRTC functionality requires @roamhq/wrtc and platform-specific binary packages");
2376
+ }
2377
+ }
2378
+ return this._wrtc;
2379
+ }
927
2380
  async _processOffer(client, data) {
2381
+ if (!this.allowWebRTC) {
2382
+ this.warn("WebRTC is disabled");
2383
+ return;
2384
+ }
2385
+ const wrtc = await this._loadWebRTC();
928
2386
  const peerConnection = new wrtc.RTCPeerConnection({
929
2387
  iceServers: [
930
2388
  { urls: "stun:stun.l.google.com:19302" },
@@ -1195,6 +2653,17 @@ var TopazCubeServer = class {
1195
2653
  await this._saveDocument(name);
1196
2654
  }
1197
2655
  }
2656
+ async _saveChanges() {
2657
+ if (!this.allowSave) {
2658
+ return;
2659
+ }
2660
+ for (let name in this._documentChanged) {
2661
+ if (this._documentChanged[name]) {
2662
+ await this._saveDocument(name);
2663
+ this._documentChanged[name] = false;
2664
+ }
2665
+ }
2666
+ }
1198
2667
  _initServerDocument() {
1199
2668
  this.documents["_server"] = {
1200
2669
  nextUID: 100
@@ -1206,6 +2675,8 @@ var TopazCubeServer = class {
1206
2675
  this.log("\nEXIT: Caught interrupt signal " + signal);
1207
2676
  this._exited = true;
1208
2677
  clearInterval(this._loopiv);
2678
+ clearInterval(this._statsiv);
2679
+ clearInterval(this._saveiv);
1209
2680
  this.onBeforeExit();
1210
2681
  this.broadcast({ server: "Going down" });
1211
2682
  this._saveAllDocuments();