livekit-client 1.1.4 → 1.1.7

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.4";
10073
+ var version$1 = "1.1.7";
10074
10074
 
10075
10075
  const version = version$1;
10076
10076
  const protocolVersion = 8;
@@ -10180,6 +10180,15 @@ function getEmptyAudioStreamTrack() {
10180
10180
 
10181
10181
  return emptyAudioStreamTrack;
10182
10182
  }
10183
+ class Future {
10184
+ constructor() {
10185
+ this.promise = new Promise((resolve, reject) => {
10186
+ this.resolve = resolve;
10187
+ this.reject = reject;
10188
+ });
10189
+ }
10190
+
10191
+ }
10183
10192
 
10184
10193
  const defaultId = 'default';
10185
10194
  class DeviceManager {
@@ -13215,6 +13224,7 @@ class RemoteTrackPublication extends TrackPublication {
13215
13224
 
13216
13225
  this.handleEnded = track => {
13217
13226
  this.emit(TrackEvent.Ended, track);
13227
+ this.setTrack(undefined);
13218
13228
  };
13219
13229
 
13220
13230
  this.handleVisibilityChange = visible => {
@@ -13342,6 +13352,8 @@ class RemoteTrackPublication extends TrackPublication {
13342
13352
  get videoQuality() {
13343
13353
  return this.currentVideoQuality;
13344
13354
  }
13355
+ /** @internal */
13356
+
13345
13357
 
13346
13358
  setTrack(track) {
13347
13359
  if (this.track) {
@@ -13547,7 +13559,9 @@ class RemoteParticipant extends Participant {
13547
13559
  track.isMuted = publication.isMuted;
13548
13560
  track.setMediaStream(mediaStream);
13549
13561
  track.start();
13550
- publication.setTrack(track); // set participant volume on new microphone tracks
13562
+ publication.setTrack(track); // subscription means participant has permissions to subscribe
13563
+
13564
+ publication._allowed = true; // set participant volume on new microphone tracks
13551
13565
 
13552
13566
  if (this.volume !== undefined && track instanceof RemoteAudioTrack && track.source === Track.Source.Microphone) {
13553
13567
  track.setVolume(this.volume);
@@ -14486,6 +14500,32 @@ class LocalParticipant extends Participant {
14486
14500
  this.updateTrackSubscriptionPermissions();
14487
14501
  }
14488
14502
  }
14503
+ /** @internal */
14504
+
14505
+
14506
+ updateInfo(info) {
14507
+ super.updateInfo(info); // reconcile track mute status.
14508
+ // if server's track mute status doesn't match actual, we'll have to update
14509
+ // the server's copy
14510
+
14511
+ info.tracks.forEach(ti => {
14512
+ var _a, _b;
14513
+
14514
+ const pub = this.tracks.get(ti.sid);
14515
+
14516
+ if (pub) {
14517
+ const mutedOnServer = pub.isMuted || ((_b = (_a = pub.track) === null || _a === void 0 ? void 0 : _a.isUpstreamPaused) !== null && _b !== void 0 ? _b : false);
14518
+
14519
+ if (mutedOnServer !== ti.muted) {
14520
+ livekitLogger.debug('updating server mute state after reconcile', {
14521
+ sid: ti.sid,
14522
+ muted: mutedOnServer
14523
+ });
14524
+ this.engine.client.sendMuteTrack(ti.sid, mutedOnServer);
14525
+ }
14526
+ }
14527
+ });
14528
+ }
14489
14529
 
14490
14530
  getPublicationForTrack(track) {
14491
14531
  let publication;
@@ -14595,57 +14635,6 @@ class LocalParticipant extends Participant {
14595
14635
 
14596
14636
  }
14597
14637
 
14598
- class Queue {
14599
- constructor() {
14600
- this.queue = [];
14601
- this.running = false;
14602
- }
14603
-
14604
- enqueue(cb) {
14605
- livekitLogger.trace('enqueuing request to fire later');
14606
- this.queue.push(cb);
14607
- }
14608
-
14609
- dequeue() {
14610
- const evt = this.queue.shift();
14611
- if (evt) evt();
14612
- livekitLogger.trace('firing request from queue');
14613
- }
14614
-
14615
- async run() {
14616
- if (this.running) return;
14617
- livekitLogger.trace('start queue');
14618
- this.running = true;
14619
-
14620
- while (this.running && this.queue.length > 0) {
14621
- this.dequeue();
14622
- }
14623
-
14624
- this.running = false;
14625
- livekitLogger.trace('queue finished');
14626
- }
14627
-
14628
- pause() {
14629
- livekitLogger.trace('pausing queue');
14630
- this.running = false;
14631
- }
14632
-
14633
- reset() {
14634
- livekitLogger.trace('resetting queue');
14635
- this.running = false;
14636
- this.queue = [];
14637
- }
14638
-
14639
- isRunning() {
14640
- return this.running;
14641
- }
14642
-
14643
- isEmpty() {
14644
- return this.queue.length === 0;
14645
- }
14646
-
14647
- }
14648
-
14649
14638
  /*
14650
14639
  * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
14651
14640
  *
@@ -18131,6 +18120,57 @@ adapterFactory({
18131
18120
  window: typeof window === 'undefined' ? undefined : window
18132
18121
  });
18133
18122
 
18123
+ class Queue {
18124
+ constructor() {
18125
+ this.queue = [];
18126
+ this.running = false;
18127
+ }
18128
+
18129
+ enqueue(cb) {
18130
+ livekitLogger.trace('enqueuing request to fire later');
18131
+ this.queue.push(cb);
18132
+ }
18133
+
18134
+ dequeue() {
18135
+ const evt = this.queue.shift();
18136
+ if (evt) evt();
18137
+ livekitLogger.trace('firing request from queue');
18138
+ }
18139
+
18140
+ async run() {
18141
+ if (this.running) return;
18142
+ livekitLogger.trace('start queue');
18143
+ this.running = true;
18144
+
18145
+ while (this.running && this.queue.length > 0) {
18146
+ this.dequeue();
18147
+ }
18148
+
18149
+ this.running = false;
18150
+ livekitLogger.trace('queue finished');
18151
+ }
18152
+
18153
+ pause() {
18154
+ livekitLogger.trace('pausing queue');
18155
+ this.running = false;
18156
+ }
18157
+
18158
+ reset() {
18159
+ livekitLogger.trace('resetting queue');
18160
+ this.running = false;
18161
+ this.queue = [];
18162
+ }
18163
+
18164
+ isRunning() {
18165
+ return this.running;
18166
+ }
18167
+
18168
+ isEmpty() {
18169
+ return this.queue.length === 0;
18170
+ }
18171
+
18172
+ }
18173
+
18134
18174
  const passThroughQueueSignals = ['syncState', 'trickle', 'offer', 'answer', 'simulate', 'leave'];
18135
18175
 
18136
18176
  function canPassThroughQueue(req) {
@@ -19427,14 +19467,18 @@ class Room extends events.exports.EventEmitter {
19427
19467
  this.audioEnabled = true;
19428
19468
 
19429
19469
  this.connect = async (url, token, opts) => {
19430
- var _a, _b; // guard against calling connect
19470
+ var _a, _b, _c, _d;
19431
19471
 
19432
-
19433
- if (this.state !== ConnectionState.Disconnected) {
19472
+ if (this.state === ConnectionState.Connected) {
19473
+ // when the state is reconnecting or connected, this function returns immediately
19434
19474
  livekitLogger.warn("already connected to room ".concat(this.name));
19435
19475
  return;
19436
19476
  }
19437
19477
 
19478
+ if (this.connectFuture) {
19479
+ return this.connectFuture.promise;
19480
+ }
19481
+
19438
19482
  this.setAndEmitConnectionState(ConnectionState.Connecting);
19439
19483
 
19440
19484
  if (!this.abortController || this.abortController.signal.aborted) {
@@ -19501,49 +19545,47 @@ class Room extends events.exports.EventEmitter {
19501
19545
  this.emit(RoomEvent.SignalConnected);
19502
19546
  } catch (err) {
19503
19547
  this.recreateEngine();
19504
- this.setAndEmitConnectionState(ConnectionState.Disconnected);
19548
+ this.setAndEmitConnectionState(ConnectionState.Disconnected, new ConnectionError('could not establish signal connection'));
19505
19549
  throw err;
19506
19550
  } // don't return until ICE connected
19507
19551
 
19508
19552
 
19509
- return new Promise((resolve, reject) => {
19510
- var _a, _b;
19553
+ const connectTimeout = setTimeout(() => {
19554
+ // timeout
19555
+ this.recreateEngine();
19556
+ this.setAndEmitConnectionState(ConnectionState.Disconnected, new ConnectionError('could not connect PeerConnection after timeout'));
19557
+ }, maxICEConnectTimeout);
19511
19558
 
19512
- const connectTimeout = setTimeout(() => {
19513
- // timeout
19514
- this.recreateEngine();
19515
- this.setAndEmitConnectionState(ConnectionState.Disconnected);
19516
- reject(new ConnectionError('could not connect after timeout'));
19517
- }, maxICEConnectTimeout);
19518
-
19519
- const abortHandler = () => {
19520
- livekitLogger.warn('closing engine');
19521
- clearTimeout(connectTimeout);
19522
- this.recreateEngine();
19523
- this.setAndEmitConnectionState(ConnectionState.Disconnected);
19524
- reject(new ConnectionError('room connection has been cancelled'));
19525
- };
19559
+ const abortHandler = () => {
19560
+ livekitLogger.warn('closing engine');
19561
+ clearTimeout(connectTimeout);
19562
+ this.recreateEngine();
19563
+ this.setAndEmitConnectionState(ConnectionState.Disconnected, new ConnectionError('room connection has been cancelled'));
19564
+ };
19526
19565
 
19527
- if ((_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
19528
- abortHandler();
19529
- }
19566
+ if ((_c = this.abortController) === null || _c === void 0 ? void 0 : _c.signal.aborted) {
19567
+ abortHandler();
19568
+ }
19530
19569
 
19531
- (_b = this.abortController) === null || _b === void 0 ? void 0 : _b.signal.addEventListener('abort', abortHandler);
19532
- this.engine.once(EngineEvent.Connected, () => {
19533
- var _a, _b;
19570
+ (_d = this.abortController) === null || _d === void 0 ? void 0 : _d.signal.addEventListener('abort', abortHandler);
19571
+ this.engine.once(EngineEvent.Connected, () => {
19572
+ var _a, _b;
19534
19573
 
19535
- clearTimeout(connectTimeout);
19536
- (_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.removeEventListener('abort', abortHandler); // also hook unload event
19574
+ clearTimeout(connectTimeout);
19575
+ (_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.removeEventListener('abort', abortHandler); // also hook unload event
19537
19576
 
19538
- if (isWeb()) {
19539
- window.addEventListener('beforeunload', this.onBeforeUnload);
19540
- (_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.addEventListener('devicechange', this.handleDeviceChange);
19541
- }
19577
+ if (isWeb()) {
19578
+ window.addEventListener('beforeunload', this.onBeforeUnload);
19579
+ (_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.addEventListener('devicechange', this.handleDeviceChange);
19580
+ }
19542
19581
 
19543
- this.setAndEmitConnectionState(ConnectionState.Connected);
19544
- resolve(this);
19545
- });
19582
+ this.setAndEmitConnectionState(ConnectionState.Connected);
19546
19583
  });
19584
+
19585
+ if (this.connectFuture) {
19586
+ /** @ts-ignore */
19587
+ return this.connectFuture.promise;
19588
+ }
19547
19589
  };
19548
19590
  /**
19549
19591
  * disconnects the room, emits [[RoomEvent.Disconnected]]
@@ -19752,7 +19794,7 @@ class Room extends events.exports.EventEmitter {
19752
19794
 
19753
19795
  pub.track.streamState = Track.streamStateFromProto(streamState.state);
19754
19796
  participant.emit(ParticipantEvent.TrackStreamStateChanged, pub, pub.track.streamState);
19755
- this.emitWhenConnected(ParticipantEvent.TrackStreamStateChanged, pub, pub.track.streamState, participant);
19797
+ this.emitWhenConnected(RoomEvent.TrackStreamStateChanged, pub, pub.track.streamState, participant);
19756
19798
  });
19757
19799
  };
19758
19800
 
@@ -19771,7 +19813,7 @@ class Room extends events.exports.EventEmitter {
19771
19813
 
19772
19814
  pub._allowed = update.allowed;
19773
19815
  participant.emit(ParticipantEvent.TrackSubscriptionPermissionChanged, pub, pub.subscriptionStatus);
19774
- this.emitWhenConnected(ParticipantEvent.TrackSubscriptionPermissionChanged, pub, pub.subscriptionStatus, participant);
19816
+ this.emitWhenConnected(RoomEvent.TrackSubscriptionPermissionChanged, pub, pub.subscriptionStatus, participant);
19775
19817
  };
19776
19818
 
19777
19819
  this.handleDataPacket = (userPacket, kind) => {
@@ -19914,6 +19956,15 @@ class Room extends events.exports.EventEmitter {
19914
19956
  let req;
19915
19957
 
19916
19958
  switch (scenario) {
19959
+ case 'signal-reconnect':
19960
+ this.engine.client.close();
19961
+
19962
+ if (this.engine.client.onClose) {
19963
+ this.engine.client.onClose('simulate disconnect');
19964
+ }
19965
+
19966
+ break;
19967
+
19917
19968
  case 'speaker':
19918
19969
  req = SimulateScenario.fromPartial({
19919
19970
  speakerUpdate: 3
@@ -20277,12 +20328,41 @@ class Room extends events.exports.EventEmitter {
20277
20328
  }
20278
20329
  }
20279
20330
 
20280
- setAndEmitConnectionState(state) {
20331
+ setAndEmitConnectionState(state, error) {
20281
20332
  if (state === this.state) {
20282
20333
  // unchanged
20283
20334
  return false;
20284
20335
  }
20285
20336
 
20337
+ switch (state) {
20338
+ case ConnectionState.Connecting:
20339
+ case ConnectionState.Reconnecting:
20340
+ if (!this.connectFuture) {
20341
+ // reuse existing connect future if possible
20342
+ this.connectFuture = new Future();
20343
+ }
20344
+
20345
+ break;
20346
+
20347
+ case ConnectionState.Connected:
20348
+ if (this.connectFuture) {
20349
+ this.connectFuture.resolve();
20350
+ this.connectFuture = undefined;
20351
+ }
20352
+
20353
+ break;
20354
+
20355
+ case ConnectionState.Disconnected:
20356
+ if (this.connectFuture) {
20357
+ error !== null && error !== void 0 ? error : error = new Error('disconnected from Room');
20358
+ this.connectFuture.reject(error);
20359
+ this.connectFuture = undefined;
20360
+ }
20361
+
20362
+ break;
20363
+
20364
+ }
20365
+
20286
20366
  this.state = state;
20287
20367
  this.emit(RoomEvent.ConnectionStateChanged, this.state);
20288
20368
  return true;