livekit-client 0.18.6 → 1.0.0

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 (46) hide show
  1. package/README.md +1 -1
  2. package/dist/api/SignalClient.d.ts +2 -2
  3. package/dist/api/SignalClient.d.ts.map +1 -1
  4. package/dist/index.d.ts +2 -3
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/livekit-client.esm.mjs +131 -215
  7. package/dist/livekit-client.esm.mjs.map +1 -1
  8. package/dist/livekit-client.umd.js +1 -1
  9. package/dist/livekit-client.umd.js.map +1 -1
  10. package/dist/options.d.ts +1 -68
  11. package/dist/options.d.ts.map +1 -1
  12. package/dist/room/DeviceManager.d.ts.map +1 -1
  13. package/dist/room/RTCEngine.d.ts +3 -2
  14. package/dist/room/RTCEngine.d.ts.map +1 -1
  15. package/dist/room/Room.d.ts +11 -7
  16. package/dist/room/Room.d.ts.map +1 -1
  17. package/dist/room/events.d.ts +6 -12
  18. package/dist/room/events.d.ts.map +1 -1
  19. package/dist/room/participant/LocalParticipant.d.ts.map +1 -1
  20. package/dist/room/participant/Participant.d.ts +0 -4
  21. package/dist/room/participant/Participant.d.ts.map +1 -1
  22. package/dist/room/participant/RemoteParticipant.d.ts +3 -2
  23. package/dist/room/participant/RemoteParticipant.d.ts.map +1 -1
  24. package/dist/room/track/options.d.ts +0 -30
  25. package/dist/room/track/options.d.ts.map +1 -1
  26. package/dist/version.d.ts +1 -1
  27. package/dist/version.d.ts.map +1 -1
  28. package/package.json +1 -1
  29. package/src/api/SignalClient.ts +32 -7
  30. package/src/index.ts +2 -2
  31. package/src/options.ts +0 -82
  32. package/src/room/DeviceManager.ts +4 -1
  33. package/src/room/RTCEngine.ts +16 -7
  34. package/src/room/Room.ts +65 -41
  35. package/src/room/events.ts +7 -14
  36. package/src/room/participant/LocalParticipant.ts +4 -0
  37. package/src/room/participant/Participant.ts +0 -5
  38. package/src/room/participant/RemoteParticipant.ts +16 -5
  39. package/src/room/participant/publishUtils.test.ts +2 -2
  40. package/src/room/track/create.ts +1 -1
  41. package/src/room/track/options.ts +0 -30
  42. package/src/room/track/utils.test.ts +6 -6
  43. package/src/version.ts +1 -1
  44. package/dist/connect.d.ts +0 -24
  45. package/dist/connect.d.ts.map +0 -1
  46. package/src/connect.ts +0 -98
@@ -9260,10 +9260,15 @@ var RoomEvent;
9260
9260
  /**
9261
9261
  * Whenever the connection state of the room changes
9262
9262
  *
9263
- * args: ([[RoomState]])
9263
+ * args: ([[ConnectionState]])
9264
9264
  */
9265
9265
 
9266
- RoomEvent["StateChanged"] = "stateChanged";
9266
+ RoomEvent["ConnectionStateChanged"] = "connectionStateChanged";
9267
+ /**
9268
+ * @deprecated StateChanged has been renamed to ConnectionStateChanged
9269
+ */
9270
+
9271
+ RoomEvent["StateChanged"] = "connectionStateChanged";
9267
9272
  /**
9268
9273
  * When input or output devices on the machine have changed.
9269
9274
  */
@@ -9370,12 +9375,6 @@ var RoomEvent;
9370
9375
  */
9371
9376
 
9372
9377
  RoomEvent["ActiveSpeakersChanged"] = "activeSpeakersChanged";
9373
- /**
9374
- * @deprecated Use ParticipantMetadataChanged instead
9375
- * @internal
9376
- */
9377
-
9378
- RoomEvent["MetadataChanged"] = "metadataChanged";
9379
9378
  /**
9380
9379
  * Participant metadata is a simple way for app-specific state to be pushed to
9381
9380
  * all users.
@@ -9541,12 +9540,6 @@ var ParticipantEvent;
9541
9540
  */
9542
9541
 
9543
9542
  ParticipantEvent["LocalTrackUnpublished"] = "localTrackUnpublished";
