livekit-client 1.0.2 → 1.1.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.
@@ -10058,7 +10058,7 @@ function computeBitrate(currentStats, prevStats) {
10058
10058
  return (bytesNow - bytesPrev) * 8 * 1000 / (currentStats.timestamp - prevStats.timestamp);
10059
10059
  }
10060
10060
 
10061
- var version$1 = "1.0.2";
10061
+ var version$1 = "1.1.0";
10062
10062
 
10063
10063
  const version = version$1;
10064
10064
  const protocolVersion = 8;
@@ -13755,8 +13755,8 @@ class LocalParticipant extends Participant {
13755
13755
  */
13756
13756
 
13757
13757
 
13758
- setCameraEnabled(enabled) {
13759
- return this.setTrackEnabled(Track.Source.Camera, enabled);
13758
+ setCameraEnabled(enabled, options) {
13759
+ return this.setTrackEnabled(Track.Source.Camera, enabled, options);
13760
13760
  }
13761
13761
  /**
13762
13762
  * Enable or disable a participant's microphone track.
@@ -13766,8 +13766,8 @@ class LocalParticipant extends Participant {
13766
13766
  */
13767
13767
 
13768
13768
 
13769
- setMicrophoneEnabled(enabled) {
13770
- return this.setTrackEnabled(Track.Source.Microphone, enabled);
13769
+ setMicrophoneEnabled(enabled, options) {
13770
+ return this.setTrackEnabled(Track.Source.Microphone, enabled, options);
13771
13771
  }
13772
13772
  /**
13773
13773
  * Start or stop sharing a participant's screen
@@ -13775,8 +13775,8 @@ class LocalParticipant extends Participant {
13775
13775
  */
13776
13776
 
13777
13777
 
13778
- setScreenShareEnabled(enabled) {
13779
- return this.setTrackEnabled(Track.Source.ScreenShare, enabled);
13778
+ setScreenShareEnabled(enabled, options) {
13779
+ return this.setTrackEnabled(Track.Source.ScreenShare, enabled, options);
13780
13780
  }
13781
13781
  /** @internal */
13782
13782
 
@@ -13791,14 +13791,10 @@ class LocalParticipant extends Participant {
13791
13791
 
13792
13792
  return changed;
13793
13793
  }
13794
- /**
13795
- * Enable or disable publishing for a track by source. This serves as a simple
13796
- * way to manage the common tracks (camera, mic, or screen share).
13797
- * Resolves with LocalTrackPublication if successful and void otherwise
13798
- */
13799
13794
 
13795
+ async setTrackEnabled(source, enabled, options) {
13796
+ var _a, _b;
13800
13797
 
13801
- async setTrackEnabled(source, enabled) {
13802
13798
  livekitLogger.debug('setTrackEnabled', {
13803
13799
  source,
13804
13800
  enabled
@@ -13809,7 +13805,7 @@ class LocalParticipant extends Participant {
13809
13805
  if (track) {
13810
13806
  await track.unmute();
13811
13807
  } else {
13812
- let localTrack;
13808
+ let localTracks;
13813
13809
 
13814
13810
  if (this.pendingPublishing.has(source)) {
13815
13811
  livekitLogger.info('skipping duplicate published source', {
@@ -13824,28 +13820,35 @@ class LocalParticipant extends Participant {
13824
13820
  try {
13825
13821
  switch (source) {
13826
13822
  case Track.Source.Camera:
13827
- [localTrack] = await this.createTracks({
13828
- video: true
13823
+ localTracks = await this.createTracks({
13824
+ video: (_a = options) !== null && _a !== void 0 ? _a : true
13829
13825
  });
13830
13826
  break;
13831
13827
 
13832
13828
  case Track.Source.Microphone:
13833
- [localTrack] = await this.createTracks({
13834
- audio: true
13829
+ localTracks = await this.createTracks({
13830
+ audio: (_b = options) !== null && _b !== void 0 ? _b : true
13835
13831
  });
13836
13832
  break;
13837
13833
 
13838
13834
  case Track.Source.ScreenShare:
13839
- [localTrack] = await this.createScreenTracks({
13840
- audio: false
13841
- });
13835
+ localTracks = await this.createScreenTracks(_objectSpread2({}, options));
13842
13836
  break;
13843
13837
 
13844
13838
  default:
13845
13839
  throw new TrackInvalidError(source);
13846
13840
  }
13847
13841
 
13848
- track = await this.publishTrack(localTrack);
13842
+ const publishPromises = [];
13843
+
13844
+ for (const localTrack of localTracks) {
13845
+ publishPromises.push(this.publishTrack(localTrack));
13846
+ }
13847
+
13848
+ const publishedTracks = await Promise.all(publishPromises); // for screen share publications including audio, this will only return the screen share publication, not the screen share audio one
13849
+ // revisit if we want to return an array of tracks instead for v2
13850
+
13851
+ [track] = publishedTracks;
13849
13852
  } catch (e) {
13850
13853
  if (e instanceof Error && !(e instanceof TrackInvalidError)) {
13851
13854
  this.emit(ParticipantEvent.MediaDevicesError, e);
@@ -13860,6 +13863,11 @@ class LocalParticipant extends Participant {
13860
13863
  // screenshare cannot be muted, unpublish instead
13861
13864
  if (source === Track.Source.ScreenShare) {
13862
13865
  track = this.unpublishTrack(track.track);
13866
+ const screenAudioTrack = this.getTrack(Track.Source.ScreenShareAudio);
13867
+
13868
+ if (screenAudioTrack && screenAudioTrack.track) {
13869
+ this.unpublishTrack(screenAudioTrack.track);
13870
+ }
13863
13871
  } else {
13864
13872
  await track.mute();
13865
13873
  }
@@ -14371,38 +14379,41 @@ class LocalParticipant extends Participant {
14371
14379
  const cap = RTCRtpSender.getCapabilities(kind);
14372
14380
  if (!cap) return;
14373
14381
  livekitLogger.debug('get capabilities', cap);
14374
- let selected;
14375
- const codecs = [];
14382
+ const matched = [];
14383
+ const partialMatched = [];
14384
+ const unmatched = [];
14376
14385
  cap.codecs.forEach(c => {
14377
14386
  const codec = c.mimeType.toLowerCase();
14387
+
14388
+ if (codec === 'audio/opus') {
14389
+ matched.push(c);
14390
+ return;
14391
+ }
14392
+
14378
14393
  const matchesVideoCodec = codec === "video/".concat(videoCodec);
14379
14394
 
14380
- if (selected !== undefined) {
14381
- codecs.push(c);
14395
+ if (!matchesVideoCodec) {
14396
+ unmatched.push(c);
14382
14397
  return;
14383
14398
  } // for h264 codecs that have sdpFmtpLine available, use only if the
14384
14399
  // profile-level-id is 42e01f for cross-browser compatibility
14385
14400
 
14386
14401
 
14387
- if (videoCodec === 'h264' && c.sdpFmtpLine) {
14388
- if (matchesVideoCodec && c.sdpFmtpLine.includes('profile-level-id=42e01f')) {
14389
- selected = c;
14390
- return;
14402
+ if (videoCodec === 'h264') {
14403
+ if (c.sdpFmtpLine && c.sdpFmtpLine.includes('profile-level-id=42e01f')) {
14404
+ matched.push(c);
14405
+ } else {
14406
+ partialMatched.push(c);
14391
14407
  }
14392
- }
14393
14408
 
14394
- if (matchesVideoCodec || codec === 'audio/opus') {
14395
- selected = c;
14396
14409
  return;
14397
14410
  }
14398
14411
 
14399
- codecs.push(c);
14412
+ matched.push(c);
14400
14413
  });
14401
14414
 
14402
- if (selected && 'setCodecPreferences' in transceiver) {
14403
- // @ts-ignore
14404
- codecs.unshift(selected);
14405
- transceiver.setCodecPreferences(codecs);
14415
+ if ('setCodecPreferences' in transceiver) {
14416
+ transceiver.setCodecPreferences(matched.concat(partialMatched, unmatched));
14406
14417
  }
14407
14418
  }
14408
14419
  /** @internal */
@@ -19214,7 +19225,8 @@ const publishDefaults = {
19214
19225
  dtx: true,
19215
19226
  simulcast: true,
19216
19227
  screenShareEncoding: ScreenSharePresets.h1080fps15.encoding,
19217
- stopMicTrackOnMute: false
19228
+ stopMicTrackOnMute: false,
19229
+ videoCodec: 'vp8'
19218
19230
  };
19219
19231
  const audioDefaults = {
19220
19232
  autoGainControl: true,
@@ -19509,8 +19521,7 @@ class Room extends events.exports.EventEmitter {
19509
19521
  if (info.state === ParticipantInfo_State.DISCONNECTED) {
19510
19522
  this.handleParticipantDisconnected(info.sid, remoteParticipant);
19511
19523
  } else if (isNewParticipant) {
19512
- this.identityToSid.set(info.identity, info.sid); // fire connected event
19513
-
19524
+ // fire connected event
19514
19525
  this.emit(RoomEvent.ParticipantConnected, remoteParticipant);
19515
19526
  } else {
19516
19527
  // just update, no events
@@ -20009,10 +20020,15 @@ class Room extends events.exports.EventEmitter {
20009
20020
 
20010
20021
 
20011
20022
  const participant = this.createParticipant(id, info);
20012
- this.participants.set(id, participant); // also forward events
20023
+ this.participants.set(id, participant);
20024
+
20025
+ if (info) {
20026
+ this.identityToSid.set(info.identity, info.sid);
20027
+ } // also forward events
20013
20028
  // trackPublished is only fired for tracks added after both local participant
20014
20029
  // and remote participant joined the room
20015
20030
 
20031
+
20016
20032
  participant.on(ParticipantEvent.TrackPublished, trackPublication => {
20017
20033
  this.emit(RoomEvent.TrackPublished, trackPublication, participant);
20018
20034
  }).on(ParticipantEvent.TrackSubscribed, (track, publication) => {