livekit-client 1.1.5 → 1.1.8

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 (30) hide show
  1. package/dist/livekit-client.esm.mjs +136 -58
  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/api/SignalClient.d.ts +1 -1
  6. package/dist/src/api/SignalClient.d.ts.map +1 -1
  7. package/dist/src/room/RTCEngine.d.ts.map +1 -1
  8. package/dist/src/room/Room.d.ts.map +1 -1
  9. package/dist/src/room/participant/LocalParticipant.d.ts +3 -1
  10. package/dist/src/room/participant/LocalParticipant.d.ts.map +1 -1
  11. package/dist/src/room/participant/Participant.d.ts.map +1 -1
  12. package/dist/src/room/participant/RemoteParticipant.d.ts.map +1 -1
  13. package/dist/src/room/track/RemoteTrackPublication.d.ts +1 -0
  14. package/dist/src/room/track/RemoteTrackPublication.d.ts.map +1 -1
  15. package/dist/src/room/track/Track.d.ts +7 -0
  16. package/dist/src/room/track/Track.d.ts.map +1 -1
  17. package/dist/src/room/track/TrackPublication.d.ts.map +1 -1
  18. package/dist/src/room/track/options.d.ts +1 -1
  19. package/dist/src/room/track/options.d.ts.map +1 -1
  20. package/package.json +1 -1
  21. package/src/api/SignalClient.ts +1 -1
  22. package/src/room/RTCEngine.ts +1 -0
  23. package/src/room/Room.ts +25 -4
  24. package/src/room/participant/LocalParticipant.ts +30 -2
  25. package/src/room/participant/Participant.ts +2 -0
  26. package/src/room/participant/RemoteParticipant.ts +6 -0
  27. package/src/room/track/RemoteTrackPublication.ts +2 -0
  28. package/src/room/track/Track.ts +12 -0
  29. package/src/room/track/TrackPublication.ts +2 -0
  30. package/src/room/track/options.ts +1 -1
@@ -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.5";
10073
+ var version$1 = "1.1.8";
10074
10074
 
10075
10075
  const version = version$1;
10076
10076
  const protocolVersion = 8;