9544
- /**
9545
- * @deprecated Use ParticipantMetadataChanged instead
9546
- * @internal
9547
- */
9548
-
9549
- ParticipantEvent["MetadataChanged"] = "metadataChanged";
9550
9543
  /**
9551
9544
  * Participant metadata is a simple way for app-specific state to be pushed to
9552
9545
  * all users.
@@ -9737,8 +9730,11 @@ class DeviceManager {
9737
9730
  video: kind !== 'audioinput' && kind !== 'audiooutput',
9738
9731
  audio: kind !== 'videoinput'
9739
9732
  };
9740
- await navigator.mediaDevices.getUserMedia(permissionsToAcquire);
9733
+ const stream = await navigator.mediaDevices.getUserMedia(permissionsToAcquire);
9741
9734
  devices = await navigator.mediaDevices.enumerateDevices();
9735
+ stream.getTracks().forEach(track => {
9736
+ track.stop();
9737
+ });
9742
9738
  }
9743
9739
  }
9744
9740
 
@@ -9783,7 +9779,7 @@ class DeviceManager {
9783
9779
  }
9784
9780
  DeviceManager.mediaDeviceKinds = ['audioinput', 'audiooutput', 'videoinput'];
9785
9781
 
9786
- const version = '0.18.6';
9782
+ const version = '1.0.0';
9787
9783
  const protocolVersion = 7;
9788
9784
 
9789
9785
  const separator = '|';
@@ -12092,22 +12088,7 @@ const VideoPresets = {
12092
12088
  h720: new VideoPreset(1280, 720, 1700000, 30),
12093
12089
  h1080: new VideoPreset(1920, 1080, 3000000, 30),
12094
12090
  h1440: new VideoPreset(2560, 1440, 5000000, 30),
12095
- h2160: new VideoPreset(3840, 2160, 8000000, 30),
12096
-
12097
- /** @deprecated */
12098
- qvga: new VideoPreset(320, 180, 120000, 10),
12099
-
12100
- /** @deprecated */
12101
- vga: new VideoPreset(640, 360, 300000, 20),
12102
-
12103
- /** @deprecated */
12104
- qhd: new VideoPreset(960, 540, 600000, 25),
12105
-
12106
- /** @deprecated */
12107
- hd: new VideoPreset(1280, 720, 1700000, 30),
12108
-
12109
- /** @deprecated */
12110
- fhd: new VideoPreset(1920, 1080, 3000000, 30)
12091
+ h2160: new VideoPreset(3840, 2160, 8000000, 30)
12111
12092
  };
12112
12093
  /**
12113
12094
  * Four by three presets
@@ -12122,44 +12103,14 @@ const VideoPresets43 = {
12122
12103
  h540: new VideoPreset(720, 540, 450000, 25),
12123
12104
  h720: new VideoPreset(960, 720, 1500000, 30),
12124
12105
  h1080: new VideoPreset(1440, 1080, 2500000, 30),
12125
- h1440: new VideoPreset(1920, 1440, 3500000, 30),
12126
-
12127
- /** @deprecated */
12128
- qvga: new VideoPreset(240, 180, 90000, 10),
12129
-
12130
- /** @deprecated */
12131
- vga: new VideoPreset(480, 360, 225000, 20),
12132
-
12133
- /** @deprecated */
12134
- qhd: new VideoPreset(720, 540, 450000, 25),
12135
-
12136
- /** @deprecated */
12137
- hd: new VideoPreset(960, 720, 1500000, 30),
12138
-
12139
- /** @deprecated */
12140
- fhd: new VideoPreset(1440, 1080, 2800000, 30)
12106
+ h1440: new VideoPreset(1920, 1440, 3500000, 30)
12141
12107
  };
12142
12108
  const ScreenSharePresets = {
12143
12109
  h360fps3: new VideoPreset(640, 360, 200000, 3),
12144
12110
  h720fps5: new VideoPreset(1280, 720, 400000, 5),
12145
12111
  h720fps15: new VideoPreset(1280, 720, 1000000, 15),
12146
12112
  h1080fps15: new VideoPreset(1920, 1080, 1500000, 15),
12147
- h1080fps30: new VideoPreset(1920, 1080, 3000000, 30),
12148
-
12149
- /** @deprecated */
12150
- vga: new VideoPreset(640, 360, 200000, 3),
12151
-
12152
- /** @deprecated */
12153
- hd_8: new VideoPreset(1280, 720, 400000, 5),
12154
-
12155
- /** @deprecated */
12156
- hd_15: new VideoPreset(1280, 720, 1000000, 15),
12157
-
12158
- /** @deprecated */
12159
- fhd_15: new VideoPreset(1920, 1080, 1500000, 15),
12160
-
12161
- /** @deprecated */
12162
- fhd_30: new VideoPreset(1920, 1080, 3000000, 30)
12113
+ h1080fps30: new VideoPreset(1920, 1080, 3000000, 30)
12163
12114
  };
12164
12115
 
12165
12116
  var ConnectionQuality;
