livekit-client 1.1.2 → 1.1.3

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.
@@ -10070,7 +10070,7 @@ function computeBitrate(currentStats, prevStats) {
10070
10070
  return (bytesNow - bytesPrev) * 8 * 1000 / (currentStats.timestamp - prevStats.timestamp);
10071
10071
  }
10072
10072
 
10073
- var version$1 = "1.1.2";
10073
+ var version$1 = "1.1.3";
10074
10074
 
10075
10075
  const version = version$1;
10076
10076
  const protocolVersion = 8;
@@ -12225,6 +12225,8 @@ class RemoteVideoTrack extends RemoteTrack {
12225
12225
 
12226
12226
  this.debouncedHandleResize();
12227
12227
  this.updateVisibility();
12228
+ } else {
12229
+ livekitLogger.warn('visibility resize observer not triggered');
12228
12230
  }
12229
12231
  }
12230
12232
  /**
@@ -12373,9 +12375,7 @@ class RemoteVideoTrack extends RemoteTrack {
12373
12375
  }
12374
12376
 
12375
12377
  class HTMLElementInfo {
12376
- constructor(element) {
12377
- let visible = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
12378
-
12378
+ constructor(element, visible) {
12379
12379
  this.onVisibilityChanged = entry => {
12380
12380
  var _a;
12381
12381
 
@@ -12392,7 +12392,7 @@ class HTMLElementInfo {
12392
12392
  };
12393
12393
 
12394
12394
  this.element = element;
12395
- this.visible = visible;
12395
+ this.visible = visible !== null && visible !== void 0 ? visible : isElementInViewport(element);
12396
12396
  this.visibilityChangedAt = 0;
12397
12397
  }
12398
12398
 
@@ -12423,6 +12423,29 @@ class HTMLElementInfo {
12423
12423
  (_b = getResizeObserver()) === null || _b === void 0 ? void 0 : _b.unobserve(this.element);
12424
12424
  }
12425
12425
 
12426
+ } // does not account for occlusion by other elements
12427
+
12428
+
12429
+ function isElementInViewport(el) {
12430
+ let top = el.offsetTop;
12431
+ let left = el.offsetLeft;
12432
+ const width = el.offsetWidth;
12433
+ const height = el.offsetHeight;
12434
+ const {
12435
+ hidden
12436
+ } = el;
12437
+ const {
12438
+ opacity,
12439
+ display
12440
+ } = getComputedStyle(el);
12441
+
12442
+ while (el.offsetParent) {
12443
+ el = el.offsetParent;
12444
+ top += el.offsetTop;
12445
+ left += el.offsetLeft;
12446
+ }
12447
+
12448
+ 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';
12426
12449
  }
12427
12450
 
12428
12451
  class TrackPublication extends events.exports.EventEmitter {
@@ -13395,9 +13418,7 @@ class RemoteParticipant extends Participant {
13395
13418
 
13396
13419
 
13397
13420
  static fromParticipantInfo(signalClient, pi) {
13398
- const rp = new RemoteParticipant(signalClient, pi.sid, pi.identity);
13399
- rp.updateInfo(pi);
13400
- return rp;
13421
+ return new RemoteParticipant(signalClient, pi.sid, pi.identity);
13401
13422
  }
13402
13423
 
13403
13424
  addTrackPublication(publication) {
@@ -13538,7 +13559,6 @@ class RemoteParticipant extends Participant {
13538
13559
 
13539
13560
 
13540
13561
  updateInfo(info) {
13541
- const alreadyHasMetadata = this.hasMetadata;
13542
13562
  super.updateInfo(info); // we are getting a list of all available tracks, reconcile in here
13543
13563
  // and send out events for changes
13544
13564
  // reconcile track publications, publish events only if metadata is already there
@@ -13566,14 +13586,11 @@ class RemoteParticipant extends Participant {
13566
13586
  }
13567
13587
 
13568
13588
  validTracks.set(ti.sid, publication);
13569
- }); // send new tracks
13570
-
13571
- if (alreadyHasMetadata) {
13572
- newTracks.forEach(publication => {
13573
- this.emit(ParticipantEvent.TrackPublished, publication);
13574
- });
13575
- } // detect removed tracks
13589
+ }); // always emit events for new publications, Room will not forward them unless it's ready
13576
13590
 
13591
+ newTracks.forEach(publication => {
13592
+ this.emit(ParticipantEvent.TrackPublished, publication);
13593
+ }); // detect removed tracks
13577
13594
 
13578
13595
  this.tracks.forEach(publication => {
13579
13596
  if (!validTracks.has(publication.trackSid)) {
@@ -20015,6 +20032,22 @@ class Room extends events.exports.EventEmitter {
20015
20032
  }
20016
20033
 
20017
20034
  onTrackAdded(mediaTrack, stream, receiver) {
20035
+ // don't fire onSubscribed when connecting
20036
+ // WebRTC fires onTrack as soon as setRemoteDescription is called on the offer
20037
+ // at that time, ICE connectivity has not been established so the track is not
20038
+ // technically subscribed.
20039
+ // We'll defer these events until when the room is connected or eventually disconnected.
20040
+ if (this.state === ConnectionState.Connecting || this.state === ConnectionState.Reconnecting) {
20041
+ setTimeout(() => {
20042
+ this.onTrackAdded(mediaTrack, stream, receiver);
20043
+ }, 10);
20044
+ return;
20045
+ }
20046
+
20047
+ if (this.state === ConnectionState.Disconnected) {
20048
+ livekitLogger.warn('skipping incoming track after Room disconnected');
20049
+ }
20050
+
20018
20051
  const parts = unpackStreamId(stream.id);
20019
20052
  const participantId = parts[0];
20020
20053
  let trackId = parts[1];
@@ -20131,7 +20164,7 @@ class Room extends events.exports.EventEmitter {
20131
20164
 
20132
20165
 
20133
20166
  participant.on(ParticipantEvent.TrackPublished, trackPublication => {
20134
- this.emit(RoomEvent.TrackPublished, trackPublication, participant);
20167
+ this.emitWhenConnected(RoomEvent.TrackPublished, trackPublication, participant);
20135
20168
  }).on(ParticipantEvent.TrackSubscribed, (track, publication) => {
20136
20169
  // monitor playback status
20137
20170
  if (track.kind === Track.Kind.Audio) {
@@ -20141,22 +20174,27 @@ class Room extends events.exports.EventEmitter {
20141
20174
 
20142
20175
  this.emit(RoomEvent.TrackSubscribed, track, publication, participant);
20143
20176
  }).on(ParticipantEvent.TrackUnpublished, publication => {
20144
- this.emit(RoomEvent.TrackUnpublished, publication, participant);
20177
+ this.emitWhenConnected(RoomEvent.TrackUnpublished, publication, participant);
20145
20178
  }).on(ParticipantEvent.TrackUnsubscribed, (track, publication) => {
20146
20179
  this.emit(RoomEvent.TrackUnsubscribed, track, publication, participant);
20147
20180
  }).on(ParticipantEvent.TrackSubscriptionFailed, sid => {
20148
20181
  this.emit(RoomEvent.TrackSubscriptionFailed, sid, participant);
20149
20182
  }).on(ParticipantEvent.TrackMuted, pub => {
20150
- this.emit(RoomEvent.TrackMuted, pub, participant);
20183
+ this.emitWhenConnected(RoomEvent.TrackMuted, pub, participant);
20151
20184
  }).on(ParticipantEvent.TrackUnmuted, pub => {
20152
- this.emit(RoomEvent.TrackUnmuted, pub, participant);
20185
+ this.emitWhenConnected(RoomEvent.TrackUnmuted, pub, participant);
20153
20186
  }).on(ParticipantEvent.ParticipantMetadataChanged, metadata => {
20154
- this.emit(RoomEvent.ParticipantMetadataChanged, metadata, participant);
20187
+ this.emitWhenConnected(RoomEvent.ParticipantMetadataChanged, metadata, participant);
20155
20188
  }).on(ParticipantEvent.ConnectionQualityChanged, quality => {
20156
- this.emit(RoomEvent.ConnectionQualityChanged, quality, participant);
20189
+ this.emitWhenConnected(RoomEvent.ConnectionQualityChanged, quality, participant);
20157
20190
  }).on(ParticipantEvent.ParticipantPermissionsChanged, prevPermissions => {
20158
- this.emit(RoomEvent.ParticipantPermissionsChanged, prevPermissions, participant);
20159
- });
20191
+ this.emitWhenConnected(RoomEvent.ParticipantPermissionsChanged, prevPermissions, participant);
20192
+ }); // update info at the end after callbacks have been set up
20193
+
20194
+ if (info) {
20195
+ participant.updateInfo(info);
20196
+ }
20197
+
20160
20198
  return participant;
20161
20199
  }
20162
20200
 
@@ -20222,12 +20260,24 @@ class Room extends events.exports.EventEmitter {
20222
20260
  this.state = state;
20223
20261
  this.emit(RoomEvent.ConnectionStateChanged, this.state);
20224
20262
  return true;
20263
+ }
20264
+
20265
+ emitWhenConnected(event) {
20266
+ if (this.state === ConnectionState.Connected) {
20267
+ for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
20268
+ args[_key - 1] = arguments[_key];
20269
+ }
20270
+
20271
+ return this.emit(event, ...args);
20272
+ }
20273
+
20274
+ return false;
20225
20275
  } // /** @internal */
20226
20276
 
20227
20277
 
20228
20278
  emit(event) {
20229
- for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
20230
- args[_key - 1] = arguments[_key];
20279
+ for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
20280
+ args[_key2 - 1] = arguments[_key2];
20231
20281
  }
20232
20282
 
20233
20283
  livekitLogger.debug('room event', {