livekit-client 1.15.8 → 1.15.10

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.
@@ -10614,7 +10614,7 @@ function getMatch(exp, ua) {
10614
10614
  return match && match.length >= id && match[id] || '';
10615
10615
  }
10616
10616
 
10617
- var version$1 = "1.15.7";
10617
+ var version$1 = "1.15.10";
10618
10618
 
10619
10619
  const version = version$1;
10620
10620
  const protocolVersion = 11;
@@ -12753,6 +12753,18 @@ SimulateScenario.fields = proto3.util.newFieldList(() => [{
12753
12753
  kind: "scalar",
12754
12754
  T: 3 /* ScalarType.INT64 */,
12755
12755
  oneof: "scenario"
12756
+ }, {
12757
+ no: 7,
12758
+ name: "disconnect_signal_on_resume",
12759
+ kind: "scalar",
12760
+ T: 8 /* ScalarType.BOOL */,
12761
+ oneof: "scenario"
12762
+ }, {
12763
+ no: 8,
12764
+ name: "disconnect_signal_on_resume_no_messages",
12765
+ kind: "scalar",
12766
+ T: 8 /* ScalarType.BOOL */,
12767
+ oneof: "scenario"
12756
12768
  }]);
12757
12769
  /**
12758
12770
  * @generated from message livekit.Ping
@@ -14835,6 +14847,9 @@ class SignalClient {
14835
14847
  get isDisconnected() {
14836
14848
  return this.state === SignalConnectionState.DISCONNECTING || this.state === SignalConnectionState.DISCONNECTED;
14837
14849
  }
14850
+ get isEstablishingConnection() {
14851
+ return this.state === SignalConnectionState.CONNECTING || this.state === SignalConnectionState.RECONNECTING;
14852
+ }
14838
14853
  constructor() {
14839
14854
  let useJSON = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
14840
14855
  let loggerOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
@@ -14978,7 +14993,7 @@ class SignalClient {
14978
14993
  this.startPingInterval();
14979
14994
  }
14980
14995
  resolve(resp.message.value);
14981
- } else if (this.state === SignalConnectionState.RECONNECTING) {
14996
+ } else if (this.state === SignalConnectionState.RECONNECTING && resp.message.case !== 'leave') {
14982
14997
  // in reconnecting, any message received means signal reconnected
14983
14998
  this.state = SignalConnectionState.CONNECTED;
14984
14999
  abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', abortHandler);
@@ -14989,6 +15004,8 @@ class SignalClient {
14989
15004
  resolve();
14990
15005
  shouldProcessMessage = true;
14991
15006
  }
15007
+ } else if (this.isEstablishingConnection && resp.message.case === 'leave') {
15008
+ reject(new ConnectionError('Received leave request while trying to (re)connect', 4 /* ConnectionErrorReason.LeaveRequest */));
14992
15009
  } else if (!opts.reconnect) {
14993
15010
  // non-reconnect case, should receive join response first
14994
15011
  reject(new ConnectionError("did not receive join response, got ".concat((_d = resp.message) === null || _d === void 0 ? void 0 : _d.case, " instead")));
@@ -15003,8 +15020,12 @@ class SignalClient {
15003
15020
  this.handleSignalResponse(resp);
15004
15021
  });
15005
15022
  this.ws.onclose = ev => {
15023
+ if (this.isEstablishingConnection) {
15024
+ reject(new ConnectionError('Websocket got closed during a (re)connection attempt'));
15025
+ }
15006
15026
  this.log.warn("websocket closed", Object.assign(Object.assign({}, this.logContext), {
15007
- reason: ev.reason
15027
+ reason: ev.reason,
15028
+ state: this.state
15008
15029
  }));
15009
15030
  this.handleOnClose(ev.reason);
15010
15031
  };