@@ -12317,7 +12268,6 @@ class Participant extends events.exports.EventEmitter {
12317
12268
  this.metadata = md;
12318
12269
 
12319
12270
  if (changed) {
12320
- this.emit(ParticipantEvent.MetadataChanged, prevMetadata);
12321
12271
  this.emit(ParticipantEvent.ParticipantMetadataChanged, prevMetadata);
12322
12272
  }
12323
12273
  }
@@ -12909,29 +12859,32 @@ class RemoteParticipant extends Participant {
12909
12859
  }
12910
12860
  }
12911
12861
  /**
12912
- * sets the volume on the participant's microphone track if it exists.
12862
+ * sets the volume on the participant's microphone track
12863
+ * if no track exists the volume will be applied when the microphone track is added
12913
12864
  */
12914
12865
 
12915
12866
 
12916
12867
  setVolume(volume) {
12868
+ this.volume = volume;
12917
12869
  const audioPublication = this.getTrack(Track.Source.Microphone);
12918
12870
 
12919
- if (audioPublication) {
12871
+ if (audioPublication && audioPublication.track) {
12920
12872
  audioPublication.track.setVolume(volume);
12921
12873
  }
12922
12874
  }
12923
12875
  /**
12924
12876
  * gets the volume on the participant's microphone track
12925
- * returns undefined if no microphone track exists
12926
12877
  */
12927
12878
 
12928
12879
 
12929
12880
  getVolume() {
12930
12881
  const audioPublication = this.getTrack(Track.Source.Microphone);
12931
12882
 
12932
- if (audioPublication) {
12883
+ if (audioPublication && audioPublication.track) {
12933
12884
  return audioPublication.track.getVolume();
12934
12885
  }
12886
+
12887
+ return this.volume;
12935
12888
  }
12936
12889
  /** @internal */
12937
12890
 
@@ -12987,7 +12940,12 @@ class RemoteParticipant extends Participant {
12987
12940
  track.isMuted = publication.isMuted;
12988
12941
  track.setMediaStream(mediaStream);
12989
12942
  track.start();
12990
- publication.setTrack(track);
12943
+ publication.setTrack(track); // set participant volume on new microphone tracks
12944
+
12945
+ if (this.volume !== undefined && track instanceof RemoteAudioTrack && track.source === Track.Source.Microphone) {
12946
+ track.setVolume(this.volume);
12947
+ }
12948
+
12991
12949
  this.emit(ParticipantEvent.TrackSubscribed, track, publication);
12992
12950
  return publication;
12993
12951
  }
@@ -13592,6 +13550,10 @@ class LocalParticipant extends Participant {
13592
13550
  }];
13593
13551
  }
13594
13552
 
13553
+ if (!this.engine || this.engine.isClosed) {
13554
+ throw new UnexpectedConnectionState('cannot publish track when not connected');
13555
+ }
13556
+
13595
13557
  const ti = await this.engine.addTrack(req);
13596
13558
  const publication = new LocalTrackPublication(track.kind, ti, track);
13597
13559
  track.sid = ti.sid;
@@ -17441,7 +17403,7 @@ class SignalClient {
17441
17403
  this.requestQueue = new Queue();
17442
17404
  }
17443
17405
 
17444
- async join(url, token, opts) {
17406
+ async join(url, token, opts, abortSignal) {
17445
17407
  // during a full reconnect, we'd want to start the sequence even if currently
17446
17408
  // connected
17447
17409
  this.isConnected = false;
@@ -17449,7 +17411,7 @@ class SignalClient {
17449
17411
  autoSubscribe: opts === null || opts === void 0 ? void 0 : opts.autoSubscribe,
17450
17412
  publishOnly: opts === null || opts === void 0 ? void 0 : opts.publishOnly,
17451
17413
  adaptiveStream: opts === null || opts === void 0 ? void 0 : opts.adaptiveStream
17452
- });
17414
+ }, abortSignal);
17453
17415
  return res;
17454
17416
  }
17455
17417
 
@@ -17460,7 +17422,7 @@ class SignalClient {
17460
17422
  });
17461
17423
  }
17462
17424
 
