livekit-client 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ import LocalVideoTrack from './room/track/LocalVideoTrack';
12
12
  import RemoteAudioTrack from './room/track/RemoteAudioTrack';
13
13
  import RemoteTrack from './room/track/RemoteTrack';
14
14
  import RemoteTrackPublication from './room/track/RemoteTrackPublication';
15
- import RemoteVideoTrack from './room/track/RemoteVideoTrack';
15
+ import RemoteVideoTrack, { ElementInfo } from './room/track/RemoteVideoTrack';
16
16
  import { TrackPublication } from './room/track/TrackPublication';
17
17
  export * from './options';
18
18
  export * from './room/errors';
@@ -22,5 +22,5 @@ export * from './room/track/options';
22
22
  export * from './room/track/Track';
23
23
  export * from './room/track/types';
24
24
  export * from './version';
25
- export { setLogLevel, setLogExtension, LogLevel, Room, ConnectionState, RoomState, DataPacket_Kind, Participant, RemoteParticipant, LocalParticipant, LocalAudioTrack, LocalVideoTrack, LocalTrack, LocalTrackPublication, RemoteTrack, RemoteAudioTrack, RemoteVideoTrack, RemoteTrackPublication, ParticipantTrackPermission, TrackPublication, VideoQuality, ConnectionQuality, };
25
+ export { setLogLevel, setLogExtension, LogLevel, Room, ConnectionState, RoomState, DataPacket_Kind, Participant, RemoteParticipant, LocalParticipant, LocalAudioTrack, LocalVideoTrack, LocalTrack, LocalTrackPublication, RemoteTrack, RemoteAudioTrack, RemoteVideoTrack, RemoteTrackPublication, ParticipantTrackPermission, TrackPublication, VideoQuality, ConnectionQuality, ElementInfo, };
26
26
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,wBAAwB,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AChB,sBAAsB,EACtB,0BAA0B,EAC1B,gBAAgB,EAChB,YAAY,EACZ,iBAAiB,EACjB,WAAW,GACZ,CAAC"}
@@ -9779,7 +9779,7 @@ class DeviceManager {
9779
9779
  }
9780
9780
  DeviceManager.mediaDeviceKinds = ['audioinput', 'audiooutput', 'videoinput'];
9781
9781
 
9782
- const version = '1.0.0';
9782
+ const version = '1.0.1';
9783
9783
  const protocolVersion = 7;
9784
9784
 
9785
9785
  const separator = '|';
@@ -10332,6 +10332,7 @@ function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
10332
10332
  }
10333
10333
  }
10334
10334
 
10335
+ const BACKGROUND_REACTION_DELAY = 5000; // keep old audio elements when detached, we would re-use them since on iOS
10335
10336
  // Safari tracks which audio elements have been "blessed" by the user.
10336
10337
 
10337
10338
  const recycledElements = [];
@@ -10343,7 +10344,17 @@ class Track extends events.exports.EventEmitter {
10343
10344
  this._currentBitrate = 0;
10344
10345
 
10345
10346
  this.appVisibilityChangedListener = () => {
10346
- this.handleAppVisibilityChanged();
10347
+ if (this.backgroundTimeout) {
10348
+ clearTimeout(this.backgroundTimeout);
10349
+ } // delay app visibility update if it goes to hidden
10350
+ // update immediately if it comes back to focus
10351
+
10352
+
10353
+ if (document.visibilityState === 'hidden') {
10354
+ this.backgroundTimeout = setTimeout(() => this.handleAppVisibilityChanged(), BACKGROUND_REACTION_DELAY);
10355
+ } else {
10356
+ this.handleAppVisibilityChanged();
10357
+ }
10347
10358
  };
10348
10359
 
10349
10360
  this.kind = kind;
@@ -11252,7 +11263,7 @@ class LocalVideoTrack extends LocalTrack {
11252
11263
  bytesSent: v.bytesSent,
11253
11264
  framesSent: v.framesSent,
11254
11265
  timestamp: v.timestamp,
11255
- rid: (_a = v.rid) !== null && _a !== void 0 ? _a : '',
11266
+ rid: (_a = v.rid) !== null && _a !== void 0 ? _a : v.id,
11256
11267
  retransmittedPacketsSent: v.retransmittedPacketsSent,
11257
11268
  qualityLimitationReason: v.qualityLimitationReason,
11258
11269
  qualityLimitationResolutionChanges: v.qualityLimitationResolutionChanges
@@ -11657,21 +11668,6 @@ class RemoteVideoTrack extends RemoteTrack {
11657
11668
  }, monitorFrequency);
11658
11669
  };