@@ -16822,6 +16843,7 @@ class PCTransportManager {
16822
16843
  return __awaiter(this, void 0, void 0, function* () {
16823
16844
  this.log.debug('received server offer', Object.assign(Object.assign({}, this.logContext), {
16824
16845
  RTCSdpType: sd.type,
16846
+ sdp: sd.sdp,
16825
16847
  signalingState: this.subscriber.getSignallingState().toString()
16826
16848
  }));
16827
16849
  yield this.subscriber.setRemoteDescription(sd);
@@ -17393,6 +17415,9 @@ class RTCEngine extends eventsExports.EventEmitter {
17393
17415
  delete this.pendingTrackResolvers[res.cid];
17394
17416
  resolve(res.track);
17395
17417
  };
17418
+ this.client.onLocalTrackUnpublished = response => {
17419
+ this.emit(EngineEvent.LocalTrackUnpublished, response);
17420
+ };
17396
17421
  this.client.onTokenRefresh = token => {
17397
17422
  this.token = token;
17398
17423
  };
@@ -17615,6 +17640,7 @@ class RTCEngine extends eventsExports.EventEmitter {
17615
17640
  }
17616
17641
  // guard for attempting reconnection multiple times while one attempt is still not finished
17617
17642
  if (this.attemptingReconnect) {
17643
+ livekitLogger.warn('already attempting reconnect, returning early', this.logContext);
17618
17644
  return;
17619
17645
  }
17620
17646
  if (((_a = this.clientConfiguration) === null || _a === void 0 ? void 0 : _a.resumeConnection) === ClientConfigSetting.DISABLED ||
@@ -17704,6 +17730,10 @@ class RTCEngine extends eventsExports.EventEmitter {
17704
17730
  this.client.setReconnected();
17705
17731
  this.emit(EngineEvent.SignalRestarted, joinResponse);
17706
17732
  yield this.waitForPCReconnected();
17733
+ // re-check signal connection state before setting engine as resumed
17734
+ if (this.client.currentState !== SignalConnectionState.CONNECTED) {
17735
+ throw new SignalReconnectError('Signal connection got severed during reconnect');
17736
+ }
17707
17737
  (_a = this.regionUrlProvider) === null || _a === void 0 ? void 0 : _a.resetAttempts();
17708
17738
  // reconnect success
17709
17739
  this.emit(EngineEvent.Restarted);
@@ -17740,15 +17770,20 @@ class RTCEngine extends eventsExports.EventEmitter {
17740
17770
  const rtcConfig = this.makeRTCConfiguration(res);
17741
17771
  this.pcManager.updateConfiguration(rtcConfig);
17742
17772
  }
17743
- } catch (e) {
17773
+ } catch (error) {
17744
17774
  let message = '';
17745
- if (e instanceof Error) {
17746
- message = e.message;
17747
- this.log.error(e.message, this.logContext);
17775
+ if (error instanceof Error) {
17776
+ message = error.message;
17777
+ this.log.error(error.message, Object.assign(Object.assign({}, this.logContext), {
17778
+ error
17779
+ }));
17748
17780
  }
17749
- if (e instanceof ConnectionError && e.reason === 0 /* ConnectionErrorReason.NotAllowed */) {
17781
+ if (error instanceof ConnectionError && error.reason === 0 /* ConnectionErrorReason.NotAllowed */) {
17750
17782
  throw new UnexpectedConnectionState('could not reconnect, token might be expired');
17751
17783
  }
17784
+ if (error instanceof ConnectionError && error.reason === 4 /* ConnectionErrorReason.LeaveRequest */) {
17785
+ throw error;
17786
+ }
17752
17787
  throw new SignalReconnectError(message);
17753
17788
  }
17754
17789
  this.emit(EngineEvent.SignalResumed);
@@ -17758,6 +17793,10 @@ class RTCEngine extends eventsExports.EventEmitter {
17758
17793
  }
17759
17794
  yield this.pcManager.triggerIceRestart();
17760
17795
  yield this.waitForPCReconnected();
17796
+ // re-check signal connection state before setting engine as resumed
17797
+ if (this.client.currentState !== SignalConnectionState.CONNECTED) {
17798
+ throw new SignalReconnectError('Signal connection got severed during reconnect');
17799
+ }
17761
17800
  this.client.setReconnected();
17762
17801
  // recreate publish datachannel if it's id is null
17763
17802
  // (for safari https://bugs.webkit.org/show_bug.cgi?id=184688)
@@ -22561,6 +22600,30 @@ class Room extends eventsExports.EventEmitter {
22561
22600
  // @ts-expect-error function is private
22562
22601
  yield this.engine.client.handleOnClose('simulate resume-disconnect');
22563
22602
  break;
22603
+ case 'disconnect-signal-on-resume':
22604
+ postAction = () => __awaiter(this, void 0, void 0, function* () {
22605
+ // @ts-expect-error function is private
22606
+ yield this.engine.client.handleOnClose('simulate resume-disconnect');
22607
+ });
22608
+ req = new SimulateScenario({
22609
+ scenario: {
22610
+ case: 'disconnectSignalOnResume',
22611
+ value: true
22612
+ }
22613
+ });
22614
+ break;
22615
+ case 'disconnect-signal-on-resume-no-messages':
22616
+ postAction = () => __awaiter(this, void 0, void 0, function* () {
22617
+ // @ts-expect-error function is private
22618
+ yield this.engine.client.handleOnClose('simulate resume-disconnect');
22619
+ });
22620
+ req = new SimulateScenario({
22621
+ scenario: {
22622
+ case: 'disconnectSignalOnResumeNoMessages',
22623
+ value: true
22624
+ }
22625
+ });
22626
+ break;
22564
22627
  case 'full-reconnect':
22565
22628
  this.engine.fullReconnectOnNext = true;
22566
22629
  // @ts-expect-error function is private
@@ -22597,8 +22660,8 @@ class Room extends eventsExports.EventEmitter {
22597
22660
  break;
22598
22661
  }
22599
22662
  if (req) {
22600
- this.engine.client.sendSimulateScenario(req);
22601
- postAction();
22663
+ yield this.engine.client.sendSimulateScenario(req);
22664
+ yield postAction();
22602
22665
  }
22603
22666
  });
22604
22667
  }
@@ -22967,7 +23030,11 @@ class Room extends eventsExports.EventEmitter {
22967
23030
  !this.engine.verifyTransport()) {
22968
23031
  consecutiveFailures++;
22969
23032
  this.log.warn('detected connection state mismatch', Object.assign(Object.assign({}, this.logContext), {
22970
- numFailures: consecutiveFailures
23033
+ numFailures: consecutiveFailures,
23034
+ engine: {
23035
+ closed: this.engine.isClosed,
23036
+ transportsConnected: this.engine.verifyTransport()
23037
+ }
22971
23038
  }));
22972
23039
  if (consecutiveFailures >= 3) {
22973
23040
  this.recreateEngine();
@@ -23050,7 +23117,7 @@ class Room extends eventsExports.EventEmitter {
23050
23117
  name: 'video-dummy'
23051
23118
  }), new LocalVideoTrack(publishOptions.useRealTracks ? (yield window.navigator.mediaDevices.getUserMedia({
23052
23119
  video: true
23053
- })).getVideoTracks()[0] : createDummyVideoStreamTrack((_a = 160 * participantOptions.aspectRatios[0]) !== null && _a !== void 0 ? _a : 1, 160, true, true), undefined, false, {
23120
+ })).getVideoTracks()[0] : createDummyVideoStreamTrack(160 * ((_a = participantOptions.aspectRatios[0]) !== null && _a !== void 0 ? _a : 1), 160, true, true), undefined, false, {
23054
23121
  loggerName: this.options.loggerName,
23055
23122
  loggerContextCb: () => this.logContext
23056
23123
  }), {
@@ -23089,7 +23156,7 @@ class Room extends eventsExports.EventEmitter {
23089
23156
  });
23090
23157
  const p = this.getOrCreateParticipant(info.identity, info);
23091
23158
  if (participantOptions.video) {
23092
- const dummyVideo = createDummyVideoStreamTrack((_b = 160 * participantOptions.aspectRatios[i % participantOptions.aspectRatios.length]) !== null && _b !== void 0 ? _b : 1, 160, false, true);
23159
+ const dummyVideo = createDummyVideoStreamTrack(160 * ((_b = participantOptions.aspectRatios[i % participantOptions.aspectRatios.length]) !== null && _b !== void 0 ? _b : 1), 160, false, true);
23093
23160
  const videoTrack = new TrackInfo({
23094
23161
  source: TrackSource.CAMERA,
23095
23162
  sid: Math.floor(Math.random() * 10000).toString(),