17463
- connect(url, token, opts) {
17425
+ connect(url, token, opts, abortSignal) {
17464
17426
  if (url.startsWith('http')) {
17465
17427
  url = url.replace('http', 'ws');
17466
17428
  } // strip trailing slash
@@ -17471,6 +17433,17 @@ class SignalClient {
17471
17433
  const clientInfo = getClientInfo();
17472
17434
  const params = createConnectionParams(token, clientInfo, opts);
17473
17435
  return new Promise((resolve, reject) => {
17436
+ const abortHandler = () => {
17437
+ ws.close();
17438
+ this.close();
17439
+ reject(new ConnectionError('room connection has been cancelled'));
17440
+ };
17441
+
17442
+ if (abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.aborted) {
17443
+ abortHandler();
17444
+ }
17445
+
17446
+ abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.addEventListener('abort', abortHandler);
17474
17447
  livekitLogger.debug("connecting to ".concat(url + params));
17475
17448
  this.ws = undefined;
17476
17449
  const ws = new WebSocket(url + params);
@@ -17526,6 +17499,7 @@ class SignalClient {
17526
17499
  // handle join message only
17527
17500
  if (msg.join) {
17528
17501
  this.isConnected = true;
17502
+ abortSignal === null || abortSignal === void 0 ? void 0 : abortSignal.removeEventListener('abort', abortHandler);
17529
17503
  resolve(msg.join);
17530
17504
  } else {
17531
17505
  reject(new ConnectionError('did not receive join response'));
@@ -17948,7 +17922,7 @@ class RTCEngine extends events.exports.EventEmitter {
17948
17922
  this.rtcConfig = {};
17949
17923
  this.subscriberPrimary = false;
17950
17924
  this.pcState = PCState.New;
17951
- this.isClosed = true;
17925
+ this._isClosed = true;
17952
17926
  this.pendingTrackResolvers = {}; // true if publisher connection has already been established.
17953
17927
  // this is helpful to know if we need to restart ICE on the publisher connection
17954
17928
 
@@ -18019,7 +17993,7 @@ class RTCEngine extends events.exports.EventEmitter {
18019
17993
 
18020
17994
 
18021
17995
  this.handleDisconnect = connection => {
18022
- if (this.isClosed) {
17996
+ if (this._isClosed) {
18023
17997
  return;
18024
17998
  }
18025
17999
 
@@ -18034,7 +18008,7 @@ class RTCEngine extends events.exports.EventEmitter {
18034
18008
  setTimeout(async () => {
18035
18009
  var _a;
18036
18010
 
18037
- if (this.isClosed) {
18011
+ if (this._isClosed) {
18038
18012
  return;
18039
18013
  }
18040
18014
 
@@ -18087,12 +18061,16 @@ class RTCEngine extends events.exports.EventEmitter {
18087
18061
  this.client = new SignalClient();
18088
18062
  }
18089
18063
 
18090
- async join(url, token, opts) {
18064
+ get isClosed() {
18065
+ return this._isClosed;
18066
+ }
18067
+
18068
+ async join(url, token, opts, abortSignal) {
18091
18069
  this.url = url;
18092
18070
  this.token = token;
18093
18071
  this.signalOpts = opts;
18094
- const joinResponse = await this.client.join(url, token, opts);
18095
- this.isClosed = false;
18072
+ const joinResponse = await this.client.join(url, token, opts, abortSignal);
18073
+ this._isClosed = false;
18096
18074
  this.subscriberPrimary = joinResponse.subscriberPrimary;
18097
18075
 
18098
18076
  if (!this.publisher) {
@@ -18109,7 +18087,7 @@ class RTCEngine extends events.exports.EventEmitter {
18109
18087
  }
18110
18088
 
18111
18089
  close() {
18112
- this.isClosed = true;
18090
+ this._isClosed = true;
18113
18091
  this.removeAllListeners();
18114
18092
 
18115
18093
  if (this.publisher && this.publisher.pc.signalingState !== 'closed') {
@@ -18619,13 +18597,18 @@ const videoDefaults = {
18619
18597
  resolution: VideoPresets.h720.resolution
18620
18598
  };
18621
18599
 
18622
- var RoomState;
18600
+ var ConnectionState;
18601
+
18602
+ (function (ConnectionState) {
18603
+ ConnectionState["Disconnected"] = "disconnected";
18604
+ ConnectionState["Connecting"] = "connecting";
18605
+ ConnectionState["Connected"] = "connected";
18606
+ ConnectionState["Reconnecting"] = "reconnecting";
18607
+ })(ConnectionState || (ConnectionState = {}));
18608
+ /** @deprecated RoomState has been renamed to [[ConnectionState]] */
18623
18609
 
18624
- (function (RoomState) {
18625
- RoomState["Disconnected"] = "disconnected";
18626
- RoomState["Connected"] = "connected";
18627
- RoomState["Reconnecting"] = "reconnecting";
18628
- })(RoomState || (RoomState = {}));
18610
+
18611
+ const RoomState = ConnectionState;
18629
18612
  /**
18630
18613
  * In LiveKit, a room is the logical grouping for a list of participants.
18631
18614
  * Participants in a room can publish tracks, and subscribe to others' tracks.
@@ -18635,7 +18618,6 @@ var RoomState;
18635
18618
  * @noInheritDoc
18636
18619
  */
18637
18620
 
18638
-
18639
18621
  class Room extends events.exports.EventEmitter {
18640
18622
  /**
18641
18623
  * Creates a new Room, the primary construct for a LiveKit session.
@@ -18648,7 +18630,7 @@ class Room extends events.exports.EventEmitter {
18648
18630
 
18649
18631
  super();
18650
18632
  _this = this;
18651
- this.state = RoomState.Disconnected;
18633
+ this.state = ConnectionState.Disconnected;
18652
18634
  /**
18653
18635
  * list of participants that are actively speaking. when this changes
18654
18636
  * a [[RoomEvent.ActiveSpeakersChanged]] event is fired
@@ -18671,9 +18653,15 @@ class Room extends events.exports.EventEmitter {
18671
18653
  var _a, _b; // guard against calling connect
18672
18654
 
18673
18655
 
18674
- if (this.state !== RoomState.Disconnected) {
18656
+ if (this.state !== ConnectionState.Disconnected) {
18675
18657
  livekitLogger.warn("already connected to room ".concat(this.name));
18676
18658
  return;
18659
+ }
18660
+
18661
+ this.setAndEmitConnectionState(ConnectionState.Connecting);
18662
+
18663
+ if (!this.abortController || this.abortController.signal.aborted) {
18664
+ this.abortController = new AbortController();
18677
18665
  } // recreate engine if previously disconnected
18678
18666
 
18679
18667
 
@@ -18691,7 +18679,7 @@ class Room extends events.exports.EventEmitter {
18691
18679
  autoSubscribe: opts === null || opts === void 0 ? void 0 : opts.autoSubscribe,
18692
18680
  publishOnly: opts === null || opts === void 0 ? void 0 : opts.publishOnly,
18693
18681
  adaptiveStream: typeof ((_a = this.options) === null || _a === void 0 ? void 0 : _a.adaptiveStream) === 'object' ? true : (_b = this.options) === null || _b === void 0 ? void 0 : _b.adaptiveStream
18694
- });
18682
+ }, this.abortController.signal);
18695
18683
  livekitLogger.debug("connected to Livekit Server version: ".concat(joinResponse.serverVersion, ", region: ").concat(joinResponse.serverRegion));
18696
18684
 
18697
18685
  if (!joinResponse.serverVersion) {
@@ -18704,15 +18692,12 @@ class Room extends events.exports.EventEmitter {
18704
18692
  this.options.dynacast = false;
18705
18693
  }
18706
18694
 
18707
- this.state = RoomState.Connected;
18708
18695
  const pi = joinResponse.participant;
18709
18696
  this.localParticipant.sid = pi.sid;
18710
18697
  this.localParticipant.identity = pi.identity;
18711
18698
  this.localParticipant.updateInfo(pi); // forward metadata changed for the local participant
18712
18699
 
18713
- this.localParticipant.on(ParticipantEvent.MetadataChanged, metadata => {
18714
- this.emit(RoomEvent.MetadataChanged, metadata, this.localParticipant);
18715
- }).on(ParticipantEvent.ParticipantMetadataChanged, metadata => {
18700
+ this.localParticipant.on(ParticipantEvent.ParticipantMetadataChanged, metadata => {
18716
18701
  this.emit(RoomEvent.ParticipantMetadataChanged, metadata, this.localParticipant);
18717
18702
  }).on(ParticipantEvent.TrackMuted, pub => {
18718
18703
  this.emit(RoomEvent.TrackMuted, pub, this.localParticipant);
@@ -18736,29 +18721,48 @@ class Room extends events.exports.EventEmitter {
18736
18721
  this.name = joinResponse.room.name;
18737
18722
  this.sid = joinResponse.room.sid;
18738
18723
  this.metadata = joinResponse.room.metadata;
18739
- this.emit(RoomEvent.StateChanged, this.state);
18740
18724
  } catch (err) {
18741
18725
  this.engine.close();
18726
+ this.setAndEmitConnectionState(ConnectionState.Disconnected);
18742
18727
  throw err;
18743
18728
  } // don't return until ICE connected
18744
18729
 
18745
18730
 
18746
18731
  return new Promise((resolve, reject) => {
18732
+ var _a, _b;
18733
+
18747
18734
  const connectTimeout = setTimeout(() => {
18748
18735
  // timeout
18749
18736
  this.engine.close();
18737
+ this.setAndEmitConnectionState(ConnectionState.Disconnected);
18750
18738
  reject(new ConnectionError('could not connect after timeout'));
18751
18739
  }, maxICEConnectTimeout);
18740
+
18741
+ const abortHandler = () => {
18742
+ livekitLogger.warn('closing engine');
18743
+ clearTimeout(connectTimeout);
18744
+ this.engine.close();
18745
+ this.setAndEmitConnectionState(ConnectionState.Disconnected);
18746
+ reject(new ConnectionError('room connection has been cancelled'));
18747
+ };
18748
+
18749
+ if ((_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
18750
+ abortHandler();
18751
+ }
18752
+
18753
+ (_b = this.abortController) === null || _b === void 0 ? void 0 : _b.signal.addEventListener('abort', abortHandler);
18752
18754
  this.engine.once(EngineEvent.Connected, () => {
18753
- var _a;
18755
+ var _a, _b;
18754
18756
 
18755
- clearTimeout(connectTimeout); // also hook unload event
18757
+ clearTimeout(connectTimeout);
18758
+ (_a = this.abortController) === null || _a === void 0 ? void 0 : _a.signal.removeEventListener('abort', abortHandler); // also hook unload event
18756
18759
 
18757
18760
  if (isWeb()) {
18758
18761
  window.addEventListener('beforeunload', this.onBeforeUnload);
18759
- (_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.addEventListener('devicechange', this.handleDeviceChange);
18762
+ (_b = navigator.mediaDevices) === null || _b === void 0 ? void 0 : _b.addEventListener('devicechange', this.handleDeviceChange);
18760
18763
  }
18761
18764
 
18765
+ this.setAndEmitConnectionState(ConnectionState.Connected);
18762
18766
  resolve(this);
18763
18767
  });
18764
18768
  });
@@ -18771,7 +18775,16 @@ class Room extends events.exports.EventEmitter {
18771
18775
  this.disconnect = function () {
18772
18776
  let stopTracks = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
18773
18777
 
18774
- // send leave
18778
+ var _a;
18779
+
18780
+ if (_this.state === ConnectionState.Connecting) {
18781
+ // try aborting pending connection attempt
18782
+ livekitLogger.warn('abort connection attempt');
18783
+ (_a = _this.abortController) === null || _a === void 0 ? void 0 : _a.abort();
18784
+ return;
18785
+ } // send leave
18786
+
18787
+
18775
18788
  if (_this.engine) {
18776
18789
  _this.engine.client.sendLeave();
18777
18790
 
@@ -18790,9 +18803,8 @@ class Room extends events.exports.EventEmitter {
18790
18803
  };
18791
18804
 
18792
18805
  this.handleRestarting = () => {
18793
- this.state = RoomState.Reconnecting;
18794
- this.emit(RoomEvent.Reconnecting);
18795
- this.emit(RoomEvent.StateChanged, this.state); // also unwind existing participants & existing subscriptions
18806
+ this.setAndEmitConnectionState(ConnectionState.Reconnecting);
18807
+ this.emit(RoomEvent.Reconnecting); // also unwind existing participants & existing subscriptions
18796
18808
 
18797
18809
  for (const p of this.participants.values()) {
18798
18810
  this.handleParticipantDisconnected(p.sid, p);
@@ -18801,9 +18813,8 @@ class Room extends events.exports.EventEmitter {
18801
18813
 
18802
18814
  this.handleRestarted = async joinResponse => {
18803
18815
  livekitLogger.debug("reconnected to server region ".concat(joinResponse.serverRegion));
18804
- this.state = RoomState.Connected;
18805
- this.emit(RoomEvent.Reconnected);
18806
- this.emit(RoomEvent.StateChanged, this.state); // rehydrate participants
18816
+ this.setAndEmitConnectionState(ConnectionState.Connected);
18817
+ this.emit(RoomEvent.Reconnected); // rehydrate participants
18807
18818
 
18808
18819
  if (joinResponse.participant) {
18809
18820
  // with a restart, the sid will have changed, we'll map our understanding to it
@@ -19045,16 +19056,14 @@ class Room extends events.exports.EventEmitter {
19045
19056
  }).on(EngineEvent.Disconnected, () => {
19046
19057
  this.handleDisconnect();
19047
19058
  }).on(EngineEvent.ActiveSpeakersUpdate, this.handleActiveSpeakersUpdate).on(EngineEvent.DataPacketReceived, this.handleDataPacket).on(EngineEvent.Resuming, () => {
19048
- this.state = RoomState.Reconnecting;
19059
+ this.setAndEmitConnectionState(ConnectionState.Reconnecting);
19049
19060
  this.emit(RoomEvent.Reconnecting);
19050
- this.emit(RoomEvent.StateChanged, this.state);
19051
19061
  }).on(EngineEvent.Resumed, () => {
19052
- this.state = RoomState.Connected;
19062
+ this.setAndEmitConnectionState(ConnectionState.Connected);
19053
19063
  this.emit(RoomEvent.Reconnected);
19054
- this.emit(RoomEvent.StateChanged, this.state);
19055
19064
  this.updateSubscriptions();
19056
19065
  }).on(EngineEvent.SignalResumed, () => {
19057
- if (this.state === RoomState.Reconnecting) {
19066
+ if (this.state === ConnectionState.Reconnecting) {
19058
19067
  this.sendSyncState();
19059
19068
  }
19060
19069
  }).on(EngineEvent.Restarting, this.handleRestarting).on(EngineEvent.Restarted, this.handleRestarted);
@@ -19240,10 +19249,6 @@ class Room extends events.exports.EventEmitter {
19240
19249
 
19241
19250
  var _a;
19242
19251
 
19243
- if (this.state === RoomState.Disconnected) {
19244
- return;
19245
- }
19246
-
19247
19252
  this.participants.forEach(p => {
19248
19253
  p.tracks.forEach(pub => {
19249
19254
  p.unpublishTrack(pub.trackSid);
@@ -19274,9 +19279,8 @@ class Room extends events.exports.EventEmitter {
19274
19279
  (_a = navigator.mediaDevices) === null || _a === void 0 ? void 0 : _a.removeEventListener('devicechange', this.handleDeviceChange);
19275
19280
  }
19276
19281
 
19277
- this.state = RoomState.Disconnected;
19282
+ this.setAndEmitConnectionState(ConnectionState.Disconnected);
19278
19283
  this.emit(RoomEvent.Disconnected);
19279
- this.emit(RoomEvent.StateChanged, this.state);
19280
19284
  }
19281
19285
 
19282
19286
  handleParticipantDisconnected(sid, participant) {
@@ -19351,8 +19355,6 @@ class Room extends events.exports.EventEmitter {
19351
19355
  this.emit(RoomEvent.TrackMuted, pub, participant);
19352
19356
  }).on(ParticipantEvent.TrackUnmuted, pub => {
19353
19357
  this.emit(RoomEvent.TrackUnmuted, pub, participant);
19354
- }).on(ParticipantEvent.MetadataChanged, metadata => {
19355
- this.emit(RoomEvent.MetadataChanged, metadata, participant);
19356
19358
  }).on(ParticipantEvent.ParticipantMetadataChanged, metadata => {
19357
19359
  this.emit(RoomEvent.ParticipantMetadataChanged, metadata, participant);
19358
19360
  }).on(ParticipantEvent.ConnectionQualityChanged, quality => {
@@ -19414,6 +19416,15 @@ class Room extends events.exports.EventEmitter {
19414
19416
  }
19415
19417
  }
19416
19418
  }
19419
+ }
19420
+
19421
+ setAndEmitConnectionState(state) {
19422
+ if (state === this.state) {
19423
+ return;
19424
+ }
19425
+
19426
+ this.state = state;
19427
+ this.emit(RoomEvent.ConnectionStateChanged, this.state);
19417
19428
  } // /** @internal */
19418
19429
 
19419
19430
 
@@ -19431,101 +19442,6 @@ class Room extends events.exports.EventEmitter {
19431
19442
 
19432
19443
  }
19433
19444
 
19434
- /**
19435
- * @deprecated Use room.connect() instead
19436
- *
19437
- * Connects to a LiveKit room, shorthand for `new Room()` and [[Room.connect]]
19438
- *
19439
- * ```typescript
19440
- * connect('wss://myhost.livekit.io', token, {
19441
- * // publish audio and video tracks on joining
19442
- * audio: true,
19443
- * video: true,
19444
- * captureDefaults: {
19445
- * facingMode: 'user',
19446
- * },
19447
- * })
19448
- * ```
19449
- * @param url URL to LiveKit server
19450
- * @param token AccessToken, a JWT token that includes authentication and room details
19451
- * @param options
19452
- */
19453
-
19454
- async function connect(url, token, options) {
19455
- var _a, _b, _c, _d;
19456
-
19457
- options !== null && options !== void 0 ? options : options = {};
19458
-
19459
- if (options.adaptiveStream === undefined) {
19460
- options.adaptiveStream = options.autoManageVideo === true ? {} : undefined;
19461
- }
19462
-
19463
- setLogLevel((_a = options.logLevel) !== null && _a !== void 0 ? _a : LogLevel.warn);
19464
- const config = (_b = options.rtcConfig) !== null && _b !== void 0 ? _b : {};
19465
-
19466
- if (options.iceServers) {
19467
- config.iceServers = options.iceServers;
19468
- }
19469
-
19470
- const room = new Room(options); // connect to room
19471
-
19472
- await room.connect(url, token, options);
19473
- const publishAudio = (_c = options.audio) !== null && _c !== void 0 ? _c : false;
19474
- const publishVideo = (_d = options.video) !== null && _d !== void 0 ? _d : false;
19475
-
19476
- if (publishAudio || publishVideo) {
19477
- setTimeout(async () => {
19478
- // if publishing both
19479
- let err;
19480
-
19481
- if (publishAudio && publishVideo) {
19482
- try {
19483
- await room.localParticipant.enableCameraAndMicrophone();
19484
- } catch (e) {
19485
- const errKind = MediaDeviceFailure.getFailure(e);
19486
- livekitLogger.warn('received error while creating media', {
19487
- error: errKind
19488
- });
19489
-
19490
- if (e instanceof Error) {
19491
- livekitLogger.warn(e.message);
19492
- } // when it's a device issue, try to publish the other kind
19493
-
19494
-
19495
- if (errKind === MediaDeviceFailure.NotFound || errKind === MediaDeviceFailure.DeviceInUse) {
19496
- try {
19497
- await room.localParticipant.setMicrophoneEnabled(true);
19498
- } catch (audioErr) {
19499
- err = audioErr;
19500
- }
19501
- } else {
19502
- err = e;
19503
- }
19504
- }
19505
- } else if (publishAudio) {
19506
- try {
19507
- await room.localParticipant.setMicrophoneEnabled(true);
19508
- } catch (e) {
19509
- err = e;
19510
- }
19511
- } else if (publishVideo) {
19512
- try {
19513
- await room.localParticipant.setCameraEnabled(true);
19514
- } catch (e) {
19515
- err = e;
19516
- }
19517
- }
19518
-
19519
- if (err) {
19520
- room.emit(RoomEvent.MediaDevicesError, err);
19521
- livekitLogger.error('could not create media', err);
19522
- }
19523
- });
19524
- }
19525
-
19526
- return room;
19527
- }
19528
-
19529
19445
  /**
19530
19446
  * Creates a local video and audio track at the same time. When acquiring both
19531
19447
  * audio and video tracks together, it'll display a single permission prompt to
@@ -19599,7 +19515,7 @@ async function createLocalScreenTracks(options) {
19599
19515
  }
19600
19516
 
19601
19517
  if (options.resolution === undefined) {
19602
- options.resolution = VideoPresets.fhd.resolution;
19518
+ options.resolution = VideoPresets.h1080.resolution;
19603
19519
  }
19604
19520
 
19605
19521
  let videoConstraints = true;
@@ -19636,5 +19552,5 @@ async function createLocalScreenTracks(options) {
19636
19552
  return localTracks;
19637
19553
  }
19638
19554
 
19639
- export { AudioPresets, ConnectionError, ConnectionQuality, DataPacket_Kind, EngineEvent, LivekitError, LocalAudioTrack, LocalParticipant, LocalTrack, LocalTrackPublication, LocalVideoTrack, LogLevel, MediaDeviceFailure, Participant, ParticipantEvent, PublishDataError, RemoteAudioTrack, RemoteParticipant, RemoteTrack, RemoteTrackPublication, RemoteVideoTrack, Room, RoomEvent, RoomState, ScreenSharePresets, Track, TrackEvent, TrackInvalidError, TrackPublication, UnexpectedConnectionState, UnsupportedServer, VideoPreset, VideoPresets, VideoPresets43, VideoQuality, attachToElement, connect, createLocalAudioTrack, createLocalScreenTracks, createLocalTracks, createLocalVideoTrack, detachTrack, protocolVersion, setLogExtension, setLogLevel, version };
19555
+ export { AudioPresets, ConnectionError, ConnectionQuality, ConnectionState, DataPacket_Kind, EngineEvent, LivekitError, LocalAudioTrack, LocalParticipant, LocalTrack, LocalTrackPublication, LocalVideoTrack, LogLevel, MediaDeviceFailure, Participant, ParticipantEvent, PublishDataError, RemoteAudioTrack, RemoteParticipant, RemoteTrack, RemoteTrackPublication, RemoteVideoTrack, Room, RoomEvent, RoomState, ScreenSharePresets, Track, TrackEvent, TrackInvalidError, TrackPublication, UnexpectedConnectionState, UnsupportedServer, VideoPreset, VideoPresets, VideoPresets43, VideoQuality, attachToElement, createLocalAudioTrack, createLocalScreenTracks, createLocalTracks, createLocalVideoTrack, detachTrack, protocolVersion, setLogExtension, setLogLevel, version };
19640
19556
  //# sourceMappingURL=livekit-client.esm.mjs.map