@@ -10742,6 +10742,7 @@ class Track extends events.exports.EventEmitter {
10742
10742
 
10743
10743
  this.kind = kind;
10744
10744
  this._mediaStreamTrack = mediaTrack;
10745
+ this._mediaStreamID = mediaTrack.id;
10745
10746
  this.source = Track.Source.Unknown;
10746
10747
 
10747
10748
  if (isWeb()) {
@@ -10761,6 +10762,16 @@ class Track extends events.exports.EventEmitter {
10761
10762
  get mediaStreamTrack() {
10762
10763
  return this._mediaStreamTrack;
10763
10764
  }
10765
+ /**
10766
+ * @internal
10767
+ * used for keep mediaStream's first id, since it's id might change
10768
+ * if we disable/enable a track
10769
+ */
10770
+
10771
+
10772
+ get mediaStreamID() {
10773
+ return this._mediaStreamID;
10774
+ }
10764
10775
 
10765
10776
  attach(element) {
10766
10777
  let elementType = 'audio';
@@ -12553,6 +12564,9 @@ class TrackPublication extends events.exports.EventEmitter {
12553
12564
  }
12554
12565
 
12555
12566
  this.trackInfo = info;
12567
+ livekitLogger.trace('update publication info', {
12568
+ info
12569
+ });
12556
12570
  }
12557
12571
 
12558
12572
  }
@@ -12875,6 +12889,9 @@ class Participant extends events.exports.EventEmitter {
12875
12889
 
12876
12890
 
12877
12891
  this.participantInfo = info;
12892
+ livekitLogger.trace('update participant info', {
12893
+ info
12894
+ });
12878
12895
  }
12879
12896
  /** @internal */
12880
12897
 
@@ -13224,6 +13241,7 @@ class RemoteTrackPublication extends TrackPublication {
13224
13241
 
13225
13242
  this.handleEnded = track => {
13226
13243
  this.emit(TrackEvent.Ended, track);
13244
+ this.setTrack(undefined);
13227
13245
  };
13228
13246
 
13229
13247
  this.handleVisibilityChange = visible => {
@@ -13351,6 +13369,8 @@ class RemoteTrackPublication extends TrackPublication {
13351
13369
  get videoQuality() {
13352
13370
  return this.currentVideoQuality;
13353
13371
  }
13372
+ /** @internal */
13373
+
13354
13374
 
13355
13375
  setTrack(track) {
13356
13376
  if (this.track) {
@@ -13556,7 +13576,9 @@ class RemoteParticipant extends Participant {
13556
13576
  track.isMuted = publication.isMuted;
13557
13577
  track.setMediaStream(mediaStream);
13558
13578
  track.start();
13559
- publication.setTrack(track); // set participant volume on new microphone tracks
13579
+ publication.setTrack(track); // subscription means participant has permissions to subscribe
13580
+
13581
+ publication._allowed = true; // set participant volume on new microphone tracks
13560
13582
 
13561
13583
  if (this.volume !== undefined && track instanceof RemoteAudioTrack && track.source === Track.Source.Microphone) {
13562
13584
  track.setVolume(this.volume);
@@ -13614,6 +13636,10 @@ class RemoteParticipant extends Participant {
13614
13636
 
13615
13637
  this.tracks.forEach(publication => {
13616
13638
  if (!validTracks.has(publication.trackSid)) {
13639
+ livekitLogger.trace('detected removed track on remote participant, unpublishing', {
13640
+ publication,
13641
+ participantSid: this.sid
13642
+ });
13617
13643
  this.unpublishTrack(publication.trackSid, true);
13618
13644
  }
13619
13645
  });
@@ -14495,6 +14521,32 @@ class LocalParticipant extends Participant {
14495
14521
  this.updateTrackSubscriptionPermissions();
14496
14522
  }
14497
14523
  }
14524
+ /** @internal */
14525
+
14526
+
14527
+ updateInfo(info) {
14528
+ super.updateInfo(info); // reconcile track mute status.
14529
+ // if server's track mute status doesn't match actual, we'll have to update
14530
+ // the server's copy
14531
+
14532
+ info.tracks.forEach(ti => {
14533
+ var _a, _b;
14534
+
14535
+ const pub = this.tracks.get(ti.sid);
14536
+
14537
+ if (pub) {
14538
+ const mutedOnServer = pub.isMuted || ((_b = (_a = pub.track) === null || _a === void 0 ? void 0 : _a.isUpstreamPaused) !== null && _b !== void 0 ? _b : false);
14539
+
14540
+ if (mutedOnServer !== ti.muted) {
14541
+ livekitLogger.debug('updating server mute state after reconcile', {
14542
+ sid: ti.sid,
14543
+ muted: mutedOnServer
14544
+ });
14545
+ this.engine.client.sendMuteTrack(ti.sid, mutedOnServer);
14546
+ }
14547
+ }
14548
+ });
14549
+ }
14498
14550
 
14499
14551
  getPublicationForTrack(track) {
14500
14552
  let publication;
@@ -14572,7 +14624,7 @@ class LocalParticipant extends Participant {
14572
14624
  this.tracks.forEach(track => {
14573
14625
  if (track.track !== undefined) {
14574
14626
  infos.push({
14575
- cid: track.track.mediaStreamTrack.id,
14627
+ cid: track.track.mediaStreamID,
14576
14628
  track: track.trackInfo
14577
14629
  });
14578
14630
  }
@@ -14604,57 +14656,6 @@ class LocalParticipant extends Participant {
14604
14656
 
14605
14657
  }
14606
14658
 
14607
- class Queue {
14608
- constructor() {
14609
- this.queue = [];
14610
- this.running = false;
14611
- }
14612
-
14613
- enqueue(cb) {
14614
- livekitLogger.trace('enqueuing request to fire later');
14615
- this.queue.push(cb);
14616
- }
14617
-
14618
- dequeue() {
14619
- const evt = this.queue.shift();
14620
- if (evt) evt();
14621
- livekitLogger.trace('firing request from queue');
14622
- }
14623
-
14624
- async run() {
14625
- if (this.running) return;
14626
- livekitLogger.trace('start queue');
14627
- this.running = true;
14628
-
14629
- while (this.running && this.queue.length > 0) {
14630
- this.dequeue();
14631
- }
14632
-
14633
- this.running = false;
14634
- livekitLogger.trace('queue finished');
14635
- }
14636
-
14637
- pause() {
14638
- livekitLogger.trace('pausing queue');
14639
- this.running = false;
14640
- }
14641
-
14642
- reset() {
14643
- livekitLogger.trace('resetting queue');
14644
- this.running = false;
14645
- this.queue = [];
14646
- }
14647
-
14648
- isRunning() {
14649
- return this.running;
14650
- }
14651
-
14652
- isEmpty() {
14653
- return this.queue.length === 0;
14654
- }
14655
-
14656
- }
14657
-
14658
14659
  /*
14659
14660
  * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
14660
14661
  *
@@ -18140,6 +18141,57 @@ adapterFactory({
18140
18141
  window: typeof window === 'undefined' ? undefined : window
18141
18142
  });
18142
18143
 
18144
+ class Queue {
18145
+ constructor() {
18146
+ this.queue = [];
18147
+ this.running = false;
18148
+ }
18149
+
18150
+ enqueue(cb) {
18151
+ livekitLogger.trace('enqueuing request to fire later');
18152
+ this.queue.push(cb);
18153
+ }
18154
+
18155
+ dequeue() {
18156
+ const evt = this.queue.shift();
18157
+ if (evt) evt();
18158
+ livekitLogger.trace('firing request from queue');
18159
+ }
18160
+
18161
+ async run() {
18162
+ if (this.running) return;
18163
+ livekitLogger.trace('start queue');
18164
+ this.running = true;
18165
+
18166
+ while (this.running && this.queue.length > 0) {
18167
+ this.dequeue();
18168
+ }
18169
+
18170
+ this.running = false;
18171
+ livekitLogger.trace('queue finished');
18172
+ }
18173
+
18174
+ pause() {
18175
+ livekitLogger.trace('pausing queue');
18176
+ this.running = false;
18177
+ }
18178
+
18179
+ reset() {
18180
+ livekitLogger.trace('resetting queue');
18181
+ this.running = false;
18182
+ this.queue = [];
18183
+ }
18184
+
18185
+ isRunning() {
18186
+ return this.running;
18187
+ }
18188
+
18189
+ isEmpty() {
18190
+ return this.queue.length === 0;
18191
+ }
18192
+
18193
+ }
18194
+
18143
18195
  const passThroughQueueSignals = ['syncState', 'trickle', 'offer', 'answer', 'simulate', 'leave'];
18144
18196
 
18145
18197
  function canPassThroughQueue(req) {
@@ -19124,6 +19176,10 @@ class RTCEngine extends events.exports.EventEmitter {
19124
19176
  this.emit(EngineEvent.Disconnected);
19125
19177
  this.close();
19126
19178
  }
19179
+
19180
+ livekitLogger.trace('leave request', {
19181
+ leave
19182
+ });
19127
19183
  };
19128
19184
  }
19129
19185
 
@@ -19506,7 +19562,14 @@ class Room extends events.exports.EventEmitter {
19506
19562
  }); // populate remote participants, these should not trigger new events
19507
19563
 
19508
19564
  joinResponse.otherParticipants.forEach(info => {
19509
- this.getOrCreateParticipant(info.sid, info);
19565
+ if (info.sid !== this.localParticipant.sid && info.identity !== this.localParticipant.identity) {
19566
+ this.getOrCreateParticipant(info.sid, info);
19567
+ } else {
19568
+ livekitLogger.warn('received info to create local participant as remote participant', {
19569
+ info,
19570
+ localParticipant: this.localParticipant
19571
+ });
19572
+ }
19510
19573
  });
19511
19574
  this.name = joinResponse.room.name;
19512
19575
  this.sid = joinResponse.room.sid;
@@ -19763,7 +19826,7 @@ class Room extends events.exports.EventEmitter {
19763
19826
 
19764
19827
  pub.track.streamState = Track.streamStateFromProto(streamState.state);
19765
19828
  participant.emit(ParticipantEvent.TrackStreamStateChanged, pub, pub.track.streamState);
19766
- this.emitWhenConnected(ParticipantEvent.TrackStreamStateChanged, pub, pub.track.streamState, participant);
19829
+ this.emitWhenConnected(RoomEvent.TrackStreamStateChanged, pub, pub.track.streamState, participant);
19767
19830
  });
19768
19831
  };
19769
19832
 
@@ -19782,7 +19845,7 @@ class Room extends events.exports.EventEmitter {
19782
19845
 
19783
19846
  pub._allowed = update.allowed;
19784
19847
  participant.emit(ParticipantEvent.TrackSubscriptionPermissionChanged, pub, pub.subscriptionStatus);
19785
- this.emitWhenConnected(ParticipantEvent.TrackSubscriptionPermissionChanged, pub, pub.subscriptionStatus, participant);
19848
+ this.emitWhenConnected(RoomEvent.TrackSubscriptionPermissionChanged, pub, pub.subscriptionStatus, participant);
19786
19849
  };
19787
19850
 
19788
19851
  this.handleDataPacket = (userPacket, kind) => {
@@ -19863,7 +19926,7 @@ class Room extends events.exports.EventEmitter {
19863
19926
  this.engine.on(EngineEvent.MediaTrackAdded, (mediaTrack, stream, receiver) => {
19864
19927
  this.onTrackAdded(mediaTrack, stream, receiver);
19865
19928
  }).on(EngineEvent.Disconnected, () => {
19866
- this.handleDisconnect();
19929
+ this.handleDisconnect(this.options.stopLocalTrackOnUnpublish);
19867
19930
  }).on(EngineEvent.ActiveSpeakersUpdate, this.handleActiveSpeakersUpdate).on(EngineEvent.DataPacketReceived, this.handleDataPacket).on(EngineEvent.Resuming, () => {
19868
19931
  if (this.setAndEmitConnectionState(ConnectionState.Reconnecting)) {
19869
19932
  this.emit(RoomEvent.Reconnecting);
@@ -19925,6 +19988,15 @@ class Room extends events.exports.EventEmitter {
19925
19988
  let req;
19926
19989
 
19927
19990
  switch (scenario) {
19991
+ case 'signal-reconnect':
19992
+ this.engine.client.close();
19993
+
19994
+ if (this.engine.client.onClose) {
19995
+ this.engine.client.onClose('simulate disconnect');
19996
+ }
19997
+
19998
+ break;
19999
+
19928
20000
  case 'speaker':
19929
20001
  req = SimulateScenario.fromPartial({
19930
20002
  speakerUpdate: 3
@@ -20089,6 +20161,12 @@ class Room extends events.exports.EventEmitter {
20089
20161
  const participantId = parts[0];
20090
20162
  let trackId = parts[1];
20091
20163
  if (!trackId || trackId === '') trackId = mediaTrack.id;
20164
+
20165
+ if (participantId === this.localParticipant.sid) {
20166
+ livekitLogger.warn('tried to create RemoteParticipant for local participant');
20167
+ return;
20168
+ }
20169
+
20092
20170
  const participant = this.getOrCreateParticipant(participantId);
20093
20171
  let adaptiveStreamSettings;
20094
20172