livekit-client 1.2.2 → 1.2.5

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 (57) hide show
  1. package/dist/livekit-client.esm.mjs +1990 -905
  2. package/dist/livekit-client.esm.mjs.map +1 -1
  3. package/dist/livekit-client.umd.js +1 -1
  4. package/dist/livekit-client.umd.js.map +1 -1
  5. package/dist/src/index.d.ts +2 -1
  6. package/dist/src/index.d.ts.map +1 -1
  7. package/dist/src/options.d.ts +5 -0
  8. package/dist/src/options.d.ts.map +1 -1
  9. package/dist/src/proto/google/protobuf/timestamp.d.ts +1 -1
  10. package/dist/src/proto/google/protobuf/timestamp.d.ts.map +1 -1
  11. package/dist/src/proto/livekit_models.d.ts +34 -34
  12. package/dist/src/proto/livekit_models.d.ts.map +1 -1
  13. package/dist/src/proto/livekit_rtc.d.ts +124 -124
  14. package/dist/src/proto/livekit_rtc.d.ts.map +1 -1
  15. package/dist/src/room/DefaultReconnectPolicy.d.ts +8 -0
  16. package/dist/src/room/DefaultReconnectPolicy.d.ts.map +1 -0
  17. package/dist/src/room/DeviceManager.d.ts +1 -0
  18. package/dist/src/room/DeviceManager.d.ts.map +1 -1
  19. package/dist/src/room/PCTransport.d.ts +5 -1
  20. package/dist/src/room/PCTransport.d.ts.map +1 -1
  21. package/dist/src/room/RTCEngine.d.ts +7 -1
  22. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  23. package/dist/src/room/ReconnectPolicy.d.ts +23 -0
  24. package/dist/src/room/ReconnectPolicy.d.ts.map +1 -0
  25. package/dist/src/room/Room.d.ts +12 -1
  26. package/dist/src/room/Room.d.ts.map +1 -1
  27. package/dist/src/room/events.d.ts +2 -2
  28. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  29. package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
  30. package/dist/src/room/track/LocalAudioTrack.d.ts +0 -1
  31. package/dist/src/room/track/LocalAudioTrack.d.ts.map +1 -1
  32. package/dist/src/room/track/LocalVideoTrack.d.ts +1 -1
  33. package/dist/src/room/track/LocalVideoTrack.d.ts.map +1 -1
  34. package/dist/src/room/track/RemoteTrackPublication.d.ts.map +1 -1
  35. package/dist/src/room/track/RemoteVideoTrack.d.ts +0 -2
  36. package/dist/src/room/track/RemoteVideoTrack.d.ts.map +1 -1
  37. package/dist/src/room/track/create.d.ts.map +1 -1
  38. package/dist/src/room/utils.d.ts +1 -1
  39. package/dist/src/room/utils.d.ts.map +1 -1
  40. package/package.json +37 -33
  41. package/src/index.ts +2 -0
  42. package/src/options.ts +6 -0
  43. package/src/room/DefaultReconnectPolicy.ts +35 -0
  44. package/src/room/DeviceManager.ts +23 -1
  45. package/src/room/PCTransport.ts +91 -17
  46. package/src/room/RTCEngine.ts +105 -33
  47. package/src/room/ReconnectPolicy.ts +25 -0
  48. package/src/room/Room.ts +190 -167
  49. package/src/room/events.ts +2 -2
  50. package/src/room/participant/LocalParticipant.ts +38 -14
  51. package/src/room/participant/RemoteParticipant.ts +14 -0
  52. package/src/room/track/LocalAudioTrack.ts +0 -2
  53. package/src/room/track/LocalVideoTrack.ts +3 -8
  54. package/src/room/track/RemoteTrackPublication.ts +1 -1
  55. package/src/room/track/RemoteVideoTrack.ts +0 -3
  56. package/src/room/track/create.ts +16 -1
  57. package/src/room/utils.ts +7 -5
@@ -1607,9 +1607,11 @@ Long.fromBytesBE = function fromBytesBE(bytes, unsigned) {
1607
1607
  return new Long(bytes[4] << 24 | bytes[5] << 16 | bytes[6] << 8 | bytes[7], bytes[0] << 24 | bytes[1] << 16 | bytes[2] << 8 | bytes[3], unsigned);
1608
1608
  };
1609
1609
 
1610
+ var minimal$1 = {exports: {}};
1611
+
1610
1612
  var indexMinimal = {};
1611
1613
 
1612
- var minimal$1 = {};
1614
+ var minimal = {};
1613
1615
 
1614
1616
  var aspromise = asPromise;
1615
1617
  /**
@@ -2387,618 +2389,656 @@ function pool(alloc, slice, size) {
2387
2389
  };
2388
2390
  }
2389
2391
 
2390
- var longbits = LongBits$2;
2391
- var util$5 = minimal$1;
2392
- /**
2393
- * Constructs new long bits.
2394
- * @classdesc Helper class for working with the low and high bits of a 64 bit value.
2395
- * @memberof util
2396
- * @constructor
2397
- * @param {number} lo Low 32 bits, unsigned
2398
- * @param {number} hi High 32 bits, unsigned
2399
- */
2392
+ var longbits;
2393
+ var hasRequiredLongbits;
2400
2394
 