11659
11670
 
11660
- this.handleVisibilityChanged = entry => {
11661
- const {
11662
- target,
11663
- isIntersecting
11664
- } = entry;
11665
- const elementInfo = this.elementInfos.find(info => info.element === target);
11666
-
11667
- if (elementInfo) {
11668
- elementInfo.visible = isIntersecting;
11669
- elementInfo.visibilityChangedAt = Date.now();
11670
- }
11671
-
11672
- this.updateVisibility();
11673
- };
11674
-
11675
11671
  this.debouncedHandleResize = r(() => {
11676
11672
  this.updateDimensions();
11677
11673
  }, REACTION_DELAY);
@@ -11718,23 +11714,55 @@ class RemoteVideoTrack extends RemoteTrack {
11718
11714
 
11719
11715
 
11720
11716
  if (this.adaptiveStreamSettings && this.elementInfos.find(info => info.element === element) === undefined) {
11721
- this.elementInfos.push({
11722
- element,
11723
- visible: true // default visible
11717
+ const elementInfo = new HTMLElementInfo(element);
11718
+ this.observeElementInfo(elementInfo);
11719
+ }
11724
11720
 
11725
- });
11726
- element.handleResize = this.debouncedHandleResize;
11727
- element.handleVisibilityChanged = this.handleVisibilityChanged;
11728
- getIntersectionObserver().observe(element);
11729
- getResizeObserver().observe(element); // trigger the first resize update cycle
11721
+ this.hasUsedAttach = true;
11722
+ return element;
11723
+ }
11724
+ /**
11725
+ * Observe an ElementInfo for changes when adaptive streaming.
11726
+ * @param elementInfo
11727
+ * @internal
11728
+ */
11729
+
11730
+
11731
+ observeElementInfo(elementInfo) {
11732
+ if (this.adaptiveStreamSettings && this.elementInfos.find(info => info === elementInfo) === undefined) {
11733
+ elementInfo.handleResize = () => {
11734
+ this.debouncedHandleResize();
11735
+ };
11736
+
11737
+ elementInfo.handleVisibilityChanged = () => {
11738
+ this.updateVisibility();
11739
+ };
11740
+
11741
+ this.elementInfos.push(elementInfo);
11742
+ elementInfo.observe(); // trigger the first resize update cycle
11730
11743
  // if the tab is backgrounded, the initial resize event does not fire until
11731
11744
  // the tab comes into focus for the first time.
11732
11745
 
11733
11746
  this.debouncedHandleResize();
11747
+ this.updateVisibility();
11734
11748
  }
11749
+ }
11750
+ /**
11751
+ * Stop observing an ElementInfo for changes.
11752
+ * @param elementInfo
11753
+ * @internal
11754
+ */
11735
11755
 
11736
- this.hasUsedAttach = true;
11737
- return element;
11756
+
11757
+ stopObservingElementInfo(elementInfo) {
11758
+ const stopElementInfos = this.elementInfos.filter(info => info === elementInfo);
11759
+
11760
+ for (const info of stopElementInfos) {
11761
+ info.stopObserving();
11762
+ }
11763
+
11764
+ this.elementInfos = this.elementInfos.filter(info => info !== elementInfo);
11765
+ this.updateVisibility();
11738
11766
  }
11739
11767
 
