livekit-client 2.6.2 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10401,10 +10401,11 @@ var ConnectionErrorReason;
10401
10401
  ConnectionErrorReason[ConnectionErrorReason["LeaveRequest"] = 4] = "LeaveRequest";
10402
10402
  })(ConnectionErrorReason || (ConnectionErrorReason = {}));
10403
10403
  class ConnectionError extends LivekitError {
10404
- constructor(message, reason, status) {
10404
+ constructor(message, reason, status, context) {
10405
10405
  super(1, message);
10406
10406
  this.status = status;
10407
10407
  this.reason = reason;
10408
+ this.context = context;
10408
10409
  }
10409
10410
  }
10410
10411
  class DeviceUnsupportedError extends LivekitError {
@@ -11176,7 +11177,7 @@ function getOSVersion(ua) {
11176
11177
  return ua.includes('mac os') ? getMatch(/\(.+?(\d+_\d+(:?_\d+)?)/, ua, 1).replace(/_/g, '.') : undefined;
11177
11178
  }
11178
11179
 
11179
- var version$1 = "2.6.2";
11180
+ var version$1 = "2.7.0";
11180
11181
 
11181
11182
  const version = version$1;
11182
11183
  const protocolVersion = 15;
@@ -12321,6 +12322,20 @@ function extractChatMessage(msg) {
12321
12322
  message
12322
12323
  };
12323
12324
  }
12325
+ function getDisconnectReasonFromConnectionError(e) {
12326
+ switch (e.reason) {
12327
+ case ConnectionErrorReason.LeaveRequest:
12328
+ return e.context;
12329
+ case ConnectionErrorReason.Cancelled:
12330
+ return DisconnectReason.CLIENT_INITIATED;
12331
+ case ConnectionErrorReason.NotAllowed:
12332
+ return DisconnectReason.USER_REJECTED;
12333
+ case ConnectionErrorReason.ServerUnreachable:
12334
+ return DisconnectReason.JOIN_FAILURE;
12335
+ default:
12336
+ return DisconnectReason.UNKNOWN_REASON;
12337
+ }
12338
+ }
12324
12339
 
12325
12340
  const defaultId = 'default';
12326
12341
  class DeviceManager {
@@ -13470,7 +13485,7 @@ class SignalClient {
13470
13485
  shouldProcessMessage = true;
13471
13486
  }
13472
13487
  } else if (this.isEstablishingConnection && resp.message.case === 'leave') {
13473
- reject(new ConnectionError('Received leave request while trying to (re)connect', ConnectionErrorReason.LeaveRequest));
13488
+ reject(new ConnectionError('Received leave request while trying to (re)connect', ConnectionErrorReason.LeaveRequest, undefined, resp.message.value.reason));
13474
13489
  } else if (!opts.reconnect) {
13475
13490
  // non-reconnect case, should receive join response first
13476
13491
  reject(new ConnectionError("did not receive join response, got ".concat((_c = resp.message) === null || _c === void 0 ? void 0 : _c.case, " instead"), ConnectionErrorReason.InternalError));
@@ -15201,7 +15216,8 @@ const publishDefaults = {
15201
15216
  const audioDefaults = {
15202
15217
  autoGainControl: true,
15203
15218
  echoCancellation: true,
15204
- noiseSuppression: true
15219
+ noiseSuppression: true,
15220
+ voiceIsolation: true
15205
15221
  };
15206
15222
  const videoDefaults = {
15207
15223
  resolution: VideoPresets.h720.resolution
@@ -18562,23 +18578,25 @@ class HTMLElementInfo {
18562
18578
  } = entry;
18563
18579
  if (target === this.element) {
18564
18580
  this.isIntersecting = isIntersecting;
18581
+ this.isPiP = isElementInPiP(this.element);
18565
18582
  this.visibilityChangedAt = Date.now();
18566
18583
  (_a = this.handleVisibilityChanged) === null || _a === void 0 ? void 0 : _a.call(this);
18567
18584
  }
18568
18585
  };
18569
18586
  this.onEnterPiP = () => {
18570
- var _a;
18571
- this.isPiP = true;
18572
- (_a = this.handleVisibilityChanged) === null || _a === void 0 ? void 0 : _a.call(this);
18587
+ var _a, _b, _c;
18588
+ (_b = (_a = window.documentPictureInPicture) === null || _a === void 0 ? void 0 : _a.window) === null || _b === void 0 ? void 0 : _b.addEventListener('pagehide', this.onLeavePiP);
18589
+ this.isPiP = isElementInPiP(this.element);
18590
+ (_c = this.handleVisibilityChanged) === null || _c === void 0 ? void 0 : _c.call(this);
18573
18591
  };
18574
18592
  this.onLeavePiP = () => {
18575
18593
  var _a;
18576
- this.isPiP = false;
18594
+ this.isPiP = isElementInPiP(this.element);
18577
18595
  (_a = this.handleVisibilityChanged) === null || _a === void 0 ? void 0 : _a.call(this);
18578
18596
  };
18579
18597
  this.element = element;
18580
18598
  this.isIntersecting = visible !== null && visible !== void 0 ? visible : isElementInViewport(element);
18581
- this.isPiP = isWeb() && document.pictureInPictureElement === element;
18599
+ this.isPiP = isWeb() && isElementInPiP(element);
18582
18600
  this.visibilityChangedAt = 0;
18583
18601
  }
18584
18602
  width() {
@@ -18588,9 +18606,10 @@ class HTMLElementInfo {
18588
18606
  return this.element.clientHeight;
18589
18607
  }
18590
18608
  observe() {
18609
+ var _a, _b, _c;
18591
18610
  // make sure we update the current visible state once we start to observe
18592
18611
  this.isIntersecting = isElementInViewport(this.element);
18593
- this.isPiP = document.pictureInPictureElement === this.element;
18612
+ this.isPiP = isElementInPiP(this.element);
18594
18613
  this.element.handleResize = () => {
18595
18614
  var _a;
18596
18615
  (_a = this.handleResize) === null || _a === void 0 ? void 0 : _a.call(this);
@@ -18600,17 +18619,30 @@ class HTMLElementInfo {
18600
18619
  getResizeObserver().observe(this.element);
18601
18620
  this.element.addEventListener('enterpictureinpicture', this.onEnterPiP);
18602
18621
  this.element.addEventListener('leavepictureinpicture', this.onLeavePiP);
18622
+ (_a = window.documentPictureInPicture) === null || _a === void 0 ? void 0 : _a.addEventListener('enter', this.onEnterPiP);
18623
+ (_c = (_b = window.documentPictureInPicture) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.addEventListener('pagehide', this.onLeavePiP);
18603
18624
  }
18604
18625
  stopObserving() {
18605
- var _a, _b;
18626
+ var _a, _b, _c, _d, _e;
18606
18627
  (_a = getIntersectionObserver()) === null || _a === void 0 ? void 0 : _a.unobserve(this.element);
18607
18628
  (_b = getResizeObserver()) === null || _b === void 0 ? void 0 : _b.unobserve(this.element);
18608
18629
  this.element.removeEventListener('enterpictureinpicture', this.onEnterPiP);
18609
18630
  this.element.removeEventListener('leavepictureinpicture', this.onLeavePiP);
18631
+ (_c = window.documentPictureInPicture) === null || _c === void 0 ? void 0 : _c.removeEventListener('enter', this.onEnterPiP);
18632
+ (_e = (_d = window.documentPictureInPicture) === null || _d === void 0 ? void 0 : _d.window) === null || _e === void 0 ? void 0 : _e.removeEventListener('pagehide', this.onLeavePiP);
18610
18633
  }
18611
18634
  }
18612
- // does not account for occlusion by other elements
18613
- function isElementInViewport(el) {
18635
+ function isElementInPiP(el) {
18636
+ var _a, _b;
18637
+ // Simple video PiP
18638
+ if (document.pictureInPictureElement === el) return true;
18639
+ // Document PiP
18640
+ if ((_a = window.documentPictureInPicture) === null || _a === void 0 ? void 0 : _a.window) return isElementInViewport(el, (_b = window.documentPictureInPicture) === null || _b === void 0 ? void 0 : _b.window);
18641
+ return false;
18642
+ }
18643
+ // does not account for occlusion by other elements or opacity property
18644
+ function isElementInViewport(el, win) {
18645
+ const viewportWindow = win || window;
18614
18646
  let top = el.offsetTop;
18615
18647
  let left = el.offsetLeft;
18616
18648
  const width = el.offsetWidth;
@@ -18619,7 +18651,6 @@ function isElementInViewport(el) {
18619
18651
  hidden
18620
18652
  } = el;
18621
18653
  const {
18622
- opacity,
18623
18654
  display
18624
18655
  } = getComputedStyle(el);
18625
18656
  while (el.offsetParent) {
@@ -18627,7 +18658,7 @@ function isElementInViewport(el) {
18627
18658
  top += el.offsetTop;
18628
18659
  left += el.offsetLeft;
18629
18660
  }
18630
- return top < window.pageYOffset + window.innerHeight && left < window.pageXOffset + window.innerWidth && top + height > window.pageYOffset && left + width > window.pageXOffset && !hidden && (opacity !== '' ? parseFloat(opacity) > 0 : true) && display !== 'none';
18661
+ return top < viewportWindow.pageYOffset + viewportWindow.innerHeight && left < viewportWindow.pageXOffset + viewportWindow.innerWidth && top + height > viewportWindow.pageYOffset && left + width > viewportWindow.pageXOffset && !hidden && display !== 'none';
18631
18662
  }
18632
18663
 
18633
18664
  class TrackPublication extends eventsExports.EventEmitter {
@@ -21406,11 +21437,15 @@ class Room extends eventsExports.EventEmitter {
21406
21437
  this.recreateEngine();
21407
21438
  yield connectFn(resolve, reject, nextUrl);
21408
21439
  } else {
21409
- this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
21440
+ this.handleDisconnect(this.options.stopLocalTrackOnUnpublish, getDisconnectReasonFromConnectionError(e));
21410
21441
  reject(e);
21411
21442
  }
21412
21443
  } else {
21413
- this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
21444
+ let disconnectReason = DisconnectReason.UNKNOWN_REASON;
21445
+ if (e instanceof ConnectionError) {
21446
+ disconnectReason = getDisconnectReasonFromConnectionError(e);
21447
+ }
21448
+ this.handleDisconnect(this.options.stopLocalTrackOnUnpublish, disconnectReason);
21414
21449
  reject(e);
21415
21450
  }
21416
21451
  }