2401
- function LongBits$2(lo, hi) {
2402
- // note that the casts below are theoretically unnecessary as of today, but older statically
2403
- // generated converter code might still call the ctor with signed 32bits. kept for compat.
2395
+ function requireLongbits() {
2396
+ if (hasRequiredLongbits) return longbits;
2397
+ hasRequiredLongbits = 1;
2404
2398
 
2399
+ longbits = LongBits;
2400
+ var util = requireMinimal();
2405
2401
  /**
2406
- * Low bits.
2407
- * @type {number}
2402
+ * Constructs new long bits.
2403
+ * @classdesc Helper class for working with the low and high bits of a 64 bit value.
2404
+ * @memberof util
2405
+ * @constructor
2406
+ * @param {number} lo Low 32 bits, unsigned
2407
+ * @param {number} hi High 32 bits, unsigned
2408
2408
  */
2409
- this.lo = lo >>> 0;
2409
+
2410
+ function LongBits(lo, hi) {
2411
+ // note that the casts below are theoretically unnecessary as of today, but older statically
2412
+ // generated converter code might still call the ctor with signed 32bits. kept for compat.
2413
+
2414
+ /**
2415
+ * Low bits.
2416
+ * @type {number}
2417
+ */
2418
+ this.lo = lo >>> 0;
2419
+ /**
2420
+ * High bits.
2421
+ * @type {number}
2422
+ */
2423
+
2424
+ this.hi = hi >>> 0;
2425
+ }
2410
2426
  /**
2411
- * High bits.
2412
- * @type {number}
2427
+ * Zero bits.
2428
+ * @memberof util.LongBits
2429
+ * @type {util.LongBits}
2413
2430
  */
2414
2431
 
2415
- this.hi = hi >>> 0;
2416
- }
2417
- /**
2418
- * Zero bits.
2419
- * @memberof util.LongBits
2420
- * @type {util.LongBits}
2421
- */
2422
2432
 
2433
+ var zero = LongBits.zero = new LongBits(0, 0);
2423
2434
 
2424
- var zero = LongBits$2.zero = new LongBits$2(0, 0);
2435
+ zero.toNumber = function () {
2436
+ return 0;
2437
+ };
2425
2438
 
2426
- zero.toNumber = function () {
2427
- return 0;
2428
- };
2439
+ zero.zzEncode = zero.zzDecode = function () {
2440
+ return this;
2441
+ };
2429
2442
 
2430
- zero.zzEncode = zero.zzDecode = function () {
2431
- return this;
2432
- };
2443
+ zero.length = function () {
2444
+ return 1;
2445
+ };
2446
+ /**
2447
+ * Zero hash.
2448
+ * @memberof util.LongBits
2449
+ * @type {string}
2450
+ */
2433
2451
 
2434
- zero.length = function () {
2435
- return 1;
2436
- };
2437
- /**
2438
- * Zero hash.
2439
- * @memberof util.LongBits
2440
- * @type {string}
2441
- */
2442
2452
 
2453
+ var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";
2454
+ /**
2455
+ * Constructs new long bits from the specified number.
2456
+ * @param {number} value Value
2457
+ * @returns {util.LongBits} Instance
2458
+ */
2443
2459
 
2444
- var zeroHash = LongBits$2.zeroHash = "\0\0\0\0\0\0\0\0";
2445
- /**
2446
- * Constructs new long bits from the specified number.
2447
- * @param {number} value Value
2448
- * @returns {util.LongBits} Instance
2449
- */
2460
+ LongBits.fromNumber = function fromNumber(value) {
2461
+ if (value === 0) return zero;
2462
+ var sign = value < 0;
2463
+ if (sign) value = -value;
2464
+ var lo = value >>> 0,
2465
+ hi = (value - lo) / 4294967296 >>> 0;
2466
+
2467
+ if (sign) {
2468
+ hi = ~hi >>> 0;
2469
+ lo = ~lo >>> 0;
2470
+
2471
+ if (++lo > 4294967295) {
2472
+ lo = 0;
2473
+ if (++hi > 4294967295) hi = 0;
2474
+ }
2475
+ }
2476
+
2477
+ return new LongBits(lo, hi);
2478
+ };
2479
+ /**
2480
+ * Constructs new long bits from a number, long or string.
2481
+ * @param {Long|number|string} value Value
2482
+ * @returns {util.LongBits} Instance
2483
+ */
2450
2484
 
2451
- LongBits$2.fromNumber = function fromNumber(value) {
2452
- if (value === 0) return zero;
2453
- var sign = value < 0;
2454
- if (sign) value = -value;
2455
- var lo = value >>> 0,
2456
- hi = (value - lo) / 4294967296 >>> 0;
2457
2485
 
2458
- if (sign) {
2459
- hi = ~hi >>> 0;
2460
- lo = ~lo >>> 0;
2486
+ LongBits.from = function from(value) {
2487
+ if (typeof value === "number") return LongBits.fromNumber(value);
2461
2488
 
2462
- if (++lo > 4294967295) {
2463
- lo = 0;
2464
- if (++hi > 4294967295) hi = 0;
2489
+ if (util.isString(value)) {
2490
+ /* istanbul ignore else */
2491
+ if (util.Long) value = util.Long.fromString(value);else return LongBits.fromNumber(parseInt(value, 10));
2465
2492
  }
2466
- }
2467
2493
 
2468
- return new LongBits$2(lo, hi);
2469
- };
2470
- /**
2471
- * Constructs new long bits from a number, long or string.
2472
- * @param {Long|number|string} value Value
2473
- * @returns {util.LongBits} Instance
2474
- */
2494
+ return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
2495
+ };
2496
+ /**
2497
+ * Converts this long bits to a possibly unsafe JavaScript number.
2498
+ * @param {boolean} [unsigned=false] Whether unsigned or not
2499
+ * @returns {number} Possibly unsafe number
2500
+ */
2475
2501
 
2476
2502
 
2477
- LongBits$2.from = function from(value) {
2478
- if (typeof value === "number") return LongBits$2.fromNumber(value);
2503
+ LongBits.prototype.toNumber = function toNumber(unsigned) {
2504
+ if (!unsigned && this.hi >>> 31) {
2505
+ var lo = ~this.lo + 1 >>> 0,
2506
+ hi = ~this.hi >>> 0;
2507
+ if (!lo) hi = hi + 1 >>> 0;
2508
+ return -(lo + hi * 4294967296);
2509
+ }
2479
2510
 
2480
- if (util$5.isString(value)) {
2481
- /* istanbul ignore else */
2482
- if (util$5.Long) value = util$5.Long.fromString(value);else return LongBits$2.fromNumber(parseInt(value, 10));
2483
- }
2511
+ return this.lo + this.hi * 4294967296;
2512
+ };
2513
+ /**
2514
+ * Converts this long bits to a long.
2515
+ * @param {boolean} [unsigned=false] Whether unsigned or not
2516
+ * @returns {Long} Long
2517
+ */
2484
2518
 
2485
- return value.low || value.high ? new LongBits$2(value.low >>> 0, value.high >>> 0) : zero;
2486
- };
2487
- /**
2488
- * Converts this long bits to a possibly unsafe JavaScript number.
2489
- * @param {boolean} [unsigned=false] Whether unsigned or not
2490
- * @returns {number} Possibly unsafe number
2491
- */
2492
2519
 
2520
+ LongBits.prototype.toLong = function toLong(unsigned) {
2521
+ return util.Long ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
2522
+ /* istanbul ignore next */
2523
+ : {
2524
+ low: this.lo | 0,
2525
+ high: this.hi | 0,
2526
+ unsigned: Boolean(unsigned)
2527
+ };
2528
+ };
2493
2529
 
2494
- LongBits$2.prototype.toNumber = function toNumber(unsigned) {
2495
- if (!unsigned && this.hi >>> 31) {
2496
- var lo = ~this.lo + 1 >>> 0,
2497
- hi = ~this.hi >>> 0;
2498
- if (!lo) hi = hi + 1 >>> 0;
2499
- return -(lo + hi * 4294967296);
2500
- }
2530
+ var charCodeAt = String.prototype.charCodeAt;
2531
+ /**
2532
+ * Constructs new long bits from the specified 8 characters long hash.
2533
+ * @param {string} hash Hash
2534
+ * @returns {util.LongBits} Bits
2535
+ */
2501
2536
 
2502
- return this.lo + this.hi * 4294967296;
2503
- };
2504
- /**
2505
- * Converts this long bits to a long.
2506
- * @param {boolean} [unsigned=false] Whether unsigned or not
2507
- * @returns {Long} Long
2508
- */
2537
+ LongBits.fromHash = function fromHash(hash) {
2538
+ if (hash === zeroHash) return zero;
2539
+ return new LongBits((charCodeAt.call(hash, 0) | charCodeAt.call(hash, 1) << 8 | charCodeAt.call(hash, 2) << 16 | charCodeAt.call(hash, 3) << 24) >>> 0, (charCodeAt.call(hash, 4) | charCodeAt.call(hash, 5) << 8 | charCodeAt.call(hash, 6) << 16 | charCodeAt.call(hash, 7) << 24) >>> 0);
2540
+ };
2541
+ /**
2542
+ * Converts this long bits to a 8 characters long hash.
2543
+ * @returns {string} Hash
2544
+ */
2509
2545
 
2510
2546
 
2511
- LongBits$2.prototype.toLong = function toLong(unsigned) {
2512
- return util$5.Long ? new util$5.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
2513
- /* istanbul ignore next */
2514
- : {
2515
- low: this.lo | 0,
2516
- high: this.hi | 0,
2517
- unsigned: Boolean(unsigned)
2547
+ LongBits.prototype.toHash = function toHash() {
2548
+ return String.fromCharCode(this.lo & 255, this.lo >>> 8 & 255, this.lo >>> 16 & 255, this.lo >>> 24, this.hi & 255, this.hi >>> 8 & 255, this.hi >>> 16 & 255, this.hi >>> 24);
2518
2549
  };
2519
- };
2550
+ /**
2551
+ * Zig-zag encodes this long bits.
2552
+ * @returns {util.LongBits} `this`
2553
+ */
2520
2554
 
2521
- var charCodeAt = String.prototype.charCodeAt;
2522
- /**
2523
- * Constructs new long bits from the specified 8 characters long hash.
2524
- * @param {string} hash Hash
2525
- * @returns {util.LongBits} Bits
2526
- */
2527
2555
 
2528
- LongBits$2.fromHash = function fromHash(hash) {
2529
- if (hash === zeroHash) return zero;
2530
- return new LongBits$2((charCodeAt.call(hash, 0) | charCodeAt.call(hash, 1) << 8 | charCodeAt.call(hash, 2) << 16 | charCodeAt.call(hash, 3) << 24) >>> 0, (charCodeAt.call(hash, 4) | charCodeAt.call(hash, 5) << 8 | charCodeAt.call(hash, 6) << 16 | charCodeAt.call(hash, 7) << 24) >>> 0);
2531
- };
2532
- /**
2533
- * Converts this long bits to a 8 characters long hash.
2534
- * @returns {string} Hash
2535
- */
2556
+ LongBits.prototype.zzEncode = function zzEncode() {
2557
+ var mask = this.hi >> 31;
2558
+ this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
2559
+ this.lo = (this.lo << 1 ^ mask) >>> 0;
2560
+ return this;
2561
+ };
2562
+ /**
2563
+ * Zig-zag decodes this long bits.
2564
+ * @returns {util.LongBits} `this`
2565
+ */
2536
2566
 
2537
2567
 
2538
- LongBits$2.prototype.toHash = function toHash() {
2539
- return String.fromCharCode(this.lo & 255, this.lo >>> 8 & 255, this.lo >>> 16 & 255, this.lo >>> 24, this.hi & 255, this.hi >>> 8 & 255, this.hi >>> 16 & 255, this.hi >>> 24);
2540
- };
2541
- /**
2542
- * Zig-zag encodes this long bits.
2543
- * @returns {util.LongBits} `this`
2544
- */
2568
+ LongBits.prototype.zzDecode = function zzDecode() {
2569
+ var mask = -(this.lo & 1);
2570
+ this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
2571
+ this.hi = (this.hi >>> 1 ^ mask) >>> 0;
2572
+ return this;
2573
+ };
2574
+ /**
2575
+ * Calculates the length of this longbits when encoded as a varint.
2576
+ * @returns {number} Length
2577
+ */
2545
2578
 
2546
2579
 
2547
- LongBits$2.prototype.zzEncode = function zzEncode() {
2548
- var mask = this.hi >> 31;
2549
- this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
2550
- this.lo = (this.lo << 1 ^ mask) >>> 0;
2551
- return this;
2552
- };
2553
- /**
2554
- * Zig-zag decodes this long bits.
2555
- * @returns {util.LongBits} `this`
2556
- */
2580
+ LongBits.prototype.length = function length() {
2581
+ var part0 = this.lo,
2582
+ part1 = (this.lo >>> 28 | this.hi << 4) >>> 0,
2583
+ part2 = this.hi >>> 24;
2584
+ return part2 === 0 ? part1 === 0 ? part0 < 16384 ? part0 < 128 ? 1 : 2 : part0 < 2097152 ? 3 : 4 : part1 < 16384 ? part1 < 128 ? 5 : 6 : part1 < 2097152 ? 7 : 8 : part2 < 128 ? 9 : 10;
2585
+ };
2557
2586
 
2587
+ return longbits;
2588
+ }
2558
2589
 
2559
- LongBits$2.prototype.zzDecode = function zzDecode() {
2560
- var mask = -(this.lo & 1);
2561
- this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
2562
- this.hi = (this.hi >>> 1 ^ mask) >>> 0;
2563
- return this;
2564
- };
2565
- /**
2566
- * Calculates the length of this longbits when encoded as a varint.
2567
- * @returns {number} Length
2568
- */
2590
+ var hasRequiredMinimal;
2569
2591
 
2592
+ function requireMinimal() {
2593
+ if (hasRequiredMinimal) return minimal;
2594
+ hasRequiredMinimal = 1;
2570
2595
 
2571
- LongBits$2.prototype.length = function length() {
2572
- var part0 = this.lo,
2573
- part1 = (this.lo >>> 28 | this.hi << 4) >>> 0,
2574
- part2 = this.hi >>> 24;
2575
- return part2 === 0 ? part1 === 0 ? part0 < 16384 ? part0 < 128 ? 1 : 2 : part0 < 2097152 ? 3 : 4 : part1 < 16384 ? part1 < 128 ? 5 : 6 : part1 < 2097152 ? 7 : 8 : part2 < 128 ? 9 : 10;
2576
- };
2596
+ (function (exports) {
2577
2597
 
2578
- (function (exports) {
2598
+ var util = exports; // used to return a Promise where callback is omitted
2579
2599
 
2580
- var util = exports; // used to return a Promise where callback is omitted
2600
+ util.asPromise = aspromise; // converts to / from base64 encoded strings
2581
2601
 
2582
- util.asPromise = aspromise; // converts to / from base64 encoded strings
2602
+ util.base64 = base64$1; // base class of rpc.Service
2583
2603
 
2584
- util.base64 = base64$1; // base class of rpc.Service
2604
+ util.EventEmitter = eventemitter; // float handling accross browsers
2585
2605
 
2586
- util.EventEmitter = eventemitter; // float handling accross browsers
2606
+ util.float = float; // requires modules optionally and hides the call from bundlers
2587
2607
 
2588
- util.float = float; // requires modules optionally and hides the call from bundlers
2608
+ util.inquire = inquire_1; // converts to / from utf8 encoded strings
2589
2609
 
2590
- util.inquire = inquire_1; // converts to / from utf8 encoded strings
2610
+ util.utf8 = utf8$2; // provides a node-like buffer pool in the browser
2591
2611
 
2592
- util.utf8 = utf8$2; // provides a node-like buffer pool in the browser
2612
+ util.pool = pool_1; // utility to work with the low and high bits of a 64 bit value
2593
2613
 
2594
- util.pool = pool_1; // utility to work with the low and high bits of a 64 bit value
2614
+ util.LongBits = requireLongbits();
2615
+ /**
2616
+ * Whether running within node or not.
2617
+ * @memberof util
2618
+ * @type {boolean}
2619
+ */
2595
2620
 
2596
- util.LongBits = longbits;
2597
- /**
2598
- * Whether running within node or not.
2599
- * @memberof util
2600
- * @type {boolean}
2601
- */
2621
+ util.isNode = Boolean(typeof commonjsGlobal !== "undefined" && commonjsGlobal && commonjsGlobal.process && commonjsGlobal.process.versions && commonjsGlobal.process.versions.node);
2622
+ /**
2623
+ * Global object reference.
2624
+ * @memberof util
2625
+ * @type {Object}
2626
+ */
2602
2627
 
2603
- util.isNode = Boolean(typeof commonjsGlobal !== "undefined" && commonjsGlobal && commonjsGlobal.process && commonjsGlobal.process.versions && commonjsGlobal.process.versions.node);
2604
- /**
2605
- * Global object reference.
2606
- * @memberof util
2607
- * @type {Object}
2608
- */
2628
+ util.global = util.isNode && commonjsGlobal || typeof window !== "undefined" && window || typeof self !== "undefined" && self || commonjsGlobal; // eslint-disable-line no-invalid-this
2609
2629
 
2610
- util.global = util.isNode && commonjsGlobal || typeof window !== "undefined" && window || typeof self !== "undefined" && self || commonjsGlobal; // eslint-disable-line no-invalid-this
2630
+ /**
2631
+ * An immuable empty array.
2632
+ * @memberof util
2633
+ * @type {Array.<*>}
2634
+ * @const
2635
+ */
2611
2636
 
2612
- /**
2613
- * An immuable empty array.
2614
- * @memberof util
2615
- * @type {Array.<*>}
2616
- * @const
2617
- */
2637
+ util.emptyArray = Object.freeze ? Object.freeze([]) :
2638
+ /* istanbul ignore next */
2639
+ []; // used on prototypes
2618
2640
 
2619
- util.emptyArray = Object.freeze ? Object.freeze([]) :
2620
- /* istanbul ignore next */
2621
- []; // used on prototypes
2641
+ /**
2642
+ * An immutable empty object.
2643
+ * @type {Object}
2644
+ * @const
2645
+ */
2622
2646
 
2623
- /**
2624
- * An immutable empty object.
2625
- * @type {Object}
2626
- * @const
2627
- */
2647
+ util.emptyObject = Object.freeze ? Object.freeze({}) :
2648
+ /* istanbul ignore next */
2649
+ {}; // used on prototypes
2628
2650
 
2629
- util.emptyObject = Object.freeze ? Object.freeze({}) :
2630
- /* istanbul ignore next */
2631
- {}; // used on prototypes
2651
+ /**
2652
+ * Tests if the specified value is an integer.
2653
+ * @function
2654
+ * @param {*} value Value to test
2655
+ * @returns {boolean} `true` if the value is an integer
2656
+ */
2632
2657
 
2633
- /**
2634
- * Tests if the specified value is an integer.
2635
- * @function
2636
- * @param {*} value Value to test
2637
- * @returns {boolean} `true` if the value is an integer
2638
- */
2658
+ util.isInteger = Number.isInteger ||
2659
+ /* istanbul ignore next */
2660
+ function isInteger(value) {
2661
+ return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
2662
+ };
2663
+ /**
2664
+ * Tests if the specified value is a string.
2665
+ * @param {*} value Value to test
2666
+ * @returns {boolean} `true` if the value is a string
2667
+ */
2639
2668
 
2640
- util.isInteger = Number.isInteger ||
2641
- /* istanbul ignore next */
2642
- function isInteger(value) {
2643
- return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
2644
- };
2645
- /**
2646
- * Tests if the specified value is a string.
2647
- * @param {*} value Value to test
2648
- * @returns {boolean} `true` if the value is a string
2649
- */
2650
2669
 
2670
+ util.isString = function isString(value) {
2671
+ return typeof value === "string" || value instanceof String;
2672
+ };
2673
+ /**
2674
+ * Tests if the specified value is a non-null object.
2675
+ * @param {*} value Value to test
2676
+ * @returns {boolean} `true` if the value is a non-null object
2677
+ */
2651
2678
 
2652
- util.isString = function isString(value) {
2653
- return typeof value === "string" || value instanceof String;
2654
- };
2655
- /**
2656
- * Tests if the specified value is a non-null object.
2657
- * @param {*} value Value to test
2658
- * @returns {boolean} `true` if the value is a non-null object
2659
- */
2660
2679
 
2680
+ util.isObject = function isObject(value) {
2681
+ return value && typeof value === "object";
2682
+ };
2683
+ /**
2684
+ * Checks if a property on a message is considered to be present.
2685
+ * This is an alias of {@link util.isSet}.
2686
+ * @function
2687
+ * @param {Object} obj Plain object or message instance
2688
+ * @param {string} prop Property name
2689
+ * @returns {boolean} `true` if considered to be present, otherwise `false`
2690
+ */
2661
2691
 
2662
- util.isObject = function isObject(value) {
2663
- return value && typeof value === "object";
2664
- };
2665
- /**
2666
- * Checks if a property on a message is considered to be present.
2667
- * This is an alias of {@link util.isSet}.
2668
- * @function
2669
- * @param {Object} obj Plain object or message instance
2670
- * @param {string} prop Property name
2671
- * @returns {boolean} `true` if considered to be present, otherwise `false`
2672
- */
2673
2692
 
2693
+ util.isset =
2694
+ /**
2695
+ * Checks if a property on a message is considered to be present.
2696
+ * @param {Object} obj Plain object or message instance
2697
+ * @param {string} prop Property name
2698
+ * @returns {boolean} `true` if considered to be present, otherwise `false`
2699
+ */
2700
+ util.isSet = function isSet(obj, prop) {
2701
+ var value = obj[prop];
2702
+ if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins
2703
+ return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
2704
+ return false;
2705
+ };
2706
+ /**
2707
+ * Any compatible Buffer instance.
2708
+ * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
2709
+ * @interface Buffer
2710
+ * @extends Uint8Array
2711
+ */
2674
2712
 
2675
- util.isset =
2676
- /**
2677
- * Checks if a property on a message is considered to be present.
2678
- * @param {Object} obj Plain object or message instance
2679
- * @param {string} prop Property name
2680
- * @returns {boolean} `true` if considered to be present, otherwise `false`
2681
- */
2682
- util.isSet = function isSet(obj, prop) {
2683
- var value = obj[prop];
2684
- if (value != null && obj.hasOwnProperty(prop)) // eslint-disable-line eqeqeq, no-prototype-builtins
2685
- return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
2686
- return false;
2687
- };
2688
- /**
2689
- * Any compatible Buffer instance.
2690
- * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
2691
- * @interface Buffer
2692
- * @extends Uint8Array
2693
- */
2713
+ /**
2714
+ * Node's Buffer class if available.
2715
+ * @type {Constructor<Buffer>}
2716
+ */
2694
2717
 
2695
- /**
2696
- * Node's Buffer class if available.
2697
- * @type {Constructor<Buffer>}
2698
- */
2699
2718
 
2719
+ util.Buffer = function () {
2720
+ try {
2721
+ var Buffer = util.inquire("buffer").Buffer; // refuse to use non-node buffers if not explicitly assigned (perf reasons):
2700
2722
 
2701
- util.Buffer = function () {
2702
- try {
2703
- var Buffer = util.inquire("buffer").Buffer; // refuse to use non-node buffers if not explicitly assigned (perf reasons):
2723
+ return Buffer.prototype.utf8Write ? Buffer :
2724
+ /* istanbul ignore next */
2725
+ null;
2726
+ } catch (e) {
2727
+ /* istanbul ignore next */
2728
+ return null;
2729
+ }
2730
+ }(); // Internal alias of or polyfull for Buffer.from.
2704
2731
 
2705
- return Buffer.prototype.utf8Write ? Buffer :
2706
- /* istanbul ignore next */
2707
- null;
2708
- } catch (e) {
2732
+
2733
+ util._Buffer_from = null; // Internal alias of or polyfill for Buffer.allocUnsafe.
2734
+
2735
+ util._Buffer_allocUnsafe = null;
2736
+ /**
2737
+ * Creates a new buffer of whatever type supported by the environment.
2738
+ * @param {number|number[]} [sizeOrArray=0] Buffer size or number array
2739
+ * @returns {Uint8Array|Buffer} Buffer
2740
+ */
2741
+
2742
+ util.newBuffer = function newBuffer(sizeOrArray) {
2709
2743
  /* istanbul ignore next */
2710
- return null;
2711
- }
2712
- }(); // Internal alias of or polyfull for Buffer.from.
2744
+ return typeof sizeOrArray === "number" ? util.Buffer ? util._Buffer_allocUnsafe(sizeOrArray) : new util.Array(sizeOrArray) : util.Buffer ? util._Buffer_from(sizeOrArray) : typeof Uint8Array === "undefined" ? sizeOrArray : new Uint8Array(sizeOrArray);
2745
+ };
2746
+ /**
2747
+ * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
2748
+ * @type {Constructor<Uint8Array>}
2749
+ */
2713
2750
 
2714
2751
 
2715
- util._Buffer_from = null; // Internal alias of or polyfill for Buffer.allocUnsafe.
2752
+ util.Array = typeof Uint8Array !== "undefined" ? Uint8Array
2753
+ /* istanbul ignore next */
2754
+ : Array;
2755
+ /**
2756
+ * Any compatible Long instance.
2757
+ * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.
2758
+ * @interface Long
2759
+ * @property {number} low Low bits
2760
+ * @property {number} high High bits
2761
+ * @property {boolean} unsigned Whether unsigned or not
2762
+ */
2716
2763
 
2717
- util._Buffer_allocUnsafe = null;
2718
- /**
2719
- * Creates a new buffer of whatever type supported by the environment.
2720
- * @param {number|number[]} [sizeOrArray=0] Buffer size or number array
2721
- * @returns {Uint8Array|Buffer} Buffer
2722
- */
2764
+ /**
2765
+ * Long.js's Long class if available.
2766
+ * @type {Constructor<Long>}
2767
+ */
2723
2768
 
2724
- util.newBuffer = function newBuffer(sizeOrArray) {
2769
+ util.Long =
2725
2770
  /* istanbul ignore next */
2726
- return typeof sizeOrArray === "number" ? util.Buffer ? util._Buffer_allocUnsafe(sizeOrArray) : new util.Array(sizeOrArray) : util.Buffer ? util._Buffer_from(sizeOrArray) : typeof Uint8Array === "undefined" ? sizeOrArray : new Uint8Array(sizeOrArray);
2727
- };
2728
- /**
2729
- * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
2730
- * @type {Constructor<Uint8Array>}
2731
- */
2771
+ util.global.dcodeIO &&
2772
+ /* istanbul ignore next */
2773
+ util.global.dcodeIO.Long ||
2774
+ /* istanbul ignore next */
2775
+ util.global.Long || util.inquire("long");
2776
+ /**
2777
+ * Regular expression used to verify 2 bit (`bool`) map keys.
2778
+ * @type {RegExp}
2779
+ * @const
2780
+ */
2732
2781
 
2782
+ util.key2Re = /^true|false|0|1$/;
2783
+ /**
2784
+ * Regular expression used to verify 32 bit (`int32` etc.) map keys.
2785
+ * @type {RegExp}
2786
+ * @const
2787
+ */
2733
2788
 
2734
- util.Array = typeof Uint8Array !== "undefined" ? Uint8Array
2735
- /* istanbul ignore next */
2736
- : Array;
2737
- /**
2738
- * Any compatible Long instance.
2739
- * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.
2740
- * @interface Long
2741
- * @property {number} low Low bits
2742
- * @property {number} high High bits
2743
- * @property {boolean} unsigned Whether unsigned or not
2744
- */
2789
+ util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
2790
+ /**
2791
+ * Regular expression used to verify 64 bit (`int64` etc.) map keys.
2792
+ * @type {RegExp}
2793
+ * @const
2794
+ */
2745
2795
 
2746
- /**
2747
- * Long.js's Long class if available.
2748
- * @type {Constructor<Long>}
2749
- */
2796
+ util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
2797
+ /**
2798
+ * Converts a number or long to an 8 characters long hash string.
2799
+ * @param {Long|number} value Value to convert
2800
+ * @returns {string} Hash
2801
+ */
2750
2802
 
2751
- util.Long =
2752
- /* istanbul ignore next */
2753
- util.global.dcodeIO &&
2754
- /* istanbul ignore next */
2755
- util.global.dcodeIO.Long ||
2756
- /* istanbul ignore next */
2757
- util.global.Long || util.inquire("long");
2758
- /**
2759
- * Regular expression used to verify 2 bit (`bool`) map keys.
2760
- * @type {RegExp}
2761
- * @const
2762
- */
2803
+ util.longToHash = function longToHash(value) {
2804
+ return value ? util.LongBits.from(value).toHash() : util.LongBits.zeroHash;
2805
+ };
2806
+ /**
2807
+ * Converts an 8 characters long hash string to a long or number.
2808
+ * @param {string} hash Hash
2809
+ * @param {boolean} [unsigned=false] Whether unsigned or not
2810
+ * @returns {Long|number} Original value
2811
+ */
2763
2812
 
2764
- util.key2Re = /^true|false|0|1$/;
2765
- /**
2766
- * Regular expression used to verify 32 bit (`int32` etc.) map keys.
2767
- * @type {RegExp}
2768
- * @const
2769
- */
2770
2813
 
2771
- util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
2772
- /**
2773
- * Regular expression used to verify 64 bit (`int64` etc.) map keys.
2774
- * @type {RegExp}
2775
- * @const
2776
- */
2814
+ util.longFromHash = function longFromHash(hash, unsigned) {
2815
+ var bits = util.LongBits.fromHash(hash);
2816
+ if (util.Long) return util.Long.fromBits(bits.lo, bits.hi, unsigned);
2817
+ return bits.toNumber(Boolean(unsigned));
2818
+ };
2819
+ /**
2820
+ * Merges the properties of the source object into the destination object.
2821
+ * @memberof util
2822
+ * @param {Object.<string,*>} dst Destination object
2823
+ * @param {Object.<string,*>} src Source object
2824
+ * @param {boolean} [ifNotSet=false] Merges only if the key is not already set
2825
+ * @returns {Object.<string,*>} Destination object
2826
+ */
2777
2827
 
2778
- util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
2779
- /**
2780
- * Converts a number or long to an 8 characters long hash string.
2781
- * @param {Long|number} value Value to convert
2782
- * @returns {string} Hash
2783
- */
2784
2828
 
2785
- util.longToHash = function longToHash(value) {
2786
- return value ? util.LongBits.from(value).toHash() : util.LongBits.zeroHash;
2787
- };
2788
- /**
2789
- * Converts an 8 characters long hash string to a long or number.
2790
- * @param {string} hash Hash
2791
- * @param {boolean} [unsigned=false] Whether unsigned or not
2792
- * @returns {Long|number} Original value
2793
- */
2829
+ function merge(dst, src, ifNotSet) {
2830
+ // used by converters
2831
+ for (var keys = Object.keys(src), i = 0; i < keys.length; ++i) if (dst[keys[i]] === undefined || !ifNotSet) dst[keys[i]] = src[keys[i]];
2794
2832
 
2833
+ return dst;
2834
+ }
2795
2835
 
2796
- util.longFromHash = function longFromHash(hash, unsigned) {
2797
- var bits = util.LongBits.fromHash(hash);
2798
- if (util.Long) return util.Long.fromBits(bits.lo, bits.hi, unsigned);
2799
- return bits.toNumber(Boolean(unsigned));
2800
- };
2801
- /**
2802
- * Merges the properties of the source object into the destination object.
2803
- * @memberof util
2804
- * @param {Object.<string,*>} dst Destination object
2805
- * @param {Object.<string,*>} src Source object
2806
- * @param {boolean} [ifNotSet=false] Merges only if the key is not already set
2807
- * @returns {Object.<string,*>} Destination object
2808
- */
2836
+ util.merge = merge;
2837
+ /**
2838
+ * Converts the first character of a string to lower case.
2839
+ * @param {string} str String to convert
2840
+ * @returns {string} Converted string
2841
+ */
2809
2842
 
2843
+ util.lcFirst = function lcFirst(str) {
2844
+ return str.charAt(0).toLowerCase() + str.substring(1);
2845
+ };
2846
+ /**
2847
+ * Creates a custom error constructor.
2848
+ * @memberof util
2849
+ * @param {string} name Error name
2850
+ * @returns {Constructor<Error>} Custom error constructor
2851
+ */
2810
2852
 
2811
- function merge(dst, src, ifNotSet) {
2812
- // used by converters
2813
- for (var keys = Object.keys(src), i = 0; i < keys.length; ++i) if (dst[keys[i]] === undefined || !ifNotSet) dst[keys[i]] = src[keys[i]];
2814
2853
 
2815
- return dst;
2816
- }
2854
+ function newError(name) {
2855
+ function CustomError(message, properties) {
2856
+ if (!(this instanceof CustomError)) return new CustomError(message, properties); // Error.call(this, message);
2857
+ // ^ just returns a new error instance because the ctor can be called as a function
2817
2858
 
2818
- util.merge = merge;
2819
- /**
2820
- * Converts the first character of a string to lower case.
2821
- * @param {string} str String to convert
2822
- * @returns {string} Converted string
2823
- */
2859
+ Object.defineProperty(this, "message", {
2860
+ get: function () {
2861
+ return message;
2862
+ }
2863
+ });
2864
+ /* istanbul ignore next */
2824
2865
 
2825
- util.lcFirst = function lcFirst(str) {
2826
- return str.charAt(0).toLowerCase() + str.substring(1);
2827
- };
2828
- /**
2829
- * Creates a custom error constructor.
2830
- * @memberof util
2831
- * @param {string} name Error name
2832
- * @returns {Constructor<Error>} Custom error constructor
2833
- */
2866
+ if (Error.captureStackTrace) // node
2867
+ Error.captureStackTrace(this, CustomError);else Object.defineProperty(this, "stack", {
2868
+ value: new Error().stack || ""
2869
+ });
2870
+ if (properties) merge(this, properties);
2871
+ }
2834
2872
 
2873
+ CustomError.prototype = Object.create(Error.prototype, {
2874
+ constructor: {
2875
+ value: CustomError,
2876
+ writable: true,
2877
+ enumerable: false,
2878
+ configurable: true
2879
+ },
2880
+ name: {
2881
+ get() {
2882
+ return name;
2883
+ },
2835
2884
 
2836
- function newError(name) {
2837
- function CustomError(message, properties) {
2838
- if (!(this instanceof CustomError)) return new CustomError(message, properties); // Error.call(this, message);
2839
- // ^ just returns a new error instance because the ctor can be called as a function
2885
+ set: undefined,
2886
+ enumerable: false,
2887
+ // configurable: false would accurately preserve the behavior of
2888
+ // the original, but I'm guessing that was not intentional.
2889
+ // For an actual error subclass, this property would
2890
+ // be configurable.
2891
+ configurable: true
2892
+ },
2893
+ toString: {
2894
+ value() {
2895
+ return this.name + ": " + this.message;
2896
+ },
2840
2897
 
2841
- Object.defineProperty(this, "message", {
2842
- get: function () {
2843
- return message;
2898
+ writable: true,
2899
+ enumerable: false,
2900
+ configurable: true
2844
2901
  }
2845
2902
  });
2846
- /* istanbul ignore next */
2847
-
2848
- if (Error.captureStackTrace) // node
2849
- Error.captureStackTrace(this, CustomError);else Object.defineProperty(this, "stack", {
2850
- value: new Error().stack || ""
2851
- });
2852
- if (properties) merge(this, properties);
2903
+ return CustomError;
2853
2904
  }
2854
2905
 
2855
- (CustomError.prototype = Object.create(Error.prototype)).constructor = CustomError;
2856
- Object.defineProperty(CustomError.prototype, "name", {
2857
- get: function () {
2858
- return name;
2859
- }
2860
- });
2906
+ util.newError = newError;
2907
+ /**
2908
+ * Constructs a new protocol error.
2909
+ * @classdesc Error subclass indicating a protocol specifc error.
2910
+ * @memberof util
2911
+ * @extends Error
2912
+ * @template T extends Message<T>
2913
+ * @constructor
2914
+ * @param {string} message Error message
2915
+ * @param {Object.<string,*>} [properties] Additional properties
2916
+ * @example
2917
+ * try {
2918
+ * MyMessage.decode(someBuffer); // throws if required fields are missing
2919
+ * } catch (e) {
2920
+ * if (e instanceof ProtocolError && e.instance)
2921
+ * console.log("decoded so far: " + JSON.stringify(e.instance));
2922
+ * }
2923
+ */
2861
2924
 
2862
- CustomError.prototype.toString = function toString() {
2863
- return this.name + ": " + this.message;
2864
- };
2925
+ util.ProtocolError = newError("ProtocolError");
2926
+ /**
2927
+ * So far decoded message instance.
2928
+ * @name util.ProtocolError#instance
2929
+ * @type {Message<T>}
2930
+ */
2865
2931
 
2866
- return CustomError;
2867
- }
2932
+ /**
2933
+ * A OneOf getter as returned by {@link util.oneOfGetter}.
2934
+ * @typedef OneOfGetter
2935
+ * @type {function}
2936
+ * @returns {string|undefined} Set field name, if any
2937
+ */
2868
2938
 
2869
- util.newError = newError;
2870
- /**
2871
- * Constructs a new protocol error.
2872
- * @classdesc Error subclass indicating a protocol specifc error.
2873
- * @memberof util
2874
- * @extends Error
2875
- * @template T extends Message<T>
2876
- * @constructor
2877
- * @param {string} message Error message
2878
- * @param {Object.<string,*>} [properties] Additional properties
2879
- * @example
2880
- * try {
2881
- * MyMessage.decode(someBuffer); // throws if required fields are missing
2882
- * } catch (e) {
2883
- * if (e instanceof ProtocolError && e.instance)
2884
- * console.log("decoded so far: " + JSON.stringify(e.instance));
2885
- * }
2886
- */
2939
+ /**
2940
+ * Builds a getter for a oneof's present field name.
2941
+ * @param {string[]} fieldNames Field names
2942
+ * @returns {OneOfGetter} Unbound getter
2943
+ */
2887
2944
 
2888
- util.ProtocolError = newError("ProtocolError");
2889
- /**
2890
- * So far decoded message instance.
2891
- * @name util.ProtocolError#instance
2892
- * @type {Message<T>}
2893
- */
2945
+ util.oneOfGetter = function getOneOf(fieldNames) {
2946
+ var fieldMap = {};
2894
2947
 
2895
- /**
2896
- * A OneOf getter as returned by {@link util.oneOfGetter}.
2897
- * @typedef OneOfGetter
2898
- * @type {function}
2899
- * @returns {string|undefined} Set field name, if any
2900
- */
2948
+ for (var i = 0; i < fieldNames.length; ++i) fieldMap[fieldNames[i]] = 1;
2949
+ /**
2950
+ * @returns {string|undefined} Set field name, if any
2951
+ * @this Object
2952
+ * @ignore
2953
+ */
2901
2954
 
2902
- /**
2903
- * Builds a getter for a oneof's present field name.
2904
- * @param {string[]} fieldNames Field names
2905
- * @returns {OneOfGetter} Unbound getter
2906
- */
2907
2955
 
2908
- util.oneOfGetter = function getOneOf(fieldNames) {
2909
- var fieldMap = {};
2956
+ return function () {
2957
+ // eslint-disable-line consistent-return
2958
+ for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i) if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null) return keys[i];
2959
+ };
2960
+ };
2961
+ /**
2962
+ * A OneOf setter as returned by {@link util.oneOfSetter}.
2963
+ * @typedef OneOfSetter
2964
+ * @type {function}
2965
+ * @param {string|undefined} value Field name
2966
+ * @returns {undefined}
2967
+ */
2910
2968
 
2911
- for (var i = 0; i < fieldNames.length; ++i) fieldMap[fieldNames[i]] = 1;
2912
2969
  /**
2913
- * @returns {string|undefined} Set field name, if any
2914
- * @this Object
2915
- * @ignore
2970
+ * Builds a setter for a oneof's present field name.
2971
+ * @param {string[]} fieldNames Field names
2972
+ * @returns {OneOfSetter} Unbound setter
2916
2973
  */
2917
2974
 
2918
2975
 
2919
- return function () {
2920
- // eslint-disable-line consistent-return
2921
- for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i) if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null) return keys[i];
2976
+ util.oneOfSetter = function setOneOf(fieldNames) {
2977
+ /**
2978
+ * @param {string} name Field name
2979
+ * @returns {undefined}
2980
+ * @this Object
2981
+ * @ignore
2982
+ */
2983
+ return function (name) {
2984
+ for (var i = 0; i < fieldNames.length; ++i) if (fieldNames[i] !== name) delete this[fieldNames[i]];
2985
+ };
2922
2986
  };
2923
- };
2924
- /**
2925
- * A OneOf setter as returned by {@link util.oneOfSetter}.
2926
- * @typedef OneOfSetter
2927
- * @type {function}
2928
- * @param {string|undefined} value Field name
2929
- * @returns {undefined}
2930
- */
2931
-
2932
- /**
2933
- * Builds a setter for a oneof's present field name.
2934
- * @param {string[]} fieldNames Field names
2935
- * @returns {OneOfSetter} Unbound setter
2936
- */
2937
-
2938
-
2939
- util.oneOfSetter = function setOneOf(fieldNames) {
2940
2987
  /**
2941
- * @param {string} name Field name
2942
- * @returns {undefined}
2943
- * @this Object
2944
- * @ignore
2988
+ * Default conversion options used for {@link Message#toJSON} implementations.
2989
+ *
2990
+ * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
2991
+ *
2992
+ * - Longs become strings
2993
+ * - Enums become string keys
2994
+ * - Bytes become base64 encoded strings
2995
+ * - (Sub-)Messages become plain objects
2996
+ * - Maps become plain objects with all string keys
2997
+ * - Repeated fields become arrays
2998
+ * - NaN and Infinity for float and double fields become strings
2999
+ *
3000
+ * @type {IConversionOptions}
3001
+ * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
2945
3002
  */
2946
- return function (name) {
2947
- for (var i = 0; i < fieldNames.length; ++i) if (fieldNames[i] !== name) delete this[fieldNames[i]];
2948
- };
2949
- };
2950
- /**
2951
- * Default conversion options used for {@link Message#toJSON} implementations.
2952
- *
2953
- * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
2954
- *
2955
- * - Longs become strings
2956
- * - Enums become string keys
2957
- * - Bytes become base64 encoded strings
2958
- * - (Sub-)Messages become plain objects
2959
- * - Maps become plain objects with all string keys
2960
- * - Repeated fields become arrays
2961
- * - NaN and Infinity for float and double fields become strings
2962
- *
2963
- * @type {IConversionOptions}
2964
- * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
2965
- */
2966
3003
 
2967
3004
 
2968
- util.toJSONOptions = {
2969
- longs: String,
2970
- enums: String,
2971
- bytes: String,
2972
- json: true
2973
- }; // Sets up buffer utility according to the environment (called in index-minimal)
3005
+ util.toJSONOptions = {
3006
+ longs: String,
3007
+ enums: String,
3008
+ bytes: String,
3009
+ json: true
3010
+ }; // Sets up buffer utility according to the environment (called in index-minimal)
2974
3011
 
2975
- util._configure = function () {
2976
- var Buffer = util.Buffer;
2977
- /* istanbul ignore if */
3012
+ util._configure = function () {
3013
+ var Buffer = util.Buffer;
3014
+ /* istanbul ignore if */
2978
3015
 
2979
- if (!Buffer) {
2980
- util._Buffer_from = util._Buffer_allocUnsafe = null;
2981
- return;
2982
- } // because node 4.x buffers are incompatible & immutable
2983
- // see: https://github.com/dcodeIO/protobuf.js/pull/665
3016
+ if (!Buffer) {
3017
+ util._Buffer_from = util._Buffer_allocUnsafe = null;
3018
+ return;
3019
+ } // because node 4.x buffers are incompatible & immutable
3020
+ // see: https://github.com/dcodeIO/protobuf.js/pull/665
2984
3021
 
2985
3022
 
2986
- util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
2987
- /* istanbul ignore next */
2988
- function Buffer_from(value, encoding) {
2989
- return new Buffer(value, encoding);
2990
- };
3023
+ util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
3024
+ /* istanbul ignore next */
3025
+ function Buffer_from(value, encoding) {
3026
+ return new Buffer(value, encoding);
3027
+ };
2991
3028
 
2992
- util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
2993
- /* istanbul ignore next */
2994
- function Buffer_allocUnsafe(size) {
2995
- return new Buffer(size);
3029
+ util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
3030
+ /* istanbul ignore next */
3031
+ function Buffer_allocUnsafe(size) {
3032
+ return new Buffer(size);
3033
+ };
2996
3034
  };
2997
- };
2998
- })(minimal$1);
3035
+ })(minimal);
3036
+
3037
+ return minimal;
3038
+ }
2999
3039
 
3000
- var writer = Writer$1;
3001
- var util$4 = minimal$1;
3040
+ var writer$2 = Writer$1;
3041
+ var util$4 = requireMinimal();
3002
3042
  var BufferWriter$1; // cyclic
3003
3043
 
3004
3044
  var LongBits$1 = util$4.LongBits,
@@ -3476,9 +3516,9 @@ Writer$1._configure = function (BufferWriter_) {
3476
3516
 
3477
3517
  var writer_buffer = BufferWriter; // extends Writer
3478
3518
 
3479
- var Writer = writer;
3519
+ var Writer = writer$2;
3480
3520
  (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
3481
- var util$3 = minimal$1;
3521
+ var util$3 = requireMinimal();
3482
3522
  /**
3483
3523
  * Constructs a new buffer writer instance.
3484
3524
  * @classdesc Wire format writer using node buffers.
@@ -3548,7 +3588,7 @@ BufferWriter.prototype.string = function write_string_buffer(value) {
3548
3588
  BufferWriter._configure();
3549
3589
 
3550
3590
  var reader = Reader$1;
3551
- var util$2 = minimal$1;
3591
+ var util$2 = requireMinimal();
3552
3592
  var BufferReader$1; // cyclic
3553
3593
 
3554
3594
  var LongBits = util$2.LongBits,
@@ -3961,7 +4001,7 @@ var reader_buffer = BufferReader; // extends Reader
3961
4001
 
3962
4002
  var Reader = reader;
3963
4003
  (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
3964
- var util$1 = minimal$1;
4004
+ var util$1 = requireMinimal();
3965
4005
  /**
3966
4006
  * Constructs a new buffer reader instance.
3967
4007
  * @classdesc Wire format reader using node buffers.
@@ -4006,7 +4046,7 @@ BufferReader._configure();
4006
4046
  var rpc = {};
4007
4047
 
4008
4048
  var service = Service;
4009
- var util = minimal$1; // Extends EventEmitter
4049
+ var util = requireMinimal(); // Extends EventEmitter
4010
4050
 
4011
4051
  (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
4012
4052
  /**
@@ -4193,12 +4233,12 @@ var roots = {};
4193
4233
 
4194
4234
  protobuf.build = "minimal"; // Serialization
4195
4235
 
4196
- protobuf.Writer = writer;
4236
+ protobuf.Writer = writer$2;
4197
4237
  protobuf.BufferWriter = writer_buffer;
4198
4238
  protobuf.Reader = reader;
4199
4239
  protobuf.BufferReader = reader_buffer; // Utility
4200
4240
 
4201
- protobuf.util = minimal$1;
4241
+ protobuf.util = requireMinimal();
4202
4242
  protobuf.rpc = rpc;
4203
4243
  protobuf.roots = roots;
4204
4244
  protobuf.configure = configure;
@@ -4221,7 +4261,10 @@ var roots = {};
4221
4261
  configure();
4222
4262
  })(indexMinimal);
4223
4263
 
4224
- var minimal = indexMinimal;
4264
+ (function (module) {
4265
+
4266
+ module.exports = indexMinimal;
4267
+ })(minimal$1);
4225
4268
 
4226
4269
  /* eslint-disable */
4227
4270
 
@@ -4233,10 +4276,10 @@ var globalThis$2 = (() => {
4233
4276
  throw 'Unable to locate global object';
4234
4277
  })();
4235
4278
 
4236
- if (minimal.util.Long !== long) {
4237
- minimal.util.Long = long;
4279
+ if (minimal$1.exports.util.Long !== long) {
4280
+ minimal$1.exports.util.Long = long;
4238
4281
 
4239
- minimal.configure();
4282
+ minimal$1.exports.configure();
4240
4283
  }
4241
4284
 
4242
4285
  /* eslint-disable */
@@ -4749,7 +4792,7 @@ function createBaseRoom() {
4749
4792
 
4750
4793
  const Room$1 = {
4751
4794
  encode(message) {
4752
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
4795
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
4753
4796
 
4754
4797
  if (message.sid !== '') {
4755
4798
  writer.uint32(10).string(message.sid);
@@ -4795,7 +4838,7 @@ const Room$1 = {
4795
4838
  },
4796
4839
 
4797
4840
  decode(input, length) {
4798
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
4841
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
4799
4842
  let end = length === undefined ? reader.len : reader.pos + length;
4800
4843
  const message = createBaseRoom();
4801
4844
 
@@ -4916,7 +4959,7 @@ function createBaseCodec() {
4916
4959
 
4917
4960
  const Codec = {
4918
4961
  encode(message) {
4919
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
4962
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
4920
4963
 
4921
4964
  if (message.mime !== '') {
4922
4965
  writer.uint32(10).string(message.mime);
@@ -4930,7 +4973,7 @@ const Codec = {
4930
4973
  },
4931
4974
 
4932
4975
  decode(input, length) {
4933
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
4976
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
4934
4977
  let end = length === undefined ? reader.len : reader.pos + length;
4935
4978
  const message = createBaseCodec();
4936
4979
 
@@ -4992,7 +5035,7 @@ function createBaseParticipantPermission() {
4992
5035
 
4993
5036
  const ParticipantPermission = {
4994
5037
  encode(message) {
4995
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
5038
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
4996
5039
 
4997
5040
  if (message.canSubscribe === true) {
4998
5041
  writer.uint32(8).bool(message.canSubscribe);
@@ -5018,7 +5061,7 @@ const ParticipantPermission = {
5018
5061
  },
5019
5062
 
5020
5063
  decode(input, length) {
5021
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
5064
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
5022
5065
  let end = length === undefined ? reader.len : reader.pos + length;
5023
5066
  const message = createBaseParticipantPermission();
5024
5067
 
@@ -5107,7 +5150,7 @@ function createBaseParticipantInfo() {
5107
5150
 
5108
5151
  const ParticipantInfo = {
5109
5152
  encode(message) {
5110
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
5153
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
5111
5154
 
5112
5155
  if (message.sid !== '') {
5113
5156
  writer.uint32(10).string(message.sid);
@@ -5157,7 +5200,7 @@ const ParticipantInfo = {
5157
5200
  },
5158
5201
 
5159
5202
  decode(input, length) {
5160
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
5203
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
5161
5204
  let end = length === undefined ? reader.len : reader.pos + length;
5162
5205
  const message = createBaseParticipantInfo();
5163
5206
 
@@ -5287,7 +5330,7 @@ function createBaseSimulcastCodecInfo() {
5287
5330
 
5288
5331
  const SimulcastCodecInfo = {
5289
5332
  encode(message) {
5290
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
5333
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
5291
5334
 
5292
5335
  if (message.mimeType !== '') {
5293
5336
  writer.uint32(10).string(message.mimeType);
@@ -5309,7 +5352,7 @@ const SimulcastCodecInfo = {
5309
5352
  },
5310
5353
 
5311
5354
  decode(input, length) {
5312
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
5355
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
5313
5356
  let end = length === undefined ? reader.len : reader.pos + length;
5314
5357
  const message = createBaseSimulcastCodecInfo();
5315
5358
 
@@ -5399,7 +5442,7 @@ function createBaseTrackInfo() {
5399
5442
 
5400
5443
  const TrackInfo = {
5401
5444
  encode(message) {
5402
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
5445
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
5403
5446
 
5404
5447
  if (message.sid !== '') {
5405
5448
  writer.uint32(10).string(message.sid);
@@ -5457,7 +5500,7 @@ const TrackInfo = {
5457
5500
  },
5458
5501
 
5459
5502
  decode(input, length) {
5460
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
5503
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
5461
5504
  let end = length === undefined ? reader.len : reader.pos + length;
5462
5505
  const message = createBaseTrackInfo();
5463
5506
 
@@ -5608,7 +5651,7 @@ function createBaseVideoLayer() {
5608
5651
 
5609
5652
  const VideoLayer = {
5610
5653
  encode(message) {
5611
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
5654
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
5612
5655
 
5613
5656
  if (message.quality !== 0) {
5614
5657
  writer.uint32(8).int32(message.quality);
@@ -5634,7 +5677,7 @@ const VideoLayer = {
5634
5677
  },
5635
5678
 
5636
5679
  decode(input, length) {
5637
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
5680
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
5638
5681
  let end = length === undefined ? reader.len : reader.pos + length;
5639
5682
  const message = createBaseVideoLayer();
5640
5683
 
@@ -5715,7 +5758,7 @@ function createBaseDataPacket() {
5715
5758
 
5716
5759
  const DataPacket = {
5717
5760
  encode(message) {
5718
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
5761
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
5719
5762
 
5720
5763
  if (message.kind !== 0) {
5721
5764
  writer.uint32(8).int32(message.kind);
@@ -5733,7 +5776,7 @@ const DataPacket = {
5733
5776
  },
5734
5777
 
5735
5778
  decode(input, length) {
5736
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
5779
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
5737
5780
  let end = length === undefined ? reader.len : reader.pos + length;
5738
5781
  const message = createBaseDataPacket();
5739
5782
 
@@ -5798,7 +5841,7 @@ function createBaseActiveSpeakerUpdate() {
5798
5841
 
5799
5842
  const ActiveSpeakerUpdate = {
5800
5843
  encode(message) {
5801
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
5844
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
5802
5845
 
5803
5846
  for (const v of message.speakers) {
5804
5847
  SpeakerInfo.encode(v, writer.uint32(10).fork()).ldelim();
@@ -5808,7 +5851,7 @@ const ActiveSpeakerUpdate = {
5808
5851
  },
5809
5852
 
5810
5853
  decode(input, length) {
5811
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
5854
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
5812
5855
  let end = length === undefined ? reader.len : reader.pos + length;
5813
5856
  const message = createBaseActiveSpeakerUpdate();
5814
5857
 
@@ -5867,7 +5910,7 @@ function createBaseSpeakerInfo() {
5867
5910
 
5868
5911
  const SpeakerInfo = {
5869
5912
  encode(message) {
5870
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
5913
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
5871
5914
 
5872
5915
  if (message.sid !== '') {
5873
5916
  writer.uint32(10).string(message.sid);
@@ -5885,7 +5928,7 @@ const SpeakerInfo = {
5885
5928
  },
5886
5929
 
5887
5930
  decode(input, length) {
5888
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
5931
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
5889
5932
  let end = length === undefined ? reader.len : reader.pos + length;
5890
5933
  const message = createBaseSpeakerInfo();
5891
5934
 
@@ -5952,7 +5995,7 @@ function createBaseUserPacket() {
5952
5995
 
5953
5996
  const UserPacket = {
5954
5997
  encode(message) {
5955
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
5998
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
5956
5999
 
5957
6000
  if (message.participantSid !== '') {
5958
6001
  writer.uint32(10).string(message.participantSid);
@@ -5970,7 +6013,7 @@ const UserPacket = {
5970
6013
  },
5971
6014
 
5972
6015
  decode(input, length) {
5973
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
6016
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
5974
6017
  let end = length === undefined ? reader.len : reader.pos + length;
5975
6018
  const message = createBaseUserPacket();
5976
6019
 
@@ -6042,7 +6085,7 @@ function createBaseParticipantTracks() {
6042
6085
 
6043
6086
  const ParticipantTracks = {
6044
6087
  encode(message) {
6045
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
6088
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
6046
6089
 
6047
6090
  if (message.participantSid !== '') {
6048
6091
  writer.uint32(10).string(message.participantSid);
@@ -6056,7 +6099,7 @@ const ParticipantTracks = {
6056
6099
  },
6057
6100
 
6058
6101
  decode(input, length) {
6059
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
6102
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
6060
6103
  let end = length === undefined ? reader.len : reader.pos + length;
6061
6104
  const message = createBaseParticipantTracks();
6062
6105
 
@@ -6128,7 +6171,7 @@ function createBaseClientInfo() {
6128
6171
 
6129
6172
  const ClientInfo = {
6130
6173
  encode(message) {
6131
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
6174
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
6132
6175
 
6133
6176
  if (message.sdk !== 0) {
6134
6177
  writer.uint32(8).int32(message.sdk);
@@ -6170,7 +6213,7 @@ const ClientInfo = {
6170
6213
  },
6171
6214
 
6172
6215
  decode(input, length) {
6173
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
6216
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
6174
6217
  let end = length === undefined ? reader.len : reader.pos + length;
6175
6218
  const message = createBaseClientInfo();
6176
6219
 
@@ -6280,7 +6323,7 @@ function createBaseClientConfiguration() {
6280
6323
 
6281
6324
  const ClientConfiguration = {
6282
6325
  encode(message) {
6283
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
6326
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
6284
6327
 
6285
6328
  if (message.video !== undefined) {
6286
6329
  VideoConfiguration.encode(message.video, writer.uint32(10).fork()).ldelim();
@@ -6302,7 +6345,7 @@ const ClientConfiguration = {
6302
6345
  },
6303
6346
 
6304
6347
  decode(input, length) {
6305
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
6348
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
6306
6349
  let end = length === undefined ? reader.len : reader.pos + length;
6307
6350
  const message = createBaseClientConfiguration();
6308
6351
 
@@ -6374,7 +6417,7 @@ function createBaseVideoConfiguration() {
6374
6417
 
6375
6418
  const VideoConfiguration = {
6376
6419
  encode(message) {
6377
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
6420
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
6378
6421
 
6379
6422
  if (message.hardwareEncoder !== 0) {
6380
6423
  writer.uint32(8).int32(message.hardwareEncoder);
@@ -6384,7 +6427,7 @@ const VideoConfiguration = {
6384
6427
  },
6385
6428
 
6386
6429
  decode(input, length) {
6387
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
6430
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
6388
6431
  let end = length === undefined ? reader.len : reader.pos + length;
6389
6432
  const message = createBaseVideoConfiguration();
6390
6433
 
@@ -6435,7 +6478,7 @@ function createBaseDisabledCodecs() {
6435
6478
 
6436
6479
  const DisabledCodecs = {
6437
6480
  encode(message) {
6438
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
6481
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
6439
6482
 
6440
6483
  for (const v of message.codecs) {
6441
6484
  Codec.encode(v, writer.uint32(10).fork()).ldelim();
@@ -6445,7 +6488,7 @@ const DisabledCodecs = {
6445
6488
  },
6446
6489
 
6447
6490
  decode(input, length) {
6448
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
6491
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
6449
6492
  let end = length === undefined ? reader.len : reader.pos + length;
6450
6493
  const message = createBaseDisabledCodecs();
6451
6494
 
@@ -6535,16 +6578,65 @@ function longToNumber(long) {
6535
6578
  return long.toNumber();
6536
6579
  }
6537
6580
 
6538
- if (minimal.util.Long !== long) {
6539
- minimal.util.Long = long;
6581
+ if (minimal$1.exports.util.Long !== long) {
6582
+ minimal$1.exports.util.Long = long;
6540
6583
 
6541
- minimal.configure();
6584
+ minimal$1.exports.configure();
6542
6585
  }
6543
6586
 
6544
6587
  function isSet$1(value) {
6545
6588
  return value !== null && value !== undefined;
6546
6589
  }
6547
6590
 
6591
+ function _asyncIterator(iterable) {
6592
+ var method,
6593
+ async,
6594
+ sync,
6595
+ retry = 2;
6596
+
6597
+ for ("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;) {
6598
+ if (async && null != (method = iterable[async])) return method.call(iterable);
6599
+ if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable));
6600
+ async = "@@asyncIterator", sync = "@@iterator";
6601
+ }
6602
+
6603
+ throw new TypeError("Object is not async iterable");
6604
+ }
6605
+
6606
+ function AsyncFromSyncIterator(s) {
6607
+ function AsyncFromSyncIteratorContinuation(r) {
6608
+ if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
6609
+ var done = r.done;
6610
+ return Promise.resolve(r.value).then(function (value) {
6611
+ return {
6612
+ value: value,
6613
+ done: done
6614
+ };
6615
+ });
6616
+ }
6617
+
6618
+ return AsyncFromSyncIterator = function (s) {
6619
+ this.s = s, this.n = s.next;
6620
+ }, AsyncFromSyncIterator.prototype = {
6621
+ s: null,
6622
+ n: null,
6623
+ next: function () {
6624
+ return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
6625
+ },
6626
+ return: function (value) {
6627
+ var ret = this.s.return;
6628
+ return void 0 === ret ? Promise.resolve({
6629
+ value: value,
6630
+ done: !0
6631
+ }) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments));
6632
+ },
6633
+ throw: function (value) {
6634
+ var thr = this.s.return;
6635
+ return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments));
6636
+ }
6637
+ }, new AsyncFromSyncIterator(s);
6638
+ }
6639
+
6548
6640
  function ownKeys(object, enumerableOnly) {
6549
6641
  var keys = Object.keys(object);
6550
6642
 
@@ -6715,7 +6807,7 @@ function createBaseSignalRequest() {
6715
6807
 
6716
6808
  const SignalRequest = {
6717
6809
  encode(message) {
6718
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
6810
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
6719
6811
 
6720
6812
  if (message.offer !== undefined) {
6721
6813
  SessionDescription.encode(message.offer, writer.uint32(10).fork()).ldelim();
@@ -6769,7 +6861,7 @@ const SignalRequest = {
6769
6861
  },
6770
6862
 
6771
6863
  decode(input, length) {
6772
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
6864
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
6773
6865
  let end = length === undefined ? reader.len : reader.pos + length;
6774
6866
  const message = createBaseSignalRequest();
6775
6867
 
@@ -6910,7 +7002,7 @@ function createBaseSignalResponse() {
6910
7002
 
6911
7003
  const SignalResponse = {
6912
7004
  encode(message) {
6913
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
7005
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
6914
7006
 
6915
7007
  if (message.join !== undefined) {
6916
7008
  JoinResponse.encode(message.join, writer.uint32(10).fork()).ldelim();
@@ -6980,7 +7072,7 @@ const SignalResponse = {
6980
7072
  },
6981
7073
 
6982
7074
  decode(input, length) {
6983
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
7075
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
6984
7076
  let end = length === undefined ? reader.len : reader.pos + length;
6985
7077
  const message = createBaseSignalResponse();
6986
7078
 
@@ -7138,7 +7230,7 @@ function createBaseSimulcastCodec() {
7138
7230
 
7139
7231
  const SimulcastCodec = {
7140
7232
  encode(message) {
7141
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
7233
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
7142
7234
 
7143
7235
  if (message.codec !== '') {
7144
7236
  writer.uint32(10).string(message.codec);
@@ -7156,7 +7248,7 @@ const SimulcastCodec = {
7156
7248
  },
7157
7249
 
7158
7250
  decode(input, length) {
7159
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
7251
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
7160
7252
  let end = length === undefined ? reader.len : reader.pos + length;
7161
7253
  const message = createBaseSimulcastCodec();
7162
7254
 
@@ -7231,7 +7323,7 @@ function createBaseAddTrackRequest() {
7231
7323
 
7232
7324
  const AddTrackRequest = {
7233
7325
  encode(message) {
7234
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
7326
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
7235
7327
 
7236
7328
  if (message.cid !== '') {
7237
7329
  writer.uint32(10).string(message.cid);
@@ -7281,7 +7373,7 @@ const AddTrackRequest = {
7281
7373
  },
7282
7374
 
7283
7375
  decode(input, length) {
7284
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
7376
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
7285
7377
  let end = length === undefined ? reader.len : reader.pos + length;
7286
7378
  const message = createBaseAddTrackRequest();
7287
7379
 
@@ -7414,7 +7506,7 @@ function createBaseTrickleRequest() {
7414
7506
 
7415
7507
  const TrickleRequest = {
7416
7508
  encode(message) {
7417
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
7509
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
7418
7510
 
7419
7511
  if (message.candidateInit !== '') {
7420
7512
  writer.uint32(10).string(message.candidateInit);
@@ -7428,7 +7520,7 @@ const TrickleRequest = {
7428
7520
  },
7429
7521
 
7430
7522
  decode(input, length) {
7431
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
7523
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
7432
7524
  let end = length === undefined ? reader.len : reader.pos + length;
7433
7525
  const message = createBaseTrickleRequest();
7434
7526
 
@@ -7487,7 +7579,7 @@ function createBaseMuteTrackRequest() {
7487
7579
 
7488
7580
  const MuteTrackRequest = {
7489
7581
  encode(message) {
7490
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
7582
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
7491
7583
 
7492
7584
  if (message.sid !== '') {
7493
7585
  writer.uint32(10).string(message.sid);
@@ -7501,7 +7593,7 @@ const MuteTrackRequest = {
7501
7593
  },
7502
7594
 
7503
7595
  decode(input, length) {
7504
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
7596
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
7505
7597
  let end = length === undefined ? reader.len : reader.pos + length;
7506
7598
  const message = createBaseMuteTrackRequest();
7507
7599
 
@@ -7567,7 +7659,7 @@ function createBaseJoinResponse() {
7567
7659
 
7568
7660
  const JoinResponse = {
7569
7661
  encode(message) {
7570
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
7662
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
7571
7663
 
7572
7664
  if (message.room !== undefined) {
7573
7665
  Room$1.encode(message.room, writer.uint32(10).fork()).ldelim();
@@ -7609,7 +7701,7 @@ const JoinResponse = {
7609
7701
  },
7610
7702
 
7611
7703
  decode(input, length) {
7612
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
7704
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
7613
7705
  let end = length === undefined ? reader.len : reader.pos + length;
7614
7706
  const message = createBaseJoinResponse();
7615
7707
 
@@ -7729,7 +7821,7 @@ function createBaseTrackPublishedResponse() {
7729
7821
 
7730
7822
  const TrackPublishedResponse = {
7731
7823
  encode(message) {
7732
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
7824
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
7733
7825
 
7734
7826
  if (message.cid !== '') {
7735
7827
  writer.uint32(10).string(message.cid);
@@ -7743,7 +7835,7 @@ const TrackPublishedResponse = {
7743
7835
  },
7744
7836
 
7745
7837
  decode(input, length) {
7746
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
7838
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
7747
7839
  let end = length === undefined ? reader.len : reader.pos + length;
7748
7840
  const message = createBaseTrackPublishedResponse();
7749
7841
 
@@ -7801,7 +7893,7 @@ function createBaseTrackUnpublishedResponse() {
7801
7893
 
7802
7894
  const TrackUnpublishedResponse = {
7803
7895
  encode(message) {
7804
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
7896
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
7805
7897
 
7806
7898
  if (message.trackSid !== '') {
7807
7899
  writer.uint32(10).string(message.trackSid);
@@ -7811,7 +7903,7 @@ const TrackUnpublishedResponse = {
7811
7903
  },
7812
7904
 
7813
7905
  decode(input, length) {
7814
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
7906
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
7815
7907
  let end = length === undefined ? reader.len : reader.pos + length;
7816
7908
  const message = createBaseTrackUnpublishedResponse();
7817
7909
 
@@ -7863,7 +7955,7 @@ function createBaseSessionDescription() {
7863
7955
 
7864
7956
  const SessionDescription = {
7865
7957
  encode(message) {
7866
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
7958
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
7867
7959
 
7868
7960
  if (message.type !== '') {
7869
7961
  writer.uint32(10).string(message.type);
@@ -7877,7 +7969,7 @@ const SessionDescription = {
7877
7969
  },
7878
7970
 
7879
7971
  decode(input, length) {
7880
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
7972
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
7881
7973
  let end = length === undefined ? reader.len : reader.pos + length;
7882
7974
  const message = createBaseSessionDescription();
7883
7975
 
@@ -7935,7 +8027,7 @@ function createBaseParticipantUpdate() {
7935
8027
 
7936
8028
  const ParticipantUpdate = {
7937
8029
  encode(message) {
7938
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
8030
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
7939
8031
 
7940
8032
  for (const v of message.participants) {
7941
8033
  ParticipantInfo.encode(v, writer.uint32(10).fork()).ldelim();
@@ -7945,7 +8037,7 @@ const ParticipantUpdate = {
7945
8037
  },
7946
8038
 
7947
8039
  decode(input, length) {
7948
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
8040
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
7949
8041
  let end = length === undefined ? reader.len : reader.pos + length;
7950
8042
  const message = createBaseParticipantUpdate();
7951
8043
 
@@ -8004,7 +8096,7 @@ function createBaseUpdateSubscription() {
8004
8096
 
8005
8097
  const UpdateSubscription = {
8006
8098
  encode(message) {
8007
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
8099
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
8008
8100
 
8009
8101
  for (const v of message.trackSids) {
8010
8102
  writer.uint32(10).string(v);
@@ -8022,7 +8114,7 @@ const UpdateSubscription = {
8022
8114
  },
8023
8115
 
8024
8116
  decode(input, length) {
8025
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
8117
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
8026
8118
  let end = length === undefined ? reader.len : reader.pos + length;
8027
8119
  const message = createBaseUpdateSubscription();
8028
8120
 
@@ -8103,7 +8195,7 @@ function createBaseUpdateTrackSettings() {
8103
8195
 
8104
8196
  const UpdateTrackSettings = {
8105
8197
  encode(message) {
8106
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
8198
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
8107
8199
 
8108
8200
  for (const v of message.trackSids) {
8109
8201
  writer.uint32(10).string(v);
@@ -8129,7 +8221,7 @@ const UpdateTrackSettings = {
8129
8221
  },
8130
8222
 
8131
8223
  decode(input, length) {
8132
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
8224
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
8133
8225
  let end = length === undefined ? reader.len : reader.pos + length;
8134
8226
  const message = createBaseUpdateTrackSettings();
8135
8227
 
@@ -8215,7 +8307,7 @@ function createBaseLeaveRequest() {
8215
8307
 
8216
8308
  const LeaveRequest = {
8217
8309
  encode(message) {
8218
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
8310
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
8219
8311
 
8220
8312
  if (message.canReconnect === true) {
8221
8313
  writer.uint32(8).bool(message.canReconnect);
@@ -8229,7 +8321,7 @@ const LeaveRequest = {
8229
8321
  },
8230
8322
 
8231
8323
  decode(input, length) {
8232
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
8324
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
8233
8325
  let end = length === undefined ? reader.len : reader.pos + length;
8234
8326
  const message = createBaseLeaveRequest();
8235
8327
 
@@ -8288,7 +8380,7 @@ function createBaseUpdateVideoLayers() {
8288
8380
 
8289
8381
  const UpdateVideoLayers = {
8290
8382
  encode(message) {
8291
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
8383
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
8292
8384
 
8293
8385
  if (message.trackSid !== '') {
8294
8386
  writer.uint32(10).string(message.trackSid);
@@ -8302,7 +8394,7 @@ const UpdateVideoLayers = {
8302
8394
  },
8303
8395
 
8304
8396
  decode(input, length) {
8305
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
8397
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
8306
8398
  let end = length === undefined ? reader.len : reader.pos + length;
8307
8399
  const message = createBaseUpdateVideoLayers();
8308
8400
 
@@ -8368,7 +8460,7 @@ function createBaseICEServer() {
8368
8460
 
8369
8461
  const ICEServer = {
8370
8462
  encode(message) {
8371
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
8463
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
8372
8464
 
8373
8465
  for (const v of message.urls) {
8374
8466
  writer.uint32(10).string(v);
@@ -8386,7 +8478,7 @@ const ICEServer = {
8386
8478
  },
8387
8479
 
8388
8480
  decode(input, length) {
8389
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
8481
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
8390
8482
  let end = length === undefined ? reader.len : reader.pos + length;
8391
8483
  const message = createBaseICEServer();
8392
8484
 
@@ -8457,7 +8549,7 @@ function createBaseSpeakersChanged() {
8457
8549
 
8458
8550
  const SpeakersChanged = {
8459
8551
  encode(message) {
8460
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
8552
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
8461
8553
 
8462
8554
  for (const v of message.speakers) {
8463
8555
  SpeakerInfo.encode(v, writer.uint32(10).fork()).ldelim();
@@ -8467,7 +8559,7 @@ const SpeakersChanged = {
8467
8559
  },
8468
8560
 
8469
8561
  decode(input, length) {
8470
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
8562
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
8471
8563
  let end = length === undefined ? reader.len : reader.pos + length;
8472
8564
  const message = createBaseSpeakersChanged();
8473
8565
 
@@ -8524,7 +8616,7 @@ function createBaseRoomUpdate() {
8524
8616
 
8525
8617
  const RoomUpdate = {
8526
8618
  encode(message) {
8527
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
8619
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
8528
8620
 
8529
8621
  if (message.room !== undefined) {
8530
8622
  Room$1.encode(message.room, writer.uint32(10).fork()).ldelim();
@@ -8534,7 +8626,7 @@ const RoomUpdate = {
8534
8626
  },
8535
8627
 
8536
8628
  decode(input, length) {
8537
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
8629
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
8538
8630
  let end = length === undefined ? reader.len : reader.pos + length;
8539
8631
  const message = createBaseRoomUpdate();
8540
8632
 
@@ -8585,7 +8677,7 @@ function createBaseConnectionQualityInfo() {
8585
8677
 
8586
8678
  const ConnectionQualityInfo = {
8587
8679
  encode(message) {
8588
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
8680
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
8589
8681
 
8590
8682
  if (message.participantSid !== '') {
8591
8683
  writer.uint32(10).string(message.participantSid);
@@ -8603,7 +8695,7 @@ const ConnectionQualityInfo = {
8603
8695
  },
8604
8696
 
8605
8697
  decode(input, length) {
8606
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
8698
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
8607
8699
  let end = length === undefined ? reader.len : reader.pos + length;
8608
8700
  const message = createBaseConnectionQualityInfo();
8609
8701
 
@@ -8668,7 +8760,7 @@ function createBaseConnectionQualityUpdate() {
8668
8760
 
8669
8761
  const ConnectionQualityUpdate = {
8670
8762
  encode(message) {
8671
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
8763
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
8672
8764
 
8673
8765
  for (const v of message.updates) {
8674
8766
  ConnectionQualityInfo.encode(v, writer.uint32(10).fork()).ldelim();
@@ -8678,7 +8770,7 @@ const ConnectionQualityUpdate = {
8678
8770
  },
8679
8771
 
8680
8772
  decode(input, length) {
8681
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
8773
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
8682
8774
  let end = length === undefined ? reader.len : reader.pos + length;
8683
8775
  const message = createBaseConnectionQualityUpdate();
8684
8776
 
@@ -8737,7 +8829,7 @@ function createBaseStreamStateInfo() {
8737
8829
 
8738
8830
  const StreamStateInfo = {
8739
8831
  encode(message) {
8740
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
8832
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
8741
8833
 
8742
8834
  if (message.participantSid !== '') {
8743
8835
  writer.uint32(10).string(message.participantSid);
@@ -8755,7 +8847,7 @@ const StreamStateInfo = {
8755
8847
  },
8756
8848
 
8757
8849
  decode(input, length) {
8758
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
8850
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
8759
8851
  let end = length === undefined ? reader.len : reader.pos + length;
8760
8852
  const message = createBaseStreamStateInfo();
8761
8853
 
@@ -8820,7 +8912,7 @@ function createBaseStreamStateUpdate() {
8820
8912
 
8821
8913
  const StreamStateUpdate = {
8822
8914
  encode(message) {
8823
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
8915
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
8824
8916
 
8825
8917
  for (const v of message.streamStates) {
8826
8918
  StreamStateInfo.encode(v, writer.uint32(10).fork()).ldelim();
@@ -8830,7 +8922,7 @@ const StreamStateUpdate = {
8830
8922
  },
8831
8923
 
8832
8924
  decode(input, length) {
8833
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
8925
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
8834
8926
  let end = length === undefined ? reader.len : reader.pos + length;
8835
8927
  const message = createBaseStreamStateUpdate();
8836
8928
 
@@ -8888,7 +8980,7 @@ function createBaseSubscribedQuality() {
8888
8980
 
8889
8981
  const SubscribedQuality = {
8890
8982
  encode(message) {
8891
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
8983
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
8892
8984
 
8893
8985
  if (message.quality !== 0) {
8894
8986
  writer.uint32(8).int32(message.quality);
@@ -8902,7 +8994,7 @@ const SubscribedQuality = {
8902
8994
  },
8903
8995
 
8904
8996
  decode(input, length) {
8905
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
8997
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
8906
8998
  let end = length === undefined ? reader.len : reader.pos + length;
8907
8999
  const message = createBaseSubscribedQuality();
8908
9000
 
@@ -8961,7 +9053,7 @@ function createBaseSubscribedCodec() {
8961
9053
 
8962
9054
  const SubscribedCodec = {
8963
9055
  encode(message) {
8964
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
9056
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
8965
9057
 
8966
9058
  if (message.codec !== '') {
8967
9059
  writer.uint32(10).string(message.codec);
@@ -8975,7 +9067,7 @@ const SubscribedCodec = {
8975
9067
  },
8976
9068
 
8977
9069
  decode(input, length) {
8978
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
9070
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
8979
9071
  let end = length === undefined ? reader.len : reader.pos + length;
8980
9072
  const message = createBaseSubscribedCodec();
8981
9073
 
@@ -9041,7 +9133,7 @@ function createBaseSubscribedQualityUpdate() {
9041
9133
 
9042
9134
  const SubscribedQualityUpdate = {
9043
9135
  encode(message) {
9044
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
9136
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
9045
9137
 
9046
9138
  if (message.trackSid !== '') {
9047
9139
  writer.uint32(10).string(message.trackSid);
@@ -9059,7 +9151,7 @@ const SubscribedQualityUpdate = {
9059
9151
  },
9060
9152
 
9061
9153
  decode(input, length) {
9062
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
9154
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
9063
9155
  let end = length === undefined ? reader.len : reader.pos + length;
9064
9156
  const message = createBaseSubscribedQualityUpdate();
9065
9157
 
@@ -9138,7 +9230,7 @@ function createBaseTrackPermission() {
9138
9230
 
9139
9231
  const TrackPermission = {
9140
9232
  encode(message) {
9141
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
9233
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
9142
9234
 
9143
9235
  if (message.participantSid !== '') {
9144
9236
  writer.uint32(10).string(message.participantSid);
@@ -9160,7 +9252,7 @@ const TrackPermission = {
9160
9252
  },
9161
9253
 
9162
9254
  decode(input, length) {
9163
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
9255
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
9164
9256
  let end = length === undefined ? reader.len : reader.pos + length;
9165
9257
  const message = createBaseTrackPermission();
9166
9258
 
@@ -9239,7 +9331,7 @@ function createBaseSubscriptionPermission() {
9239
9331
 
9240
9332
  const SubscriptionPermission = {
9241
9333
  encode(message) {
9242
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
9334
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
9243
9335
 
9244
9336
  if (message.allParticipants === true) {
9245
9337
  writer.uint32(8).bool(message.allParticipants);
@@ -9253,7 +9345,7 @@ const SubscriptionPermission = {
9253
9345
  },
9254
9346
 
9255
9347
  decode(input, length) {
9256
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
9348
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
9257
9349
  let end = length === undefined ? reader.len : reader.pos + length;
9258
9350
  const message = createBaseSubscriptionPermission();
9259
9351
 
@@ -9319,7 +9411,7 @@ function createBaseSubscriptionPermissionUpdate() {
9319
9411
 
9320
9412
  const SubscriptionPermissionUpdate = {
9321
9413
  encode(message) {
9322
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
9414
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
9323
9415
 
9324
9416
  if (message.participantSid !== '') {
9325
9417
  writer.uint32(10).string(message.participantSid);
@@ -9337,7 +9429,7 @@ const SubscriptionPermissionUpdate = {
9337
9429
  },
9338
9430
 
9339
9431
  decode(input, length) {
9340
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
9432
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
9341
9433
  let end = length === undefined ? reader.len : reader.pos + length;
9342
9434
  const message = createBaseSubscriptionPermissionUpdate();
9343
9435
 
@@ -9405,7 +9497,7 @@ function createBaseSyncState() {
9405
9497
 
9406
9498
  const SyncState = {
9407
9499
  encode(message) {
9408
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
9500
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
9409
9501
 
9410
9502
  if (message.answer !== undefined) {
9411
9503
  SessionDescription.encode(message.answer, writer.uint32(10).fork()).ldelim();
@@ -9427,7 +9519,7 @@ const SyncState = {
9427
9519
  },
9428
9520
 
9429
9521
  decode(input, length) {
9430
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
9522
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
9431
9523
  let end = length === undefined ? reader.len : reader.pos + length;
9432
9524
  const message = createBaseSyncState();
9433
9525
 
@@ -9512,7 +9604,7 @@ function createBaseDataChannelInfo() {
9512
9604
 
9513
9605
  const DataChannelInfo = {
9514
9606
  encode(message) {
9515
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
9607
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
9516
9608
 
9517
9609
  if (message.label !== '') {
9518
9610
  writer.uint32(10).string(message.label);
@@ -9530,7 +9622,7 @@ const DataChannelInfo = {
9530
9622
  },
9531
9623
 
9532
9624
  decode(input, length) {
9533
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
9625
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
9534
9626
  let end = length === undefined ? reader.len : reader.pos + length;
9535
9627
  const message = createBaseDataChannelInfo();
9536
9628
 
@@ -9599,7 +9691,7 @@ function createBaseSimulateScenario() {
9599
9691
 
9600
9692
  const SimulateScenario = {
9601
9693
  encode(message) {
9602
- let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal.Writer.create();
9694
+ let writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : minimal$1.exports.Writer.create();
9603
9695
 
9604
9696
  if (message.speakerUpdate !== undefined) {
9605
9697
  writer.uint32(8).int32(message.speakerUpdate);
@@ -9625,7 +9717,7 @@ const SimulateScenario = {
9625
9717
  },
9626
9718
 
9627
9719
  decode(input, length) {
9628
- const reader = input instanceof minimal.Reader ? input : new minimal.Reader(input);
9720
+ const reader = input instanceof minimal$1.exports.Reader ? input : new minimal$1.exports.Reader(input);
9629
9721
  let end = length === undefined ? reader.len : reader.pos + length;
9630
9722
  const message = createBaseSimulateScenario();
9631
9723
 
@@ -9696,10 +9788,10 @@ const SimulateScenario = {
9696
9788
 
9697
9789
  };
9698
9790
 
9699
- if (minimal.util.Long !== long) {
9700
- minimal.util.Long = long;
9791
+ if (minimal$1.exports.util.Long !== long) {
9792
+ minimal$1.exports.util.Long = long;
9701
9793
 
9702
- minimal.configure();
9794
+ minimal$1.exports.configure();
9703
9795
  }
9704
9796
 
9705
9797
  function isSet(value) {
@@ -9997,8 +10089,8 @@ var RoomEvent;
9997
10089
  * When we have encountered an error while attempting to create a track.
9998
10090
  * The errors take place in getUserMedia().
9999
10091
  * Use MediaDeviceFailure.getFailure(error) to get the reason of failure.
10000
- * [[getAudioCreateError]] and [[getVideoCreateError]] will indicate if it had
10001
- * an error while creating the audio or video track respectively.
10092
+ * [[LocalParticipant.lastCameraError]] and [[LocalParticipant.lastMicrophoneError]]
10093
+ * will indicate if it had an error while creating the audio or video track respectively.
10002
10094
  *
10003
10095
  * args: (error: Error)
10004
10096
  */
@@ -10265,7 +10357,7 @@ function computeBitrate(currentStats, prevStats) {
10265
10357
  return (bytesNow - bytesPrev) * 8 * 1000 / (currentStats.timestamp - prevStats.timestamp);
10266
10358
  }
10267
10359
 
10268
- var version$1 = "1.2.2";
10360
+ var version$1 = "1.2.5";
10269
10361
 
10270
10362
  const version = version$1;
10271
10363
  const protocolVersion = 8;
@@ -10376,8 +10468,8 @@ function getEmptyAudioStreamTrack() {
10376
10468
  return emptyAudioStreamTrack;
10377
10469
  }
10378
10470
  class Future {
10379
- constructor() {
10380
- this.promise = new Promise((resolve, reject) => {
10471
+ constructor(promise) {
10472
+ this.promise = promise !== null && promise !== void 0 ? promise : new Promise((resolve, reject) => {
10381
10473
  this.resolve = resolve;
10382
10474
  this.reject = reject;
10383
10475
  });
@@ -10569,9 +10661,27 @@ class DeviceManager {
10569
10661
 
10570
10662
  async getDevices(kind) {
10571
10663
  let requestPermissions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
10664
+
10665
+ var _a;
10666
+
10667
+ if (((_a = DeviceManager.userMediaPromiseMap) === null || _a === void 0 ? void 0 : _a.size) > 0) {
10668
+ livekitLogger.debug('awaiting getUserMedia promise');
10669
+
10670
+ try {
10671
+ if (kind) {
10672
+ await DeviceManager.userMediaPromiseMap.get(kind);
10673
+ } else {
10674
+ await Promise.all(DeviceManager.userMediaPromiseMap.values());
10675
+ }
10676
+ } catch (e) {
10677
+ livekitLogger.warn('error waiting for media permissons');
10678
+ }
10679
+ }
10680
+
10572
10681
  let devices = await navigator.mediaDevices.enumerateDevices();
10573
10682
 
10574
- if (requestPermissions) {
10683
+ if (requestPermissions && kind && ( // for safari we need to skip this check, as otherwise it will re-acquire user media and fail on iOS https://bugs.webkit.org/show_bug.cgi?id=179363
10684
+ !DeviceManager.userMediaPromiseMap.get(kind) || !isSafari())) {
10575
10685
  const isDummyDeviceOrEmpty = devices.length === 0 || devices.some(device => {
10576
10686
  const noLabel = device.label === '';
10577
10687
  const isRelevant = kind ? device.kind === kind : true;
@@ -10631,6 +10741,7 @@ class DeviceManager {
10631
10741
 
10632
10742
  }
10633
10743
  DeviceManager.mediaDeviceKinds = ['audioinput', 'audiooutput', 'videoinput'];
10744
+ DeviceManager.userMediaPromiseMap = new Map();
10634
10745
 
10635
10746
  var events = {exports: {}};
10636
10747
 
@@ -11944,6 +12055,8 @@ class LocalVideoTrack extends LocalTrack {
11944
12055
  constructor(mediaTrack, constraints) {
11945
12056
  let userProvidedTrack = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
11946
12057
  super(mediaTrack, Track.Kind.Video, constraints, userProvidedTrack);
12058
+ /* @internal */
12059
+
11947
12060
  this.simulcastCodecs = new Map();
11948
12061
 
11949
12062
  this.monitorSender = async () => {
@@ -12016,15 +12129,11 @@ class LocalVideoTrack extends LocalTrack {
12016
12129
  }
12017
12130
 
12018
12131
  stop() {
12019
- this.sender = undefined;
12020
-
12021
12132
  this._mediaStreamTrack.getConstraints();
12022
12133
 
12023
12134
  this.simulcastCodecs.forEach(trackInfo => {
12024
12135
  trackInfo.mediaStreamTrack.stop();
12025
- trackInfo.sender = undefined;
12026
12136
  });
12027
- this.simulcastCodecs.clear();
12028
12137
  super.stop();
12029
12138
  }
12030
12139
 
@@ -12189,24 +12298,45 @@ class LocalVideoTrack extends LocalTrack {
12189
12298
 
12190
12299
  this.subscribedCodecs = codecs;
12191
12300
  const newCodecs = [];
12301
+ var _iteratorAbruptCompletion = false;
12302
+ var _didIteratorError = false;
12192
12303
 
12193
- for await (const codec of codecs) {
12194
- if (!this.codec || this.codec === codec.codec) {
12195
- await this.setPublishingLayers(codec.qualities);
12196
- } else {
12197
- const simulcastCodecInfo = this.simulcastCodecs.get(codec.codec);
12198
- livekitLogger.debug("try setPublishingCodec for ".concat(codec.codec), simulcastCodecInfo);
12304
+ var _iteratorError;
12199
12305
 
12200
- if (!simulcastCodecInfo || !simulcastCodecInfo.sender) {
12201
- for (const q of codec.qualities) {
12202
- if (q.enabled) {
12203
- newCodecs.push(codec.codec);
12204
- break;
12306
+ try {
12307
+ for (var _iterator = _asyncIterator(codecs), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
12308
+ const codec = _step.value;
12309
+
12310
+ if (!this.codec || this.codec === codec.codec) {
12311
+ await this.setPublishingLayers(codec.qualities);
12312
+ } else {
12313
+ const simulcastCodecInfo = this.simulcastCodecs.get(codec.codec);
12314
+ livekitLogger.debug("try setPublishingCodec for ".concat(codec.codec), simulcastCodecInfo);
12315
+
12316
+ if (!simulcastCodecInfo || !simulcastCodecInfo.sender) {
12317
+ for (const q of codec.qualities) {
12318
+ if (q.enabled) {
12319
+ newCodecs.push(codec.codec);
12320
+ break;
12321
+ }
12205
12322
  }
12323
+ } else if (simulcastCodecInfo.encodings) {
12324
+ livekitLogger.debug("try setPublishingLayersForSender ".concat(codec.codec));
12325
+ await setPublishingLayersForSender(simulcastCodecInfo.sender, simulcastCodecInfo.encodings, codec.qualities);
12206
12326
  }
12207
- } else if (simulcastCodecInfo.encodings) {
12208
- livekitLogger.debug("try setPublishingLayersForSender ".concat(codec.codec));
12209
- await setPublishingLayersForSender(simulcastCodecInfo.sender, simulcastCodecInfo.encodings, codec.qualities);
12327
+ }
12328
+ }
12329
+ } catch (err) {
12330
+ _didIteratorError = true;
12331
+ _iteratorError = err;
12332
+ } finally {
12333
+ try {
12334
+ if (_iteratorAbruptCompletion && _iterator.return != null) {
12335
+ await _iterator.return();
12336
+ }
12337
+ } finally {
12338
+ if (_didIteratorError) {
12339
+ throw _iteratorError;
12210
12340
  }
12211
12341
  }
12212
12342
  }
@@ -13620,6 +13750,7 @@ function sortPresets(presets) {
13620
13750
  class RemoteTrackPublication extends TrackPublication {
13621
13751
  constructor() {
13622
13752
  super(...arguments);
13753
+ this.track = undefined;
13623
13754
  /** @internal */
13624
13755
 
13625
13756
  this.allowed = true;
@@ -14043,6 +14174,17 @@ class RemoteParticipant extends Participant {
14043
14174
  publication = new RemoteTrackPublication(kind, ti.sid, ti.name);
14044
14175
  publication.updateInfo(ti);
14045
14176
  newTracks.set(ti.sid, publication);
14177
+ const existingTrackOfSource = Array.from(this.tracks.values()).find(publishedTrack => publishedTrack.source === (publication === null || publication === void 0 ? void 0 : publication.source));
14178
+
14179
+ if (existingTrackOfSource) {
14180
+ livekitLogger.warn("received a second track publication for ".concat(this.identity, " with the same source: ").concat(publication.source), {
14181
+ oldTrack: existingTrackOfSource,
14182
+ newTrack: publication,
14183
+ participant: this,
14184
+ participantInfo: info
14185
+ });
14186
+ }
14187
+
14046
14188
  this.addTrackPublication(publication);
14047
14189
  } else {
14048
14190
  publication.updateInfo(ti);
@@ -14191,10 +14333,30 @@ class LocalParticipant extends Participant {
14191
14333
  }
14192
14334
 
14193
14335
  const newCodecs = await pub.videoTrack.setPublishingCodecs(update.subscribedCodecs);
14336
+ var _iteratorAbruptCompletion = false;
14337
+ var _didIteratorError = false;
14338
+
14339
+ var _iteratorError;
14194
14340
 
14195
- for await (const codec of newCodecs) {
14196
- livekitLogger.debug("publish ".concat(codec, " for ").concat(pub.videoTrack.sid));
14197
- await this.publishAdditionalCodecForTrack(pub.videoTrack, codec, pub.options);
14341
+ try {
14342
+ for (var _iterator = _asyncIterator(newCodecs), _step; _iteratorAbruptCompletion = !(_step = await _iterator.next()).done; _iteratorAbruptCompletion = false) {
14343
+ const codec = _step.value;
14344
+ livekitLogger.debug("publish ".concat(codec, " for ").concat(pub.videoTrack.sid));
14345
+ await this.publishAdditionalCodecForTrack(pub.videoTrack, codec, pub.options);
14346
+ }
14347
+ } catch (err) {
14348
+ _didIteratorError = true;
14349
+ _iteratorError = err;
14350
+ } finally {
14351
+ try {
14352
+ if (_iteratorAbruptCompletion && _iterator.return != null) {
14353
+ await _iterator.return();
14354
+ }
14355
+ } finally {
14356
+ if (_didIteratorError) {
14357
+ throw _iteratorError;
14358
+ }
14359
+ }
14198
14360
  }
14199
14361
  } else if (update.subscribedQualities.length > 0) {
14200
14362
  (_b = pub.videoTrack) === null || _b === void 0 ? void 0 : _b.setPublishingLayers(update.subscribedQualities);
@@ -14618,6 +14780,23 @@ class LocalParticipant extends Participant {
14618
14780
  track.source = opts.source;
14619
14781
  }
14620
14782
 
14783
+ const existingTrackOfSource = Array.from(this.tracks.values()).find(publishedTrack => track instanceof LocalTrack && publishedTrack.source === track.source);
14784
+
14785
+ if (existingTrackOfSource) {
14786
+ try {
14787
+ // throw an Error in order to capture the stack trace
14788
+ throw Error("publishing a second track with the same source: ".concat(track.source));
14789
+ } catch (e) {
14790
+ if (e instanceof Error) {
14791
+ livekitLogger.warn(e.message, {
14792
+ oldTrack: existingTrackOfSource,
14793
+ newTrack: track,
14794
+ trace: e.stack
14795
+ });
14796
+ }
14797
+ }
14798
+ }
14799
+
14621
14800
  if (opts.stopMicTrackOnMute && track instanceof LocalAudioTrack) {
14622
14801
  track.stopOnMute = true;
14623
14802
  }
@@ -14849,7 +15028,6 @@ class LocalParticipant extends Participant {
14849
15028
  }
14850
15029
 
14851
15030
  track = publication.track;
14852
- track.sender = undefined;
14853
15031
  track.off(TrackEvent.Muted, this.onTrackMuted);
14854
15032
  track.off(TrackEvent.Unmuted, this.onTrackUnmuted);
14855
15033
  track.off(TrackEvent.Ended, this.handleTrackEnded);
@@ -14864,29 +15042,31 @@ class LocalParticipant extends Participant {
14864
15042
  track.stop();
14865
15043
  }
14866
15044
 
14867
- const {
14868
- mediaStreamTrack
14869
- } = track;
14870
-
14871
- if (this.engine.publisher && this.engine.publisher.pc.connectionState !== 'closed') {
14872
- const senders = this.engine.publisher.pc.getSenders();
14873
- senders.forEach(sender => {
14874
- var _a;
15045
+ if (this.engine.publisher && this.engine.publisher.pc.connectionState !== 'closed' && track.sender) {
15046
+ try {
15047
+ this.engine.removeTrack(track.sender);
14875
15048
 
14876
- if (sender.track === mediaStreamTrack) {
14877
- try {
14878
- (_a = this.engine.publisher) === null || _a === void 0 ? void 0 : _a.pc.removeTrack(sender);
14879
- this.engine.negotiate();
14880
- } catch (e) {
14881
- livekitLogger.warn('failed to remove track', {
14882
- error: e,
14883
- method: 'unpublishTrack'
14884
- });
15049
+ if (track instanceof LocalVideoTrack) {
15050
+ for (const [, trackInfo] of track.simulcastCodecs) {
15051
+ if (trackInfo.sender) {
15052
+ this.engine.removeTrack(trackInfo.sender);
15053
+ trackInfo.sender = undefined;
15054
+ }
14885
15055
  }
15056
+
15057
+ track.simulcastCodecs.clear();
14886
15058
  }
14887
- });
14888
- } // remove from our maps
15059
+ } catch (e) {
15060
+ livekitLogger.warn('failed to unpublish track', {
15061
+ error: e,
15062
+ method: 'unpublishTrack'
15063
+ });
15064
+ } finally {
15065
+ this.engine.negotiate();
15066
+ }
15067
+ }
14889
15068
 
15069
+ track.sender = undefined; // remove from our maps
14890
15070
 
14891
15071
  this.tracks.delete(publication.trackSid);
14892
15072
 
@@ -18982,73 +19162,784 @@ function fromProtoSessionDescription(sd) {
18982
19162
  sdp: sd.sdp
18983
19163
  };
18984
19164
 
18985
- switch (sd.type) {
18986
- case 'answer':
18987
- case 'offer':
18988
- case 'pranswer':
18989
- case 'rollback':
18990
- rsd.type = sd.type;
18991
- break;
18992
- }
19165
+ switch (sd.type) {
19166
+ case 'answer':
19167
+ case 'offer':
19168
+ case 'pranswer':
19169
+ case 'rollback':
19170
+ rsd.type = sd.type;
19171
+ break;
19172
+ }
19173
+
19174
+ return rsd;
19175
+ }
19176
+
19177
+ function toProtoSessionDescription(rsd) {
19178
+ const sd = {
19179
+ sdp: rsd.sdp,
19180
+ type: rsd.type
19181
+ };
19182
+ return sd;
19183
+ }
19184
+
19185
+ function createConnectionParams(token, info, opts) {
19186
+ const params = new URLSearchParams();
19187
+ params.set('access_token', token); // opts
19188
+
19189
+ if (opts === null || opts === void 0 ? void 0 : opts.reconnect) {
19190
+ params.set('reconnect', '1');
19191
+ }
19192
+
19193
+ if ((opts === null || opts === void 0 ? void 0 : opts.autoSubscribe) !== undefined) {
19194
+ params.set('auto_subscribe', opts.autoSubscribe ? '1' : '0');
19195
+ } // ClientInfo
19196
+
19197
+
19198
+ params.set('sdk', 'js');
19199
+ params.set('version', info.version);
19200
+ params.set('protocol', info.protocol.toString());
19201
+
19202
+ if (info.deviceModel) {
19203
+ params.set('device_model', info.deviceModel);
19204
+ }
19205
+
19206
+ if (info.os) {
19207
+ params.set('os', info.os);
19208
+ }
19209
+
19210
+ if (info.osVersion) {
19211
+ params.set('os_version', info.osVersion);
19212
+ }
19213
+
19214
+ if (info.browser) {
19215
+ params.set('browser', info.browser);
19216
+ }
19217
+
19218
+ if (info.browserVersion) {
19219
+ params.set('browser_version', info.browserVersion);
19220
+ }
19221
+
19222
+ if ((opts === null || opts === void 0 ? void 0 : opts.publishOnly) !== undefined) {
19223
+ params.set('publish', opts.publishOnly);
19224
+ }
19225
+
19226
+ if (opts === null || opts === void 0 ? void 0 : opts.adaptiveStream) {
19227
+ params.set('adaptive_stream', '1');
19228
+ }
19229
+
19230
+ return "?".concat(params.toString());
19231
+ }
19232
+
19233
+ const maxRetryDelay = 7000;
19234
+ const DEFAULT_RETRY_DELAYS_IN_MS = [0, 300, 2 * 2 * 300, 3 * 3 * 300, 4 * 4 * 300, maxRetryDelay, maxRetryDelay, maxRetryDelay, maxRetryDelay, maxRetryDelay];
19235
+
19236
+ class DefaultReconnectPolicy {
19237
+ constructor(retryDelays) {
19238
+ this._retryDelays = retryDelays !== undefined ? [...retryDelays] : DEFAULT_RETRY_DELAYS_IN_MS;
19239
+ }
19240
+
19241
+ nextRetryDelayInMs(context) {
19242
+ if (context.retryCount >= this._retryDelays.length) return null;
19243
+ const retryDelay = this._retryDelays[context.retryCount];
19244
+ if (context.retryCount <= 1) return retryDelay;
19245
+ return retryDelay + Math.random() * 1000;
19246
+ }
19247
+
19248
+ }
19249
+
19250
+ var parser$1 = {};
19251
+
19252
+ var grammar$2 = {exports: {}};
19253
+
19254
+ var grammar$1 = grammar$2.exports = {
19255
+ v: [{
19256
+ name: 'version',
19257
+ reg: /^(\d*)$/
19258
+ }],
19259
+ o: [{
19260
+ // o=- 20518 0 IN IP4 203.0.113.1
19261
+ // NB: sessionId will be a String in most cases because it is huge
19262
+ name: 'origin',
19263
+ reg: /^(\S*) (\d*) (\d*) (\S*) IP(\d) (\S*)/,
19264
+ names: ['username', 'sessionId', 'sessionVersion', 'netType', 'ipVer', 'address'],
19265
+ format: '%s %s %d %s IP%d %s'
19266
+ }],
19267
+ // default parsing of these only (though some of these feel outdated)
19268
+ s: [{
19269
+ name: 'name'
19270
+ }],
19271
+ i: [{
19272
+ name: 'description'
19273
+ }],
19274
+ u: [{
19275
+ name: 'uri'
19276
+ }],
19277
+ e: [{
19278
+ name: 'email'
19279
+ }],
19280
+ p: [{
19281
+ name: 'phone'
19282
+ }],
19283
+ z: [{
19284
+ name: 'timezones'
19285
+ }],
19286
+ // TODO: this one can actually be parsed properly...
19287
+ r: [{
19288
+ name: 'repeats'
19289
+ }],
19290
+ // TODO: this one can also be parsed properly
19291
+ // k: [{}], // outdated thing ignored
19292
+ t: [{
19293
+ // t=0 0
19294
+ name: 'timing',
19295
+ reg: /^(\d*) (\d*)/,
19296
+ names: ['start', 'stop'],
19297
+ format: '%d %d'
19298
+ }],
19299
+ c: [{
19300
+ // c=IN IP4 10.47.197.26
19301
+ name: 'connection',
19302
+ reg: /^IN IP(\d) (\S*)/,
19303
+ names: ['version', 'ip'],
19304
+ format: 'IN IP%d %s'
19305
+ }],
19306
+ b: [{
19307
+ // b=AS:4000
19308
+ push: 'bandwidth',
19309
+ reg: /^(TIAS|AS|CT|RR|RS):(\d*)/,
19310
+ names: ['type', 'limit'],
19311
+ format: '%s:%s'
19312
+ }],
19313
+ m: [{
19314
+ // m=video 51744 RTP/AVP 126 97 98 34 31
19315
+ // NB: special - pushes to session
19316
+ // TODO: rtp/fmtp should be filtered by the payloads found here?
19317
+ reg: /^(\w*) (\d*) ([\w/]*)(?: (.*))?/,
19318
+ names: ['type', 'port', 'protocol', 'payloads'],
19319
+ format: '%s %d %s %s'
19320
+ }],
19321
+ a: [{
19322
+ // a=rtpmap:110 opus/48000/2
19323
+ push: 'rtp',
19324
+ reg: /^rtpmap:(\d*) ([\w\-.]*)(?:\s*\/(\d*)(?:\s*\/(\S*))?)?/,
19325
+ names: ['payload', 'codec', 'rate', 'encoding'],
19326
+ format: function (o) {
19327
+ return o.encoding ? 'rtpmap:%d %s/%s/%s' : o.rate ? 'rtpmap:%d %s/%s' : 'rtpmap:%d %s';
19328
+ }
19329
+ }, {
19330
+ // a=fmtp:108 profile-level-id=24;object=23;bitrate=64000
19331
+ // a=fmtp:111 minptime=10; useinbandfec=1
19332
+ push: 'fmtp',
19333
+ reg: /^fmtp:(\d*) ([\S| ]*)/,
19334
+ names: ['payload', 'config'],
19335
+ format: 'fmtp:%d %s'
19336
+ }, {
19337
+ // a=control:streamid=0
19338
+ name: 'control',
19339
+ reg: /^control:(.*)/,
19340
+ format: 'control:%s'
19341
+ }, {
19342
+ // a=rtcp:65179 IN IP4 193.84.77.194
19343
+ name: 'rtcp',
19344
+ reg: /^rtcp:(\d*)(?: (\S*) IP(\d) (\S*))?/,
19345
+ names: ['port', 'netType', 'ipVer', 'address'],
19346
+ format: function (o) {
19347
+ return o.address != null ? 'rtcp:%d %s IP%d %s' : 'rtcp:%d';
19348
+ }
19349
+ }, {
19350
+ // a=rtcp-fb:98 trr-int 100
19351
+ push: 'rtcpFbTrrInt',
19352
+ reg: /^rtcp-fb:(\*|\d*) trr-int (\d*)/,
19353
+ names: ['payload', 'value'],
19354
+ format: 'rtcp-fb:%s trr-int %d'
19355
+ }, {
19356
+ // a=rtcp-fb:98 nack rpsi
19357
+ push: 'rtcpFb',
19358
+ reg: /^rtcp-fb:(\*|\d*) ([\w-_]*)(?: ([\w-_]*))?/,
19359
+ names: ['payload', 'type', 'subtype'],
19360
+ format: function (o) {
19361
+ return o.subtype != null ? 'rtcp-fb:%s %s %s' : 'rtcp-fb:%s %s';
19362
+ }
19363
+ }, {
19364
+ // a=extmap:2 urn:ietf:params:rtp-hdrext:toffset
19365
+ // a=extmap:1/recvonly URI-gps-string
19366
+ // a=extmap:3 urn:ietf:params:rtp-hdrext:encrypt urn:ietf:params:rtp-hdrext:smpte-tc 25@600/24
19367
+ push: 'ext',
19368
+ reg: /^extmap:(\d+)(?:\/(\w+))?(?: (urn:ietf:params:rtp-hdrext:encrypt))? (\S*)(?: (\S*))?/,
19369
+ names: ['value', 'direction', 'encrypt-uri', 'uri', 'config'],
19370
+ format: function (o) {
19371
+ return 'extmap:%d' + (o.direction ? '/%s' : '%v') + (o['encrypt-uri'] ? ' %s' : '%v') + ' %s' + (o.config ? ' %s' : '');
19372
+ }
19373
+ }, {
19374
+ // a=extmap-allow-mixed
19375
+ name: 'extmapAllowMixed',
19376
+ reg: /^(extmap-allow-mixed)/
19377
+ }, {
19378
+ // a=crypto:1 AES_CM_128_HMAC_SHA1_80 inline:PS1uQCVeeCFCanVmcjkpPywjNWhcYD0mXXtxaVBR|2^20|1:32
19379
+ push: 'crypto',
19380
+ reg: /^crypto:(\d*) ([\w_]*) (\S*)(?: (\S*))?/,
19381
+ names: ['id', 'suite', 'config', 'sessionConfig'],
19382
+ format: function (o) {
19383
+ return o.sessionConfig != null ? 'crypto:%d %s %s %s' : 'crypto:%d %s %s';
19384
+ }
19385
+ }, {
19386
+ // a=setup:actpass
19387
+ name: 'setup',
19388
+ reg: /^setup:(\w*)/,
19389
+ format: 'setup:%s'
19390
+ }, {
19391
+ // a=connection:new
19392
+ name: 'connectionType',
19393
+ reg: /^connection:(new|existing)/,
19394
+ format: 'connection:%s'
19395
+ }, {
19396
+ // a=mid:1
19397
+ name: 'mid',
19398
+ reg: /^mid:([^\s]*)/,
19399
+ format: 'mid:%s'
19400
+ }, {
19401
+ // a=msid:0c8b064d-d807-43b4-b434-f92a889d8587 98178685-d409-46e0-8e16-7ef0db0db64a
19402
+ name: 'msid',
19403
+ reg: /^msid:(.*)/,
19404
+ format: 'msid:%s'
19405
+ }, {
19406
+ // a=ptime:20
19407
+ name: 'ptime',
19408
+ reg: /^ptime:(\d*(?:\.\d*)*)/,
19409
+ format: 'ptime:%d'
19410
+ }, {
19411
+ // a=maxptime:60
19412
+ name: 'maxptime',
19413
+ reg: /^maxptime:(\d*(?:\.\d*)*)/,
19414
+ format: 'maxptime:%d'
19415
+ }, {
19416
+ // a=sendrecv
19417
+ name: 'direction',
19418
+ reg: /^(sendrecv|recvonly|sendonly|inactive)/
19419
+ }, {
19420
+ // a=ice-lite
19421
+ name: 'icelite',
19422
+ reg: /^(ice-lite)/
19423
+ }, {
19424
+ // a=ice-ufrag:F7gI
19425
+ name: 'iceUfrag',
19426
+ reg: /^ice-ufrag:(\S*)/,
19427
+ format: 'ice-ufrag:%s'
19428
+ }, {
19429
+ // a=ice-pwd:x9cml/YzichV2+XlhiMu8g
19430
+ name: 'icePwd',
19431
+ reg: /^ice-pwd:(\S*)/,
19432
+ format: 'ice-pwd:%s'
19433
+ }, {
19434
+ // a=fingerprint:SHA-1 00:11:22:33:44:55:66:77:88:99:AA:BB:CC:DD:EE:FF:00:11:22:33
19435
+ name: 'fingerprint',
19436
+ reg: /^fingerprint:(\S*) (\S*)/,
19437
+ names: ['type', 'hash'],
19438
+ format: 'fingerprint:%s %s'
19439
+ }, {
19440
+ // a=candidate:0 1 UDP 2113667327 203.0.113.1 54400 typ host
19441
+ // a=candidate:1162875081 1 udp 2113937151 192.168.34.75 60017 typ host generation 0 network-id 3 network-cost 10
19442
+ // a=candidate:3289912957 2 udp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 generation 0 network-id 3 network-cost 10
19443
+ // a=candidate:229815620 1 tcp 1518280447 192.168.150.19 60017 typ host tcptype active generation 0 network-id 3 network-cost 10
19444
+ // a=candidate:3289912957 2 tcp 1845501695 193.84.77.194 60017 typ srflx raddr 192.168.34.75 rport 60017 tcptype passive generation 0 network-id 3 network-cost 10
19445
+ push: 'candidates',
19446
+ reg: /^candidate:(\S*) (\d*) (\S*) (\d*) (\S*) (\d*) typ (\S*)(?: raddr (\S*) rport (\d*))?(?: tcptype (\S*))?(?: generation (\d*))?(?: network-id (\d*))?(?: network-cost (\d*))?/,
19447
+ names: ['foundation', 'component', 'transport', 'priority', 'ip', 'port', 'type', 'raddr', 'rport', 'tcptype', 'generation', 'network-id', 'network-cost'],
19448
+ format: function (o) {
19449
+ var str = 'candidate:%s %d %s %d %s %d typ %s';
19450
+ str += o.raddr != null ? ' raddr %s rport %d' : '%v%v'; // NB: candidate has three optional chunks, so %void middles one if it's missing
19451
+
19452
+ str += o.tcptype != null ? ' tcptype %s' : '%v';
19453
+
19454
+ if (o.generation != null) {
19455
+ str += ' generation %d';
19456
+ }
19457
+
19458
+ str += o['network-id'] != null ? ' network-id %d' : '%v';
19459
+ str += o['network-cost'] != null ? ' network-cost %d' : '%v';
19460
+ return str;
19461
+ }
19462
+ }, {
19463
+ // a=end-of-candidates (keep after the candidates line for readability)
19464
+ name: 'endOfCandidates',
19465
+ reg: /^(end-of-candidates)/
19466
+ }, {
19467
+ // a=remote-candidates:1 203.0.113.1 54400 2 203.0.113.1 54401 ...
19468
+ name: 'remoteCandidates',
19469
+ reg: /^remote-candidates:(.*)/,
19470
+ format: 'remote-candidates:%s'
19471
+ }, {
19472
+ // a=ice-options:google-ice
19473
+ name: 'iceOptions',
19474
+ reg: /^ice-options:(\S*)/,
19475
+ format: 'ice-options:%s'
19476
+ }, {
19477
+ // a=ssrc:2566107569 cname:t9YU8M1UxTF8Y1A1
19478
+ push: 'ssrcs',
19479
+ reg: /^ssrc:(\d*) ([\w_-]*)(?::(.*))?/,
19480
+ names: ['id', 'attribute', 'value'],
19481
+ format: function (o) {
19482
+ var str = 'ssrc:%d';
19483
+
19484
+ if (o.attribute != null) {
19485
+ str += ' %s';
19486
+
19487
+ if (o.value != null) {
19488
+ str += ':%s';
19489
+ }
19490
+ }
19491
+
19492
+ return str;
19493
+ }
19494
+ }, {
19495
+ // a=ssrc-group:FEC 1 2
19496
+ // a=ssrc-group:FEC-FR 3004364195 1080772241
19497
+ push: 'ssrcGroups',
19498
+ // token-char = %x21 / %x23-27 / %x2A-2B / %x2D-2E / %x30-39 / %x41-5A / %x5E-7E
19499
+ reg: /^ssrc-group:([\x21\x23\x24\x25\x26\x27\x2A\x2B\x2D\x2E\w]*) (.*)/,
19500
+ names: ['semantics', 'ssrcs'],
19501
+ format: 'ssrc-group:%s %s'
19502
+ }, {
19503
+ // a=msid-semantic: WMS Jvlam5X3SX1OP6pn20zWogvaKJz5Hjf9OnlV
19504
+ name: 'msidSemantic',
19505
+ reg: /^msid-semantic:\s?(\w*) (\S*)/,
19506
+ names: ['semantic', 'token'],
19507
+ format: 'msid-semantic: %s %s' // space after ':' is not accidental
19508
+
19509
+ }, {
19510
+ // a=group:BUNDLE audio video
19511
+ push: 'groups',
19512
+ reg: /^group:(\w*) (.*)/,
19513
+ names: ['type', 'mids'],
19514
+ format: 'group:%s %s'
19515
+ }, {
19516
+ // a=rtcp-mux
19517
+ name: 'rtcpMux',
19518
+ reg: /^(rtcp-mux)/
19519
+ }, {
19520
+ // a=rtcp-rsize
19521
+ name: 'rtcpRsize',
19522
+ reg: /^(rtcp-rsize)/
19523
+ }, {
19524
+ // a=sctpmap:5000 webrtc-datachannel 1024
19525
+ name: 'sctpmap',
19526
+ reg: /^sctpmap:([\w_/]*) (\S*)(?: (\S*))?/,
19527
+ names: ['sctpmapNumber', 'app', 'maxMessageSize'],
19528
+ format: function (o) {
19529
+ return o.maxMessageSize != null ? 'sctpmap:%s %s %s' : 'sctpmap:%s %s';
19530
+ }
19531
+ }, {
19532
+ // a=x-google-flag:conference
19533
+ name: 'xGoogleFlag',
19534
+ reg: /^x-google-flag:([^\s]*)/,
19535
+ format: 'x-google-flag:%s'
19536
+ }, {
19537
+ // a=rid:1 send max-width=1280;max-height=720;max-fps=30;depend=0
19538
+ push: 'rids',
19539
+ reg: /^rid:([\d\w]+) (\w+)(?: ([\S| ]*))?/,
19540
+ names: ['id', 'direction', 'params'],
19541
+ format: function (o) {
19542
+ return o.params ? 'rid:%s %s %s' : 'rid:%s %s';
19543
+ }
19544
+ }, {
19545
+ // a=imageattr:97 send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320] recv [x=330,y=250]
19546
+ // a=imageattr:* send [x=800,y=640] recv *
19547
+ // a=imageattr:100 recv [x=320,y=240]
19548
+ push: 'imageattrs',
19549
+ reg: new RegExp( // a=imageattr:97
19550
+ '^imageattr:(\\d+|\\*)' + // send [x=800,y=640,sar=1.1,q=0.6] [x=480,y=320]
19551
+ '[\\s\\t]+(send|recv)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*)' + // recv [x=330,y=250]
19552
+ '(?:[\\s\\t]+(recv|send)[\\s\\t]+(\\*|\\[\\S+\\](?:[\\s\\t]+\\[\\S+\\])*))?'),
19553
+ names: ['pt', 'dir1', 'attrs1', 'dir2', 'attrs2'],
19554
+ format: function (o) {
19555
+ return 'imageattr:%s %s %s' + (o.dir2 ? ' %s %s' : '');
19556
+ }
19557
+ }, {
19558
+ // a=simulcast:send 1,2,3;~4,~5 recv 6;~7,~8
19559
+ // a=simulcast:recv 1;4,5 send 6;7
19560
+ name: 'simulcast',
19561
+ reg: new RegExp( // a=simulcast:
19562
+ '^simulcast:' + // send 1,2,3;~4,~5
19563
+ '(send|recv) ([a-zA-Z0-9\\-_~;,]+)' + // space + recv 6;~7,~8
19564
+ '(?:\\s?(send|recv) ([a-zA-Z0-9\\-_~;,]+))?' + // end
19565
+ '$'),
19566
+ names: ['dir1', 'list1', 'dir2', 'list2'],
19567
+ format: function (o) {
19568
+ return 'simulcast:%s %s' + (o.dir2 ? ' %s %s' : '');
19569
+ }
19570
+ }, {
19571
+ // old simulcast draft 03 (implemented by Firefox)
19572
+ // https://tools.ietf.org/html/draft-ietf-mmusic-sdp-simulcast-03
19573
+ // a=simulcast: recv pt=97;98 send pt=97
19574
+ // a=simulcast: send rid=5;6;7 paused=6,7
19575
+ name: 'simulcast_03',
19576
+ reg: /^simulcast:[\s\t]+([\S+\s\t]+)$/,
19577
+ names: ['value'],
19578
+ format: 'simulcast: %s'
19579
+ }, {
19580
+ // a=framerate:25
19581
+ // a=framerate:29.97
19582
+ name: 'framerate',
19583
+ reg: /^framerate:(\d+(?:$|\.\d+))/,
19584
+ format: 'framerate:%s'
19585
+ }, {
19586
+ // RFC4570
19587
+ // a=source-filter: incl IN IP4 239.5.2.31 10.1.15.5
19588
+ name: 'sourceFilter',
19589
+ reg: /^source-filter: *(excl|incl) (\S*) (IP4|IP6|\*) (\S*) (.*)/,
19590
+ names: ['filterMode', 'netType', 'addressTypes', 'destAddress', 'srcList'],
19591
+ format: 'source-filter: %s %s %s %s %s'
19592
+ }, {
19593
+ // a=bundle-only
19594
+ name: 'bundleOnly',
19595
+ reg: /^(bundle-only)/
19596
+ }, {
19597
+ // a=label:1
19598
+ name: 'label',
19599
+ reg: /^label:(.+)/,
19600
+ format: 'label:%s'
19601
+ }, {
19602
+ // RFC version 26 for SCTP over DTLS
19603
+ // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-5
19604
+ name: 'sctpPort',
19605
+ reg: /^sctp-port:(\d+)$/,
19606
+ format: 'sctp-port:%s'
19607
+ }, {
19608
+ // RFC version 26 for SCTP over DTLS
19609
+ // https://tools.ietf.org/html/draft-ietf-mmusic-sctp-sdp-26#section-6
19610
+ name: 'maxMessageSize',
19611
+ reg: /^max-message-size:(\d+)$/,
19612
+ format: 'max-message-size:%s'
19613
+ }, {
19614
+ // RFC7273
19615
+ // a=ts-refclk:ptp=IEEE1588-2008:39-A7-94-FF-FE-07-CB-D0:37
19616
+ push: 'tsRefClocks',
19617
+ reg: /^ts-refclk:([^\s=]*)(?:=(\S*))?/,
19618
+ names: ['clksrc', 'clksrcExt'],
19619
+ format: function (o) {
19620
+ return 'ts-refclk:%s' + (o.clksrcExt != null ? '=%s' : '');
19621
+ }
19622
+ }, {
19623
+ // RFC7273
19624
+ // a=mediaclk:direct=963214424
19625
+ name: 'mediaClk',
19626
+ reg: /^mediaclk:(?:id=(\S*))? *([^\s=]*)(?:=(\S*))?(?: *rate=(\d+)\/(\d+))?/,
19627
+ names: ['id', 'mediaClockName', 'mediaClockValue', 'rateNumerator', 'rateDenominator'],
19628
+ format: function (o) {
19629
+ var str = 'mediaclk:';
19630
+ str += o.id != null ? 'id=%s %s' : '%v%s';
19631
+ str += o.mediaClockValue != null ? '=%s' : '';
19632
+ str += o.rateNumerator != null ? ' rate=%s' : '';
19633
+ str += o.rateDenominator != null ? '/%s' : '';
19634
+ return str;
19635
+ }
19636
+ }, {
19637
+ // a=keywds:keywords
19638
+ name: 'keywords',
19639
+ reg: /^keywds:(.+)$/,
19640
+ format: 'keywds:%s'
19641
+ }, {
19642
+ // a=content:main
19643
+ name: 'content',
19644
+ reg: /^content:(.+)/,
19645
+ format: 'content:%s'
19646
+ }, // BFCP https://tools.ietf.org/html/rfc4583
19647
+ {
19648
+ // a=floorctrl:c-s
19649
+ name: 'bfcpFloorCtrl',
19650
+ reg: /^floorctrl:(c-only|s-only|c-s)/,
19651
+ format: 'floorctrl:%s'
19652
+ }, {
19653
+ // a=confid:1
19654
+ name: 'bfcpConfId',
19655
+ reg: /^confid:(\d+)/,
19656
+ format: 'confid:%s'
19657
+ }, {
19658
+ // a=userid:1
19659
+ name: 'bfcpUserId',
19660
+ reg: /^userid:(\d+)/,
19661
+ format: 'userid:%s'
19662
+ }, {
19663
+ // a=floorid:1
19664
+ name: 'bfcpFloorId',
19665
+ reg: /^floorid:(.+) (?:m-stream|mstrm):(.+)/,
19666
+ names: ['id', 'mStream'],
19667
+ format: 'floorid:%s mstrm:%s'
19668
+ }, {
19669
+ // any a= that we don't understand is kept verbatim on media.invalid
19670
+ push: 'invalid',
19671
+ names: ['value']
19672
+ }]
19673
+ }; // set sensible defaults to avoid polluting the grammar with boring details
19674
+
19675
+ Object.keys(grammar$1).forEach(function (key) {
19676
+ var objs = grammar$1[key];
19677
+ objs.forEach(function (obj) {
19678
+ if (!obj.reg) {
19679
+ obj.reg = /(.*)/;
19680
+ }
19681
+
19682
+ if (!obj.format) {
19683
+ obj.format = '%s';
19684
+ }
19685
+ });
19686
+ });
19687
+
19688
+ (function (exports) {
19689
+ var toIntIfInt = function (v) {
19690
+ return String(Number(v)) === v ? Number(v) : v;
19691
+ };
19692
+
19693
+ var attachProperties = function (match, location, names, rawName) {
19694
+ if (rawName && !names) {
19695
+ location[rawName] = toIntIfInt(match[1]);
19696
+ } else {
19697
+ for (var i = 0; i < names.length; i += 1) {
19698
+ if (match[i + 1] != null) {
19699
+ location[names[i]] = toIntIfInt(match[i + 1]);
19700
+ }
19701
+ }
19702
+ }
19703
+ };
19704
+
19705
+ var parseReg = function (obj, location, content) {
19706
+ var needsBlank = obj.name && obj.names;
19707
+
19708
+ if (obj.push && !location[obj.push]) {
19709
+ location[obj.push] = [];
19710
+ } else if (needsBlank && !location[obj.name]) {
19711
+ location[obj.name] = {};
19712
+ }
19713
+
19714
+ var keyLocation = obj.push ? {} : // blank object that will be pushed
19715
+ needsBlank ? location[obj.name] : location; // otherwise, named location or root
19716
+
19717
+ attachProperties(content.match(obj.reg), keyLocation, obj.names, obj.name);
19718
+
19719
+ if (obj.push) {
19720
+ location[obj.push].push(keyLocation);
19721
+ }
19722
+ };
19723
+
19724
+ var grammar = grammar$2.exports;
19725
+ var validLine = RegExp.prototype.test.bind(/^([a-z])=(.*)/);
19726
+
19727
+ exports.parse = function (sdp) {
19728
+ var session = {},
19729
+ media = [],
19730
+ location = session; // points at where properties go under (one of the above)
19731
+ // parse lines we understand
19732
+
19733
+ sdp.split(/(\r\n|\r|\n)/).filter(validLine).forEach(function (l) {
19734
+ var type = l[0];
19735
+ var content = l.slice(2);
19736
+
19737
+ if (type === 'm') {
19738
+ media.push({
19739
+ rtp: [],
19740
+ fmtp: []
19741
+ });
19742
+ location = media[media.length - 1]; // point at latest media line
19743
+ }
19744
+
19745
+ for (var j = 0; j < (grammar[type] || []).length; j += 1) {
19746
+ var obj = grammar[type][j];
19747
+
19748
+ if (obj.reg.test(content)) {
19749
+ return parseReg(obj, location, content);
19750
+ }
19751
+ }
19752
+ });
19753
+ session.media = media; // link it up
19754
+
19755
+ return session;
19756
+ };
19757
+
19758
+ var paramReducer = function (acc, expr) {
19759
+ var s = expr.split(/=(.+)/, 2);
19760
+
19761
+ if (s.length === 2) {
19762
+ acc[s[0]] = toIntIfInt(s[1]);
19763
+ } else if (s.length === 1 && expr.length > 1) {
19764
+ acc[s[0]] = undefined;
19765
+ }
19766
+
19767
+ return acc;
19768
+ };
19769
+
19770
+ exports.parseParams = function (str) {
19771
+ return str.split(/;\s?/).reduce(paramReducer, {});
19772
+ }; // For backward compatibility - alias will be removed in 3.0.0
19773
+
19774
+
19775
+ exports.parseFmtpConfig = exports.parseParams;
19776
+
19777
+ exports.parsePayloads = function (str) {
19778
+ return str.toString().split(' ').map(Number);
19779
+ };
19780
+
19781
+ exports.parseRemoteCandidates = function (str) {
19782
+ var candidates = [];
19783
+ var parts = str.split(' ').map(toIntIfInt);
19784
+
19785
+ for (var i = 0; i < parts.length; i += 3) {
19786
+ candidates.push({
19787
+ component: parts[i],
19788
+ ip: parts[i + 1],
19789
+ port: parts[i + 2]
19790
+ });
19791
+ }
19792
+
19793
+ return candidates;
19794
+ };
19795
+
19796
+ exports.parseImageAttributes = function (str) {
19797
+ return str.split(' ').map(function (item) {
19798
+ return item.substring(1, item.length - 1).split(',').reduce(paramReducer, {});
19799
+ });
19800
+ };
19801
+
19802
+ exports.parseSimulcastStreamList = function (str) {
19803
+ return str.split(';').map(function (stream) {
19804
+ return stream.split(',').map(function (format) {
19805
+ var scid,
19806
+ paused = false;
19807
+
19808
+ if (format[0] !== '~') {
19809
+ scid = toIntIfInt(format);
19810
+ } else {
19811
+ scid = toIntIfInt(format.substring(1, format.length));
19812
+ paused = true;
19813
+ }
19814
+
19815
+ return {
19816
+ scid: scid,
19817
+ paused: paused
19818
+ };
19819
+ });
19820
+ });
19821
+ };
19822
+ })(parser$1);
19823
+
19824
+ var grammar = grammar$2.exports; // customized util.format - discards excess arguments and can void middle ones
18993
19825
 
18994
- return rsd;
18995
- }
19826
+ var formatRegExp = /%[sdv%]/g;
18996
19827
 
18997
- function toProtoSessionDescription(rsd) {
18998
- const sd = {
18999
- sdp: rsd.sdp,
19000
- type: rsd.type
19001
- };
19002
- return sd;
19003
- }
19828
+ var format = function (formatStr) {
19829
+ var i = 1;
19830
+ var args = arguments;
19831
+ var len = args.length;
19832
+ return formatStr.replace(formatRegExp, function (x) {
19833
+ if (i >= len) {
19834
+ return x; // missing argument
19835
+ }
19004
19836
 
19005
- function createConnectionParams(token, info, opts) {
19006
- const params = new URLSearchParams();
19007
- params.set('access_token', token); // opts
19837
+ var arg = args[i];
19838
+ i += 1;
19008
19839
 
19009
- if (opts === null || opts === void 0 ? void 0 : opts.reconnect) {
19010
- params.set('reconnect', '1');
19011
- }
19840
+ switch (x) {
19841
+ case '%%':
19842
+ return '%';
19012
19843
 
19013
- if ((opts === null || opts === void 0 ? void 0 : opts.autoSubscribe) !== undefined) {
19014
- params.set('auto_subscribe', opts.autoSubscribe ? '1' : '0');
19015
- } // ClientInfo
19844
+ case '%s':
19845
+ return String(arg);
19016
19846
 
19847
+ case '%d':
19848
+ return Number(arg);
19017
19849
 
19018
- params.set('sdk', 'js');
19019
- params.set('version', info.version);
19020
- params.set('protocol', info.protocol.toString());
19850
+ case '%v':
19851
+ return '';
19852
+ }
19853
+ }); // NB: we discard excess arguments - they are typically undefined from makeLine
19854
+ };
19021
19855
 
19022
- if (info.deviceModel) {
19023
- params.set('device_model', info.deviceModel);
19024
- }
19856
+ var makeLine = function (type, obj, location) {
19857
+ var str = obj.format instanceof Function ? obj.format(obj.push ? location : location[obj.name]) : obj.format;
19858
+ var args = [type + '=' + str];
19025
19859
 
19026
- if (info.os) {
19027
- params.set('os', info.os);
19028
- }
19860
+ if (obj.names) {
19861
+ for (var i = 0; i < obj.names.length; i += 1) {
19862
+ var n = obj.names[i];
19029
19863
 
19030
- if (info.osVersion) {
19031
- params.set('os_version', info.osVersion);
19864
+ if (obj.name) {
19865
+ args.push(location[obj.name][n]);
19866
+ } else {
19867
+ // for mLine and push attributes
19868
+ args.push(location[obj.names[i]]);
19869
+ }
19870
+ }
19871
+ } else {
19872
+ args.push(location[obj.name]);
19032
19873
  }
19033
19874
 
19034
- if (info.browser) {
19035
- params.set('browser', info.browser);
19036
- }
19875
+ return format.apply(null, args);
19876
+ }; // RFC specified order
19877
+ // TODO: extend this with all the rest
19037
19878
 
19038
- if (info.browserVersion) {
19039
- params.set('browser_version', info.browserVersion);
19040
- }
19041
19879
 
19042
- if ((opts === null || opts === void 0 ? void 0 : opts.publishOnly) !== undefined) {
19043
- params.set('publish', opts.publishOnly);
19880
+ var defaultOuterOrder = ['v', 'o', 's', 'i', 'u', 'e', 'p', 'c', 'b', 't', 'r', 'z', 'a'];
19881
+ var defaultInnerOrder = ['i', 'c', 'b', 'a'];
19882
+
19883
+ var writer$1 = function (session, opts) {
19884
+ opts = opts || {}; // ensure certain properties exist
19885
+
19886
+ if (session.version == null) {
19887
+ session.version = 0; // 'v=0' must be there (only defined version atm)
19044
19888
  }
19045
19889
 
19046
- if (opts === null || opts === void 0 ? void 0 : opts.adaptiveStream) {
19047
- params.set('adaptive_stream', '1');
19890
+ if (session.name == null) {
19891
+ session.name = ' '; // 's= ' must be there if no meaningful name set
19048
19892
  }
19049
19893
 
19050
- return "?".concat(params.toString());
19051
- }
19894
+ session.media.forEach(function (mLine) {
19895
+ if (mLine.payloads == null) {
19896
+ mLine.payloads = '';
19897
+ }
19898
+ });
19899
+ var outerOrder = opts.outerOrder || defaultOuterOrder;
19900
+ var innerOrder = opts.innerOrder || defaultInnerOrder;
19901
+ var sdp = []; // loop through outerOrder for matching properties on session
19902
+
19903
+ outerOrder.forEach(function (type) {
19904
+ grammar[type].forEach(function (obj) {
19905
+ if (obj.name in session && session[obj.name] != null) {
19906
+ sdp.push(makeLine(type, obj, session));
19907
+ } else if (obj.push in session && session[obj.push] != null) {
19908
+ session[obj.push].forEach(function (el) {
19909
+ sdp.push(makeLine(type, obj, el));
19910
+ });
19911
+ }
19912
+ });
19913
+ }); // then for each media line, follow the innerOrder
19914
+
19915
+ session.media.forEach(function (mLine) {
19916
+ sdp.push(makeLine('m', grammar.m[0], mLine));
19917
+ innerOrder.forEach(function (type) {
19918
+ grammar[type].forEach(function (obj) {
19919
+ if (obj.name in mLine && mLine[obj.name] != null) {
19920
+ sdp.push(makeLine(type, obj, mLine));
19921
+ } else if (obj.push in mLine && mLine[obj.push] != null) {
19922
+ mLine[obj.push].forEach(function (el) {
19923
+ sdp.push(makeLine(type, obj, el));
19924
+ });
19925
+ }
19926
+ });
19927
+ });
19928
+ });
19929
+ return sdp.join('\r\n') + '\r\n';
19930
+ };
19931
+
19932
+ var parser = parser$1;
19933
+ var writer = writer$1;
19934
+ var write = writer;
19935
+ var parse = parser.parse;
19936
+ parser.parseParams;
19937
+ parser.parseFmtpConfig; // Alias of parseParams().
19938
+
19939
+ parser.parsePayloads;
19940
+ parser.parseRemoteCandidates;
19941
+ parser.parseImageAttributes;
19942
+ parser.parseSimulcastStreamList;
19052
19943
 
19053
19944
  /** @internal */
19054
19945
 
@@ -19092,6 +19983,8 @@ class PCTransport {
19092
19983
  }
19093
19984
 
19094
19985
  async createAndSendOffer(options) {
19986
+ var _a;
19987
+
19095
19988
  if (this.onOffer === undefined) {
19096
19989
  return;
19097
19990
  }
@@ -19121,30 +20014,72 @@ class PCTransport {
19121
20014
 
19122
20015
 
19123
20016
  livekitLogger.debug('starting to negotiate');
19124
- const offer = await this.pc.createOffer(options); // mung sdp for codec bitrate setting that can't apply by sendEncoding
20017
+ const offer = await this.pc.createOffer(options);
20018
+ const sdpParsed = parse((_a = offer.sdp) !== null && _a !== void 0 ? _a : '');
20019
+ sdpParsed.media.forEach(media => {
20020
+ if (media.type === 'audio') {
20021
+ ensureAudioNack(media);
20022
+ } else if (media.type === 'video') {
20023
+ // mung sdp for codec bitrate setting that can't apply by sendEncoding
20024
+ this.trackBitrates.some(trackbr => {
20025
+ if (!media.msid || !media.msid.includes(trackbr.sid)) {
20026
+ return false;
20027
+ }
19125
20028
 
19126
- this.trackBitrates.forEach(trackbr => {
19127
- var _a;
20029
+ let codecPayload = 0;
20030
+ media.rtp.some(rtp => {
20031
+ if (rtp.codec.toUpperCase() === trackbr.codec.toUpperCase()) {
20032
+ codecPayload = rtp.payload;
20033
+ return true;
20034
+ }
19128
20035
 
19129
- let sdp = (_a = offer.sdp) !== null && _a !== void 0 ? _a : '';
19130
- const sidIndex = sdp.search(new RegExp("msid.* ".concat(trackbr.sid)));
20036
+ return false;
20037
+ }); // add x-google-max-bitrate to fmtp line if not exist
19131
20038
 
19132
- if (sidIndex < 0) {
19133
- return;
19134
- }
20039
+ if (codecPayload > 0) {
20040
+ if (!media.fmtp.some(fmtp => {
20041
+ if (fmtp.payload === codecPayload) {
20042
+ if (!fmtp.config.includes('x-google-max-bitrate')) {
20043
+ fmtp.config += ";x-google-max-bitrate=".concat(trackbr.maxbr);
20044
+ }
19135
20045
 
19136
- const mlineStart = sdp.substring(0, sidIndex).lastIndexOf('m=');
19137
- const mlineEnd = sdp.indexOf('m=', sidIndex);
19138
- const mediaSection = sdp.substring(mlineStart, mlineEnd);
19139
- const mungedMediaSection = mediaSection.replace(new RegExp("a=rtpmap:(\\d+) ".concat(trackbr.codec, "/\\d+"), 'i'), '$'.concat("&\r\na=fmtp:$1 x-google-max-bitrate=".concat(trackbr.maxbr)));
19140
- sdp = sdp.substring(0, mlineStart) + mungedMediaSection + sdp.substring(mlineEnd);
19141
- offer.sdp = sdp;
20046
+ return true;
20047
+ }
20048
+
20049
+ return false;
20050
+ })) {
20051
+ media.fmtp.push({
20052
+ payload: codecPayload,
20053
+ config: "x-google-max-bitrate=".concat(trackbr.maxbr)
20054
+ });
20055
+ }
20056
+ }
20057
+
20058
+ return true;
20059
+ });
20060
+ }
19142
20061
  });
20062
+ offer.sdp = write(sdpParsed);
19143
20063
  this.trackBitrates = [];
19144
20064
  await this.pc.setLocalDescription(offer);
19145
20065
  this.onOffer(offer);
19146
20066
  }
19147
20067
 
20068
+ async createAndSetAnswer() {
20069
+ var _a;
20070
+
20071
+ const answer = await this.pc.createAnswer();
20072
+ const sdpParsed = parse((_a = answer.sdp) !== null && _a !== void 0 ? _a : '');
20073
+ sdpParsed.media.forEach(media => {
20074
+ if (media.type === 'audio') {
20075
+ ensureAudioNack(media);
20076
+ }
20077
+ });
20078
+ answer.sdp = write(sdpParsed);
20079
+ await this.pc.setLocalDescription(answer);
20080
+ return answer;
20081
+ }
20082
+
19148
20083
  setTrackCodecBitrate(sid, codec, maxbr) {
19149
20084
  this.trackBitrates.push({
19150
20085
  sid,
@@ -19159,11 +20094,35 @@ class PCTransport {
19159
20094
 
19160
20095
  }
19161
20096
 
20097
+ function ensureAudioNack(media) {
20098
+ // found opus codec to add nack fb
20099
+ let opusPayload = 0;
20100
+ media.rtp.some(rtp => {
20101
+ if (rtp.codec === 'opus') {
20102
+ opusPayload = rtp.payload;
20103
+ return true;
20104
+ }
20105
+
20106
+ return false;
20107
+ }); // add nack rtcpfb if not exist
20108
+
20109
+ if (opusPayload > 0) {
20110
+ if (!media.rtcpFb) {
20111
+ media.rtcpFb = [];
20112
+ }
20113
+
20114
+ if (!media.rtcpFb.some(fb => fb.payload === opusPayload && fb.type === 'nack')) {
20115
+ media.rtcpFb.push({
20116
+ payload: opusPayload,
20117
+ type: 'nack'
20118
+ });
20119
+ }
20120
+ }
20121
+ }
20122
+
19162
20123
  const lossyDataChannel = '_lossy';
19163
20124
  const reliableDataChannel = '_reliable';
19164
- const maxReconnectRetries = 10;
19165
20125
  const minReconnectWait = 2 * 1000;
19166
- const maxReconnectDuration = 60 * 1000;
19167
20126
  const maxICEConnectTimeout = 15 * 1000;
19168
20127
  var PCState;
19169
20128
 
@@ -19178,8 +20137,14 @@ var PCState;
19178
20137
 
19179
20138
 
19180
20139
  class RTCEngine extends events.exports.EventEmitter {
19181
- constructor() {
20140
+ constructor(options) {
20141
+ var _this;
20142
+
20143
+ var _a;
20144
+
19182
20145
  super();
20146
+ _this = this;
20147
+ this.options = options;
19183
20148
  this.rtcConfig = {};
19184
20149
  this.subscriberPrimary = false;
19185
20150
  this.pcState = PCState.New;
@@ -19254,53 +20219,85 @@ class RTCEngine extends events.exports.EventEmitter {
19254
20219
  // after a number of retries, we'll close and give up permanently
19255
20220
 
19256
20221
 
19257
- this.handleDisconnect = connection => {
19258
- if (this._isClosed) {
20222
+ this.handleDisconnect = function (connection) {
20223
+ let signalEvents = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
20224
+
20225
+ if (_this._isClosed) {
19259
20226
  return;
19260
20227
  }
19261
20228
 
19262
20229
  livekitLogger.debug("".concat(connection, " disconnected"));
19263
20230
 
19264
- if (this.reconnectAttempts === 0) {
20231
+ if (_this.reconnectAttempts === 0) {
19265
20232
  // only reset start time on the first try
19266
- this.reconnectStart = Date.now();
20233
+ _this.reconnectStart = Date.now();
20234
+ }
20235
+
20236
+ const disconnect = duration => {
20237
+ livekitLogger.info("could not recover connection after ".concat(_this.reconnectAttempts, " attempts, ").concat(duration, "ms. giving up"));
20238
+
20239
+ _this.emit(EngineEvent.Disconnected);
20240
+
20241
+ _this.close();
20242
+ };
20243
+
20244
+ const duration = Date.now() - _this.reconnectStart;
20245
+
20246
+ const delay = _this.getNextRetryDelay({
20247
+ elapsedMs: duration,
20248
+ retryCount: _this.reconnectAttempts
20249
+ });
20250
+
20251
+ if (delay === null) {
20252
+ disconnect(duration);
20253
+ return;
19267
20254
  }
19268
20255
 
19269
- const delay = this.reconnectAttempts * this.reconnectAttempts * 300;
19270
- setTimeout(async () => {
20256
+ livekitLogger.debug("reconnecting in ".concat(delay, "ms"));
20257
+
20258
+ if (_this.reconnectTimeout) {
20259
+ clearTimeout(_this.reconnectTimeout);
20260
+ }
20261
+
20262
+ _this.reconnectTimeout = setTimeout(async () => {
19271
20263
  var _a, _b, _c;
19272
20264
 
19273
- if (this._isClosed) {
20265
+ if (_this._isClosed) {
19274
20266
  return;
19275
20267
  } // guard for attempting reconnection multiple times while one attempt is still not finished
19276
20268
 
19277
20269
 
19278
- if (this.attemptingReconnect) {
20270
+ if (_this.attemptingReconnect) {
19279
20271
  return;
19280
20272
  }
19281
20273
 
19282
20274
  if (isFireFox() || // TODO remove once clientConfiguration handles firefox case server side
19283
- ((_a = this.clientConfiguration) === null || _a === void 0 ? void 0 : _a.resumeConnection) === ClientConfigSetting.DISABLED || // signaling state could change to closed due to hardware sleep
20275
+ ((_a = _this.clientConfiguration) === null || _a === void 0 ? void 0 : _a.resumeConnection) === ClientConfigSetting.DISABLED || // signaling state could change to closed due to hardware sleep
19284
20276
  // those connections cannot be resumed
19285
- ((_c = (_b = this.primaryPC) === null || _b === void 0 ? void 0 : _b.signalingState) !== null && _c !== void 0 ? _c : 'closed') === 'closed') {
19286
- this.fullReconnectOnNext = true;
20277
+ ((_c = (_b = _this.primaryPC) === null || _b === void 0 ? void 0 : _b.signalingState) !== null && _c !== void 0 ? _c : 'closed') === 'closed') {
20278
+ _this.fullReconnectOnNext = true;
19287
20279
  }
19288
20280
 
19289
20281
  try {
19290
- this.attemptingReconnect = true;
20282
+ _this.attemptingReconnect = true;
19291
20283
 
19292
- if (this.fullReconnectOnNext) {
19293
- await this.restartConnection();
20284
+ if (_this.fullReconnectOnNext) {
20285
+ await _this.restartConnection(signalEvents);
19294
20286
  } else {
19295
- await this.resumeConnection();
20287
+ await _this.resumeConnection(signalEvents);
19296
20288
  }
19297
20289
 
19298
- this.reconnectAttempts = 0;
19299
- this.fullReconnectOnNext = false;
20290
+ _this.reconnectAttempts = 0;
20291
+ _this.fullReconnectOnNext = false;
20292
+
20293
+ if (_this.reconnectTimeout) {
20294
+ clearTimeout(_this.reconnectTimeout);
20295
+ }
19300
20296
  } catch (e) {
19301
- this.reconnectAttempts += 1;
20297
+ _this.reconnectAttempts += 1;
19302
20298
  let reconnectRequired = false;
19303
20299
  let recoverable = true;
20300
+ let requireSignalEvents = false;
19304
20301
 
19305
20302
  if (e instanceof UnexpectedConnectionState) {
19306
20303
  livekitLogger.debug('received unrecoverable error', {
@@ -19311,35 +20308,29 @@ class RTCEngine extends events.exports.EventEmitter {
19311
20308
  } else if (!(e instanceof SignalReconnectError)) {
19312
20309
  // cannot resume
19313
20310
  reconnectRequired = true;
19314
- } // when we flip from resume to reconnect, we need to reset reconnectAttempts
19315
- // this is needed to fire the right reconnecting events
19316
-
19317
-
19318
- if (reconnectRequired && !this.fullReconnectOnNext) {
19319
- this.fullReconnectOnNext = true;
19320
- this.reconnectAttempts = 0;
19321
- }
20311
+ } // when we flip from resume to reconnect
20312
+ // we need to fire the right reconnecting events
19322
20313
 
19323
- const duration = Date.now() - this.reconnectStart;
19324
20314
 
19325
- if (this.reconnectAttempts >= maxReconnectRetries || duration > maxReconnectDuration) {
19326
- recoverable = false;
20315
+ if (reconnectRequired && !_this.fullReconnectOnNext) {
20316
+ _this.fullReconnectOnNext = true;
20317
+ requireSignalEvents = true;
19327
20318
  }
19328
20319
 
19329
20320
  if (recoverable) {
19330
- this.handleDisconnect('reconnect');
20321
+ _this.handleDisconnect('reconnect', requireSignalEvents);
19331
20322
  } else {
19332
- livekitLogger.info("could not recover connection after ".concat(maxReconnectRetries, " attempts, ").concat(duration, "ms. giving up"));
19333
- this.emit(EngineEvent.Disconnected);
19334
- this.close();
20323
+ disconnect(Date.now() - _this.reconnectStart);
19335
20324
  }
19336
20325
  } finally {
19337
- this.attemptingReconnect = false;
20326
+ _this.attemptingReconnect = false;
19338
20327
  }
19339
20328
  }, delay);
19340
20329
  };
19341
20330
 
19342
20331
  this.client = new SignalClient();
20332
+ this.client.signalLatency = this.options.expSignalLatency;
20333
+ this.reconnectPolicy = (_a = this.options.reconnectPolicy) !== null && _a !== void 0 ? _a : new DefaultReconnectPolicy();
19343
20334
  }
19344
20335
 
19345
20336
  get isClosed() {
@@ -19403,12 +20394,50 @@ class RTCEngine extends events.exports.EventEmitter {
19403
20394
  throw new TrackInvalidError('a track with the same ID has already been published');
19404
20395
  }
19405
20396
 
19406
- return new Promise(resolve => {
19407
- this.pendingTrackResolvers[req.cid] = resolve;
20397
+ return new Promise((resolve, reject) => {
20398
+ const publicationTimeout = setTimeout(() => {
20399
+ delete this.pendingTrackResolvers[req.cid];
20400
+ reject(new ConnectionError('publication of local track timed out, no response from server'));
20401
+ }, 10000);
20402
+ this.pendingTrackResolvers[req.cid] = {
20403
+ resolve: info => {
20404
+ clearTimeout(publicationTimeout);
20405
+ resolve(info);
20406
+ },
20407
+ reject: () => {
20408
+ clearTimeout(publicationTimeout);
20409
+ reject('Cancelled publication by calling unpublish');
20410
+ }
20411
+ };
19408
20412
  this.client.sendAddTrack(req);
19409
20413
  });
19410
20414
  }
19411
20415
 
20416
+ removeTrack(sender) {
20417
+ var _a;
20418
+
20419
+ if (sender.track && this.pendingTrackResolvers[sender.track.id]) {
20420
+ const {
20421
+ reject
20422
+ } = this.pendingTrackResolvers[sender.track.id];
20423
+
20424
+ if (reject) {
20425
+ reject();
20426
+ }
20427
+
20428
+ delete this.pendingTrackResolvers[sender.track.id];
20429
+ }
20430
+
20431
+ try {
20432
+ (_a = this.publisher) === null || _a === void 0 ? void 0 : _a.pc.removeTrack(sender);
20433
+ } catch (e) {
20434
+ livekitLogger.warn('failed to remove track', {
20435
+ error: e,
20436
+ method: 'removeTrack'
20437
+ });
20438
+ }
20439
+ }
20440
+
19412
20441
  updateMuteStatus(trackSid, muted) {
19413
20442
  this.client.sendMuteTrack(trackSid, muted);
19414
20443
  }
@@ -19578,14 +20607,15 @@ class RTCEngine extends events.exports.EventEmitter {
19578
20607
  });
19579
20608
  await this.subscriber.setRemoteDescription(sd); // answer the offer
19580
20609
 
19581
- const answer = await this.subscriber.pc.createAnswer();
19582
- await this.subscriber.pc.setLocalDescription(answer);
20610
+ const answer = await this.subscriber.createAndSetAnswer();
19583
20611
  this.client.sendAnswer(answer);
19584
20612
  };
19585
20613
 
19586
20614
  this.client.onLocalTrackPublished = res => {
19587
20615
  livekitLogger.debug('received trackPublishedResponse', res);
19588
- const resolve = this.pendingTrackResolvers[res.cid];
20616
+ const {
20617
+ resolve
20618
+ } = this.pendingTrackResolvers[res.cid];
19589
20619
 
19590
20620
  if (!resolve) {
19591
20621
  livekitLogger.error("missing track resolver for ".concat(res.cid));
@@ -19652,7 +20682,22 @@ class RTCEngine extends events.exports.EventEmitter {
19652
20682
  this.reliableDC.onerror = this.handleDataError;
19653
20683
  }
19654
20684
 
20685
+ getNextRetryDelay(context) {
20686
+ try {
20687
+ return this.reconnectPolicy.nextRetryDelayInMs(context);
20688
+ } catch (e) {
20689
+ livekitLogger.warn('encountered error in reconnect policy', {
20690
+ error: e
20691
+ });
20692
+ } // error in user code with provided reconnect policy, stop reconnecting
20693
+
20694
+
20695
+ return null;
20696
+ }
20697
+
19655
20698
  async restartConnection() {
20699
+ let emitRestarting = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
20700
+
19656
20701
  var _a, _b;
19657
20702
 
19658
20703
  if (!this.url || !this.token) {
@@ -19662,7 +20707,7 @@ class RTCEngine extends events.exports.EventEmitter {
19662
20707
 
19663
20708
  livekitLogger.info("reconnecting, attempt: ".concat(this.reconnectAttempts));
19664
20709
 
19665
- if (this.reconnectAttempts === 0) {
20710
+ if (emitRestarting || this.reconnectAttempts === 0) {
19666
20711
  this.emit(EngineEvent.Restarting);
19667
20712
  }
19668
20713
 
@@ -19691,6 +20736,8 @@ class RTCEngine extends events.exports.EventEmitter {
19691
20736
  }
19692
20737
 
19693
20738
  async resumeConnection() {
20739
+ let emitResuming = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
20740
+
19694
20741
  var _a;
19695
20742
 
19696
20743
  if (!this.url || !this.token) {
@@ -19705,14 +20752,20 @@ class RTCEngine extends events.exports.EventEmitter {
19705
20752
 
19706
20753
  livekitLogger.info("resuming signal connection, attempt ".concat(this.reconnectAttempts));
19707
20754
 
19708
- if (this.reconnectAttempts === 0) {
20755
+ if (emitResuming || this.reconnectAttempts === 0) {
19709
20756
  this.emit(EngineEvent.Resuming);
19710
20757
  }
19711
20758
 
19712
20759
  try {
19713
20760
  await this.client.reconnect(this.url, this.token);
19714
20761
  } catch (e) {
19715
- throw new SignalReconnectError();
20762
+ let message = '';
20763
+
20764
+ if (e instanceof Error) {
20765
+ message = e.message;
20766
+ }
20767
+
20768
+ throw new SignalReconnectError(message);
19716
20769
  }
19717
20770
 
19718
20771
  this.emit(EngineEvent.SignalResumed);
@@ -19968,133 +21021,123 @@ class Room extends events.exports.EventEmitter {
19968
21021
  this.metadata = undefined;
19969
21022
  this.audioEnabled = true;
19970
21023
 
19971
- this.connect = async (url, token, opts) => {
19972
- var _a, _b, _c, _d;
19973
-
21024
+ this.connect = (url, token, opts) => {
19974
21025
  if (this.state === ConnectionState.Connected) {
19975
21026
  // when the state is reconnecting or connected, this function returns immediately
19976
21027
  livekitLogger.warn("already connected to room ".concat(this.name));
19977
- return;
21028
+ return Promise.resolve();
19978
21029
  }
19979
21030
 
19980
21031
  if (this.connectFuture) {
19981
21032
  return this.connectFuture.promise;
21033
+ } else if (this.reconnectFuture) {
21034
+ this.connectFuture = this.reconnectFuture;
21035
+ return this.connectFuture.promise;
19982
21036
  }
19983
21037
 
19984
- this.setAndEmitConnectionState(ConnectionState.Connecting);
19985
-
19986
- if (!this.abortController || this.abortController.signal.aborted) {
19987
- this.abortController = new AbortController();
19988
- } // recreate engine if previously disconnected
21038
+ const connectPromise = new Promise(async (resolve, reject) => {
21039
+ var _a, _b, _c, _d;
19989
21040
 
21041
+ this.setAndEmitConnectionState(ConnectionState.Connecting);
19990
21042
 
19991
- this.createEngine();
19992
- this.acquireAudioContext();
21043
+ if (!this.abortController || this.abortController.signal.aborted) {
21044
+ this.abortController = new AbortController();
21045
+ } // recreate engine if previously disconnected
19993
21046
 
19994
- if (opts === null || opts === void 0 ? void 0 : opts.rtcConfig) {
19995
- this.engine.rtcConfig = opts.rtcConfig;
19996
- }
19997
21047
 
19998
- this.connOptions = opts;
21048
+ this.createEngine();
21049
+ this.acquireAudioContext();
19999
21050
 
20000
- try {
20001
- const joinResponse = await this.engine.join(url, token, {
20002
- autoSubscribe: opts === null || opts === void 0 ? void 0 : opts.autoSubscribe,
20003
- publishOnly: opts === null || opts === void 0 ? void 0 : opts.publishOnly,
20004
- adaptiveStream: typeof ((_a = this.options) === null || _a === void 0 ? void 0 : _a.adaptiveStream) === 'object' ? true : (_b = this.options) === null || _b === void 0 ? void 0 : _b.adaptiveStream
20005
- }, this.abortController.signal);
20006
- livekitLogger.debug("connected to Livekit Server version: ".concat(joinResponse.serverVersion, ", region: ").concat(joinResponse.serverRegion));
20007
-
20008
- if (!joinResponse.serverVersion) {
20009
- throw new UnsupportedServer('unknown server version');
21051
+ if (opts === null || opts === void 0 ? void 0 : opts.rtcConfig) {
21052
+ this.engine.rtcConfig = opts.rtcConfig;
20010
21053
  }
20011
21054
 
20012
- if (joinResponse.serverVersion === '0.15.1' && this.options.dynacast) {
20013
- livekitLogger.debug('disabling dynacast due to server version'); // dynacast has a bug in 0.15.1, so we cannot use it then
21055
+ this.connOptions = opts;
20014
21056
 
20015
- this.options.dynacast = false;
20016
- }
20017
-
20018
- const pi = joinResponse.participant;
20019
- this.localParticipant.sid = pi.sid;
20020
- this.localParticipant.identity = pi.identity;
20021
- this.localParticipant.updateInfo(pi); // forward metadata changed for the local participant
20022
-
20023
- this.localParticipant.on(ParticipantEvent.ParticipantMetadataChanged, metadata => {
20024
- this.emit(RoomEvent.ParticipantMetadataChanged, metadata, this.localParticipant);
20025
- }).on(ParticipantEvent.TrackMuted, pub => {
20026
- this.emit(RoomEvent.TrackMuted, pub, this.localParticipant);
20027
- }).on(ParticipantEvent.TrackUnmuted, pub => {
20028
- this.emit(RoomEvent.TrackUnmuted, pub, this.localParticipant);
20029
- }).on(ParticipantEvent.LocalTrackPublished, pub => {
20030
- this.emit(RoomEvent.LocalTrackPublished, pub, this.localParticipant);
20031
- }).on(ParticipantEvent.LocalTrackUnpublished, pub => {
20032
- this.emit(RoomEvent.LocalTrackUnpublished, pub, this.localParticipant);
20033
- }).on(ParticipantEvent.ConnectionQualityChanged, quality => {
20034
- this.emit(RoomEvent.ConnectionQualityChanged, quality, this.localParticipant);
20035
- }).on(ParticipantEvent.MediaDevicesError, e => {
20036
- this.emit(RoomEvent.MediaDevicesError, e);
20037
- }).on(ParticipantEvent.ParticipantPermissionsChanged, prevPermissions => {
20038
- this.emit(RoomEvent.ParticipantPermissionsChanged, prevPermissions, this.localParticipant);
20039
- }); // populate remote participants, these should not trigger new events
20040
-
20041
- joinResponse.otherParticipants.forEach(info => {
20042
- if (info.sid !== this.localParticipant.sid && info.identity !== this.localParticipant.identity) {
20043
- this.getOrCreateParticipant(info.sid, info);
20044
- } else {
20045
- livekitLogger.warn('received info to create local participant as remote participant', {
20046
- info,
20047
- localParticipant: this.localParticipant
20048
- });
21057
+ try {
21058
+ const joinResponse = await this.engine.join(url, token, {
21059
+ autoSubscribe: opts === null || opts === void 0 ? void 0 : opts.autoSubscribe,
21060
+ publishOnly: opts === null || opts === void 0 ? void 0 : opts.publishOnly,
21061
+ adaptiveStream: typeof ((_a = this.options) === null || _a === void 0 ? void 0 : _a.adaptiveStream) === 'object' ? true : (_b = this.options) === null || _b === void 0 ? void 0 : _b.adaptiveStream
21062
+ }, this.abortController.signal);
21063
+ livekitLogger.debug("connected to Livekit Server version: ".concat(joinResponse.serverVersion, ", region: ").concat(joinResponse.serverRegion));
21064
+
21065
+ if (!joinResponse.serverVersion) {
21066
+ throw new UnsupportedServer('unknown server version');
20049
21067
  }
20050
- });
20051
- this.name = joinResponse.room.name;
20052
- this.sid = joinResponse.room.sid;
20053
- this.metadata = joinResponse.room.metadata;
20054
- this.emit(RoomEvent.SignalConnected);
20055
- } catch (err) {
20056
- this.recreateEngine();
20057
- this.setAndEmitConnectionState(ConnectionState.Disconnected, new ConnectionError('could not establish signal connection'));
20058
- throw err;
20059
- } // don't return until ICE connected
20060
-
20061
-
20062
- const connectTimeout = setTimeout(() => {
20063
- // timeout
20064
- this.recreateEngine();
20065
- this.setAndEmitConnectionState(ConnectionState.Disconnected, new ConnectionError('could not connect PeerConnection after timeout'));
20066
- }, maxICEConnectTimeout);
20067
21068
 
20068
- const abortHandler = () => {
20069
- livekitLogger.warn('closing engine');
20070
- clearTimeout(connectTimeout);
20071
- this.recreateEngine();
20072
- this.setAndEmitConnectionState(ConnectionState.Disconnected, new ConnectionError('room connection has been cancelled'));
20073
- };
21069
+ if (joinResponse.serverVersion === '0.15.1' && this.options.dynacast) {
21070
+ livekitLogger.debug('disabling dynacast due to server version'); // dynacast has a bug in 0.15.1, so we cannot use it then
20074
21071
 
20075
- if ((_c = this.abortController) === null || _c === void 0 ? void 0 : _c.signal.aborted) {
20076
- abortHandler();
20077
- }
21072
+ this.options.dynacast = false;
21073
+ }
20078
21074
 
20079
- (_d = this.abortController) === null || _d === void 0 ? void 0 : _d.signal.addEventListener('abort', abortHandler);
20080
- this.engine.once(EngineEvent.Connected, () => {
20081
- var _a, _b;
21075
+ const pi = joinResponse.participant;
21076
+ this.localParticipant.sid = pi.sid;
21077
+ this.localParticipant.identity = pi.identity;
21078
+ this.localParticipant.updateInfo(pi); // forward metadata changed for the local participant
20082
21079
 
20083
- clearTimeout(connectTimeout);
20084
- (_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.removeEventListener('abort', abortHandler); // also hook unload event
21080
+ this.localParticipant.on(ParticipantEvent.ParticipantMetadataChanged, this.onLocalParticipantMetadataChanged).on(ParticipantEvent.TrackMuted, this.onLocalTrackMuted).on(ParticipantEvent.TrackUnmuted, this.onLocalTrackUnmuted).on(ParticipantEvent.LocalTrackPublished, this.onLocalTrackPublished).on(ParticipantEvent.LocalTrackUnpublished, this.onLocalTrackUnpublished).on(ParticipantEvent.ConnectionQualityChanged, this.onLocalConnectionQualityChanged).on(ParticipantEvent.MediaDevicesError, this.onMediaDevicesError).on(ParticipantEvent.ParticipantPermissionsChanged, this.onLocalParticipantPermissionsChanged); // populate remote participants, these should not trigger new events
20085
21081
 
20086
- if (isWeb()) {
20087
- window.addEventListener('beforeunload', this.onBeforeUnload);
20088
- (_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.addEventListener('devicechange', this.handleDeviceChange);
21082
+ joinResponse.otherParticipants.forEach(info => {
21083
+ if (info.sid !== this.localParticipant.sid && info.identity !== this.localParticipant.identity) {
21084
+ this.getOrCreateParticipant(info.sid, info);
21085
+ } else {
21086
+ livekitLogger.warn('received info to create local participant as remote participant', {
21087
+ info,
21088
+ localParticipant: this.localParticipant
21089
+ });
21090
+ }
21091
+ });
21092
+ this.name = joinResponse.room.name;
21093
+ this.sid = joinResponse.room.sid;
21094
+ this.metadata = joinResponse.room.metadata;
21095
+ this.emit(RoomEvent.SignalConnected);
21096
+ } catch (err) {
21097
+ this.recreateEngine();
21098
+ this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
21099
+ reject(new ConnectionError('could not establish signal connection'));
21100
+ } // don't return until ICE connected
21101
+
21102
+
21103
+ const connectTimeout = setTimeout(() => {
21104
+ // timeout
21105
+ this.recreateEngine();
21106
+ this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
21107
+ reject(new ConnectionError('could not connect PeerConnection after timeout'));
21108
+ }, maxICEConnectTimeout);
21109
+
21110
+ const abortHandler = () => {
21111
+ livekitLogger.warn('closing engine');
21112
+ clearTimeout(connectTimeout);
21113
+ this.recreateEngine();
21114
+ this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
21115
+ reject(new ConnectionError('room connection has been cancelled'));
21116
+ };
21117
+
21118
+ if ((_c = this.abortController) === null || _c === void 0 ? void 0 : _c.signal.aborted) {
21119
+ abortHandler();
20089
21120
  }
20090
21121
 
20091
- this.setAndEmitConnectionState(ConnectionState.Connected);
20092
- });
21122
+ (_d = this.abortController) === null || _d === void 0 ? void 0 : _d.signal.addEventListener('abort', abortHandler);
21123
+ this.engine.once(EngineEvent.Connected, () => {
21124
+ var _a, _b;
20093
21125
 
20094
- if (this.connectFuture) {
20095
- /** @ts-ignore */
20096
- return this.connectFuture.promise;
20097
- }
21126
+ clearTimeout(connectTimeout);
21127
+ (_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.removeEventListener('abort', abortHandler); // also hook unload event
21128
+
21129
+ if (isWeb()) {
21130
+ window.addEventListener('beforeunload', this.onBeforeUnload);
21131
+ (_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.addEventListener('devicechange', this.handleDeviceChange);
21132
+ }
21133
+
21134
+ this.setAndEmitConnectionState(ConnectionState.Connected);
21135
+ resolve();
21136
+ });
21137
+ });
21138
+ this.connectFuture = new Future(connectPromise);
21139
+ this.connectFuture.promise.finally(() => this.connectFuture = undefined);
21140
+ return this.connectFuture.promise;
20098
21141
  };
20099
21142
  /**
20100
21143
  * disconnects the room, emits [[RoomEvent.Disconnected]]
@@ -20104,21 +21147,23 @@ class Room extends events.exports.EventEmitter {
20104
21147
  this.disconnect = async function () {
20105
21148
  let stopTracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
20106
21149
 
20107
- var _a, _b;
21150
+ var _a, _b, _c;
20108
21151
 
20109
21152
  livekitLogger.info('disconnect from room', {
20110
21153
  identity: _this.localParticipant.identity
20111
21154
  });
20112
21155
 
20113
- if (_this.state === ConnectionState.Connecting) {
21156
+ if (_this.state === ConnectionState.Connecting || _this.state === ConnectionState.Reconnecting) {
20114
21157
  // try aborting pending connection attempt
20115
21158
  livekitLogger.warn('abort connection attempt');
20116
- (_a = _this.abortController) === null || _a === void 0 ? void 0 : _a.abort();
20117
- return;
21159
+ (_a = _this.abortController) === null || _a === void 0 ? void 0 : _a.abort(); // in case the abort controller didn't manage to cancel the connection attempt, reject the connect promise explicitly
21160
+
21161
+ (_b = _this.connectFuture) === null || _b === void 0 ? void 0 : _b.reject(new ConnectionError('Client initiated disconnect'));
21162
+ _this.connectFuture = undefined;
20118
21163
  } // send leave
20119
21164
 
20120
21165
 
20121
- if ((_b = _this.engine) === null || _b === void 0 ? void 0 : _b.client.isConnected) {
21166
+ if ((_c = _this.engine) === null || _c === void 0 ? void 0 : _c.client.isConnected) {
20122
21167
  await _this.engine.client.sendLeave();
20123
21168
  } // close engine (also closes client)
20124
21169
 
@@ -20139,7 +21184,11 @@ class Room extends events.exports.EventEmitter {
20139
21184
  };
20140
21185
 
20141
21186
  this.handleRestarting = () => {
20142
- // also unwind existing participants & existing subscriptions
21187
+ if (!this.reconnectFuture) {
21188
+ this.reconnectFuture = new Future();
21189
+ } // also unwind existing participants & existing subscriptions
21190
+
21191
+
20143
21192
  for (const p of this.participants.values()) {
20144
21193
  this.handleParticipantDisconnected(p.sid, p);
20145
21194
  }
@@ -20150,11 +21199,15 @@ class Room extends events.exports.EventEmitter {
20150
21199
  };
20151
21200
 
20152
21201
  this.handleRestarted = async joinResponse => {
21202
+ var _a;
21203
+
20153
21204
  livekitLogger.debug("reconnected to server", {
20154
21205
  region: joinResponse.serverRegion
20155
21206
  });
20156
21207
  this.setAndEmitConnectionState(ConnectionState.Connected);
20157
- this.emit(RoomEvent.Reconnected); // rehydrate participants
21208
+ this.emit(RoomEvent.Reconnected);
21209
+ (_a = this.reconnectFuture) === null || _a === void 0 ? void 0 : _a.resolve();
21210
+ this.reconnectFuture = undefined; // rehydrate participants
20158
21211
 
20159
21212
  if (joinResponse.participant) {
20160
21213
  // with a restart, the sid will have changed, we'll map our understanding to it
@@ -20379,6 +21432,38 @@ class Room extends events.exports.EventEmitter {
20379
21432
  });
20380
21433
  };
20381
21434
 
21435
+ this.onLocalParticipantMetadataChanged = metadata => {
21436
+ this.emit(RoomEvent.ParticipantMetadataChanged, metadata, this.localParticipant);
21437
+ };
21438
+
21439
+ this.onLocalTrackMuted = pub => {
21440
+ this.emit(RoomEvent.TrackMuted, pub, this.localParticipant);
21441
+ };
21442
+
21443
+ this.onLocalTrackUnmuted = pub => {
21444
+ this.emit(RoomEvent.TrackUnmuted, pub, this.localParticipant);
21445
+ };
21446
+
21447
+ this.onLocalTrackPublished = pub => {
21448
+ this.emit(RoomEvent.LocalTrackPublished, pub, this.localParticipant);
21449
+ };
21450
+
21451
+ this.onLocalTrackUnpublished = pub => {
21452
+ this.emit(RoomEvent.LocalTrackUnpublished, pub, this.localParticipant);
21453
+ };
21454
+
21455
+ this.onLocalConnectionQualityChanged = quality => {
21456
+ this.emit(RoomEvent.ConnectionQualityChanged, quality, this.localParticipant);
21457
+ };
21458
+
21459
+ this.onMediaDevicesError = e => {
21460
+ this.emit(RoomEvent.MediaDevicesError, e);
21461
+ };
21462
+
21463
+ this.onLocalParticipantPermissionsChanged = prevPermissions => {
21464
+ this.emit(RoomEvent.ParticipantPermissionsChanged, prevPermissions, this.localParticipant);
21465
+ };
21466
+
20382
21467
  this.participants = new Map();
20383
21468
  this.identityToSid = new Map();
20384
21469
  this.options = options || {};
@@ -20394,8 +21479,7 @@ class Room extends events.exports.EventEmitter {
20394
21479
  return;
20395
21480
  }
20396
21481
 
20397
- this.engine = new RTCEngine();
20398
- this.engine.client.signalLatency = this.options.expSignalLatency;
21482
+ this.engine = new RTCEngine(this.options);
20399
21483
  this.engine.client.onParticipantUpdate = this.handleParticipantUpdates;
20400
21484
  this.engine.client.onRoomUpdate = this.handleRoomUpdate;
20401
21485
  this.engine.client.onSpeakersChanged = this.handleSpeakersChanged;
@@ -20407,11 +21491,19 @@ class Room extends events.exports.EventEmitter {
20407
21491
  }).on(EngineEvent.Disconnected, reason => {
20408
21492
  this.handleDisconnect(this.options.stopLocalTrackOnUnpublish, reason);
20409
21493
  }).on(EngineEvent.ActiveSpeakersUpdate, this.handleActiveSpeakersUpdate).on(EngineEvent.DataPacketReceived, this.handleDataPacket).on(EngineEvent.Resuming, () => {
21494
+ if (!this.reconnectFuture) {
21495
+ this.reconnectFuture = new Future();
21496
+ }
21497
+
20410
21498
  if (this.setAndEmitConnectionState(ConnectionState.Reconnecting)) {
20411
21499
  this.emit(RoomEvent.Reconnecting);
20412
21500
  }
20413
21501
  }).on(EngineEvent.Resumed, () => {
21502
+ var _a;
21503
+
20414
21504
  this.setAndEmitConnectionState(ConnectionState.Connected);
21505
+ (_a = this.reconnectFuture) === null || _a === void 0 ? void 0 : _a.resolve();
21506
+ this.reconnectFuture = undefined;
20415
21507
  this.emit(RoomEvent.Reconnected);
20416
21508
  this.updateSubscriptions();
20417
21509
  }).on(EngineEvent.SignalResumed, () => {
@@ -20665,10 +21757,17 @@ class Room extends events.exports.EventEmitter {
20665
21757
  let shouldStopTracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
20666
21758
  let reason = arguments.length > 1 ? arguments[1] : undefined;
20667
21759
 
20668
- var _a;
21760
+ var _a, _b;
20669
21761
 
20670
21762
  if (this.state === ConnectionState.Disconnected) {
20671
21763
  return;
21764
+ } // reject potentially ongoing reconnection attempt
21765
+
21766
+
21767
+ if (this.connectFuture === this.reconnectFuture) {
21768
+ (_a = this.connectFuture) === null || _a === void 0 ? void 0 : _a.reject(undefined);
21769
+ this.connectFuture = undefined;
21770
+ this.reconnectFuture = undefined;
20672
21771
  }
20673
21772
 
20674
21773
  this.participants.forEach(p => {
@@ -20676,6 +21775,7 @@ class Room extends events.exports.EventEmitter {
20676
21775
  p.unpublishTrack(pub.trackSid);
20677
21776
  });
20678
21777
  });
21778
+ this.localParticipant.off(ParticipantEvent.ParticipantMetadataChanged, this.onLocalParticipantMetadataChanged).off(ParticipantEvent.TrackMuted, this.onLocalTrackMuted).off(ParticipantEvent.TrackUnmuted, this.onLocalTrackUnmuted).off(ParticipantEvent.LocalTrackPublished, this.onLocalTrackPublished).off(ParticipantEvent.LocalTrackUnpublished, this.onLocalTrackUnpublished).off(ParticipantEvent.ConnectionQualityChanged, this.onLocalConnectionQualityChanged).off(ParticipantEvent.MediaDevicesError, this.onMediaDevicesError).off(ParticipantEvent.ParticipantPermissionsChanged, this.onLocalParticipantPermissionsChanged);
20679
21779
  this.localParticipant.tracks.forEach(pub => {
20680
21780
  var _a, _b;
20681
21781
 
@@ -20701,7 +21801,7 @@ class Room extends events.exports.EventEmitter {
20701
21801
 
20702
21802
  if (isWeb()) {
20703
21803
  window.removeEventListener('beforeunload', this.onBeforeUnload);
20704
- (_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.removeEventListener('devicechange', this.handleDeviceChange);
21804
+ (_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.removeEventListener('devicechange', this.handleDeviceChange);
20705
21805
  }
20706
21806
 
20707
21807
  this.setAndEmitConnectionState(ConnectionState.Disconnected);
@@ -20856,41 +21956,12 @@ class Room extends events.exports.EventEmitter {
20856
21956
  }
20857
21957
  }
20858
21958
 
20859
- setAndEmitConnectionState(state, error) {
21959
+ setAndEmitConnectionState(state) {
20860
21960
  if (state === this.state) {
20861
21961
  // unchanged
20862
21962
  return false;
20863
21963
  }
20864
21964
 
20865
- switch (state) {
20866
- case ConnectionState.Connecting:
20867
- case ConnectionState.Reconnecting:
20868
- if (!this.connectFuture) {
20869
- // reuse existing connect future if possible
20870
- this.connectFuture = new Future();
20871
- }
20872
-
20873
- break;
20874
-
20875
- case ConnectionState.Connected:
20876
- if (this.connectFuture) {
20877
- this.connectFuture.resolve();
20878
- this.connectFuture = undefined;
20879
- }
20880
-
20881
- break;
20882
-
20883
- case ConnectionState.Disconnected:
20884
- if (this.connectFuture) {
20885
- error !== null && error !== void 0 ? error : error = new Error('disconnected from Room');
20886
- this.connectFuture.reject(error);
20887
- this.connectFuture = undefined;
20888
- }
20889
-
20890
- break;
20891
-
20892
- }
20893
-
20894
21965
  this.state = state;
20895
21966
  this.emit(RoomEvent.ConnectionStateChanged, this.state);
20896
21967
  return true;
@@ -20938,8 +22009,22 @@ async function createLocalTracks(options) {
20938
22009
  (_a = options.audio) !== null && _a !== void 0 ? _a : options.audio = true;
20939
22010
  (_b = options.video) !== null && _b !== void 0 ? _b : options.video = true;
20940
22011
  const opts = mergeDefaultOptions(options, audioDefaults, videoDefaults);
20941
- const constraints = constraintsForOptions(opts);
20942
- const stream = await navigator.mediaDevices.getUserMedia(constraints);
22012
+ const constraints = constraintsForOptions(opts); // Keep a reference to the promise on DeviceManager and await it in getLocalDevices()
22013
+ // works around iOS Safari Bug https://bugs.webkit.org/show_bug.cgi?id=179363
22014
+
22015
+ const mediaPromise = navigator.mediaDevices.getUserMedia(constraints);
22016
+
22017
+ if (options.audio) {
22018
+ DeviceManager.userMediaPromiseMap.set('audioinput', mediaPromise);
22019
+ mediaPromise.catch(() => DeviceManager.userMediaPromiseMap.delete('audioinput'));
22020
+ }
22021
+
22022
+ if (options.video) {
22023
+ DeviceManager.userMediaPromiseMap.set('videoinput', mediaPromise);
22024
+ mediaPromise.catch(() => DeviceManager.userMediaPromiseMap.delete('videoinput'));
22025
+ }
22026
+
22027
+ const stream = await mediaPromise;
20943
22028
  return stream.getTracks().map(mediaStreamTrack => {
20944
22029
  const isAudio = mediaStreamTrack.kind === 'audio';
20945
22030
  isAudio ? options.audio : options.video;
@@ -21033,5 +22118,5 @@ async function createLocalScreenTracks(options) {
21033
22118
  return localTracks;
21034
22119
  }
21035
22120
 
21036
- export { AudioPresets, ConnectionError, ConnectionQuality, ConnectionState, DataPacket_Kind, DisconnectReason, EngineEvent, LivekitError, LocalAudioTrack, LocalParticipant, LocalTrack, LocalTrackPublication, LocalVideoTrack, LogLevel, MediaDeviceFailure, Participant, ParticipantEvent, PublishDataError, RemoteAudioTrack, RemoteParticipant, RemoteTrack, RemoteTrackPublication, RemoteVideoTrack, Room, RoomEvent, RoomState, ScreenSharePresets, Track, TrackEvent, TrackInvalidError, TrackPublication, UnexpectedConnectionState, UnsupportedServer, VideoPreset, VideoPresets, VideoPresets43, VideoQuality, attachToElement, createLocalAudioTrack, createLocalScreenTracks, createLocalTracks, createLocalVideoTrack, detachTrack, getEmptyAudioStreamTrack, getEmptyVideoStreamTrack, protocolVersion, setLogExtension, setLogLevel, version };
22121
+ export { AudioPresets, ConnectionError, ConnectionQuality, ConnectionState, DataPacket_Kind, DefaultReconnectPolicy, DisconnectReason, EngineEvent, LivekitError, LocalAudioTrack, LocalParticipant, LocalTrack, LocalTrackPublication, LocalVideoTrack, LogLevel, MediaDeviceFailure, Participant, ParticipantEvent, PublishDataError, RemoteAudioTrack, RemoteParticipant, RemoteTrack, RemoteTrackPublication, RemoteVideoTrack, Room, RoomEvent, RoomState, ScreenSharePresets, Track, TrackEvent, TrackInvalidError, TrackPublication, UnexpectedConnectionState, UnsupportedServer, VideoPreset, VideoPresets, VideoPresets43, VideoQuality, attachToElement, createLocalAudioTrack, createLocalScreenTracks, createLocalTracks, createLocalVideoTrack, detachTrack, getEmptyAudioStreamTrack, getEmptyVideoStreamTrack, protocolVersion, setLogExtension, setLogLevel, version };
21037
22122
  //# sourceMappingURL=livekit-client.esm.mjs.map