11740
11768
  detach(element) {
@@ -11785,24 +11813,28 @@ class RemoteVideoTrack extends RemoteTrack {
11785
11813
  }
11786
11814
 
11787
11815
  stopObservingElement(element) {
11788
- var _a, _b;
11816
+ const stopElementInfos = this.elementInfos.filter(info => info.element === element);
11817
+
11818
+ for (const info of stopElementInfos) {
11819
+ info.stopObserving();
11820
+ }
11789
11821
 
11790
- (_a = getIntersectionObserver()) === null || _a === void 0 ? void 0 : _a.unobserve(element);
11791
- (_b = getResizeObserver()) === null || _b === void 0 ? void 0 : _b.unobserve(element);
11792
11822
  this.elementInfos = this.elementInfos.filter(info => info.element !== element);
11793
11823
  }
11794
11824
 
11795
11825
  async handleAppVisibilityChanged() {
11796
11826
  await super.handleAppVisibilityChanged();
11797
- if (!this.isAdaptiveStream) return; // on desktop don't pause when tab is backgrounded
11798
-
11799
- if (!isMobile()) return;
11827
+ if (!this.isAdaptiveStream) return;
11800
11828
  this.updateVisibility();
11801
11829
  }
11802
11830
 
11803
11831
  updateVisibility() {
11832
+ var _a, _b;
11833
+
11804
11834
  const lastVisibilityChange = this.elementInfos.reduce((prev, info) => Math.max(prev, info.visibilityChangedAt || 0), 0);
11805
- const isVisible = this.elementInfos.some(info => info.visible) && !this.isInBackground;
11835
+ const backgroundPause = ((_b = (_a = this.adaptiveStreamSettings) === null || _a === void 0 ? void 0 : _a.pauseVideoInBackground) !== null && _b !== void 0 ? _b : true // default to true
11836
+ ) ? this.isInBackground : false;
11837
+ const isVisible = this.elementInfos.some(info => info.visible) && !backgroundPause;
11806
11838
 
11807
11839
  if (this.lastVisible === isVisible) {
11808
11840
  return;
@@ -11829,8 +11861,8 @@ class RemoteVideoTrack extends RemoteTrack {
11829
11861
  for (const info of this.elementInfos) {
11830
11862
  const pixelDensity = (_b = (_a = this.adaptiveStreamSettings) === null || _a === void 0 ? void 0 : _a.pixelDensity) !== null && _b !== void 0 ? _b : 1;
11831
11863
  const pixelDensityValue = pixelDensity === 'screen' ? window.devicePixelRatio : pixelDensity;
11832
- const currentElementWidth = info.element.clientWidth * pixelDensityValue;
11833
- const currentElementHeight = info.element.clientHeight * pixelDensityValue;
11864
+ const currentElementWidth = info.width() * pixelDensityValue;
11865
+ const currentElementHeight = info.height() * pixelDensityValue;
11834
11866
 
11835
11867
  if (currentElementWidth + currentElementHeight > maxWidth + maxHeight) {
11836
11868
  maxWidth = currentElementWidth;
@@ -11851,6 +11883,59 @@ class RemoteVideoTrack extends RemoteTrack {
11851
11883
 
11852
11884
  }
11853
11885
 
11886
+ class HTMLElementInfo {
11887
+ constructor(element) {
11888
+ let visible = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
11889
+
11890
+ this.onVisibilityChanged = entry => {
11891
+ var _a;
11892
+
11893
+ const {
11894
+ target,
11895
+ isIntersecting
11896
+ } = entry;
11897
+
11898
+ if (target === this.element) {
11899
+ this.visible = isIntersecting;
11900
+ this.visibilityChangedAt = Date.now();
11901
+ (_a = this.handleVisibilityChanged) === null || _a === void 0 ? void 0 : _a.call(this);
11902
+ }
11903
+ };
11904
+
11905
+ this.element = element;
11906
+ this.visible = visible;
11907
+ this.visibilityChangedAt = 0;
11908
+ }
11909
+
11910
+ width() {
11911
+ return this.element.clientWidth;
11912
+ }
11913
+
11914
+ height() {
11915
+ return this.element.clientWidth;
11916
+ }
11917
+
11918
+ observe() {
11919
+ this.element.handleResize = () => {
11920
+ var _a;
11921
+
11922
+ (_a = this.handleResize) === null || _a === void 0 ? void 0 : _a.call(this);
11923
+ };
11924
+
11925
+ this.element.handleVisibilityChanged = this.onVisibilityChanged;
11926
+ getIntersectionObserver().observe(this.element);
11927
+ getResizeObserver().observe(this.element);
11928
+ }
11929
+
11930
+ stopObserving() {
11931
+ var _a, _b;
11932
+
11933
+ (_a = getIntersectionObserver()) === null || _a === void 0 ? void 0 : _a.unobserve(this.element);
11934
+ (_b = getResizeObserver()) === null || _b === void 0 ? void 0 : _b.unobserve(this.element);
11935
+ }
11936
+
11937
+ }
11938
+
11854
11939
  class TrackPublication extends events.exports.EventEmitter {
11855
11940
  constructor(kind, id, name) {
11856
11941
  super();
@@ -19258,7 +19343,7 @@ class Room extends events.exports.EventEmitter {
19258
19343
  var _a, _b;
19259
19344
 
19260
19345
  if (pub.track) {
19261
- this.localParticipant.unpublishTrack(pub.track);
19346
+ this.localParticipant.unpublishTrack(pub.track, shouldStopTracks);
19262
19347
  }
19263
19348
 
19264
19349
  if (shouldStopTracks) {