livekit-client 2.11.2 → 2.11.4

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.
@@ -11109,7 +11109,7 @@ var TrackEvent;
11109
11109
 
11110
11110
  function cloneDeep(value) {
11111
11111
  if (typeof value === 'undefined') {
11112
- return;
11112
+ return value;
11113
11113
  }
11114
11114
  if (typeof structuredClone === 'function') {
11115
11115
  return structuredClone(value);
@@ -11186,7 +11186,7 @@ function getOSVersion(ua) {
11186
11186
  return ua.includes('mac os') ? getMatch(/\(.+?(\d+_\d+(:?_\d+)?)/, ua, 1).replace(/_/g, '.') : undefined;
11187
11187
  }
11188
11188
 
11189
- var version$1 = "2.11.2";
11189
+ var version$1 = "2.11.4";
11190
11190
 
11191
11191
  const version = version$1;
11192
11192
  const protocolVersion = 15;
@@ -12062,6 +12062,12 @@ function unwrapConstraint(constraint) {
12062
12062
  }
12063
12063
  throw Error('could not unwrap constraint');
12064
12064
  }
12065
+ function toWebsocketUrl(url) {
12066
+ if (url.startsWith('http')) {
12067
+ return url.replace(/^(http)/, 'ws');
12068
+ }
12069
+ return url;
12070
+ }
12065
12071
  function toHttpUrl(url) {
12066
12072
  if (url.startsWith('ws')) {
12067
12073
  return url.replace(/^(ws)/, 'http');
@@ -12187,8 +12193,8 @@ function splitUtf8(s, n) {
12187
12193
  }
12188
12194
 
12189
12195
  function mergeDefaultOptions(options, audioDefaults, videoDefaults) {
12190
- var _a, _b, _c;
12191
- var _d, _e;
12196
+ var _a, _b;
12197
+ var _c, _d;
12192
12198
  const {
12193
12199
  optionsWithoutProcessor,
12194
12200
  audioProcessor,
@@ -12196,13 +12202,13 @@ function mergeDefaultOptions(options, audioDefaults, videoDefaults) {
12196
12202
  } = extractProcessorsFromOptions(options !== null && options !== void 0 ? options : {});
12197
12203
  const defaultAudioProcessor = audioDefaults === null || audioDefaults === void 0 ? void 0 : audioDefaults.processor;
12198
12204
  const defaultVideoProcessor = videoDefaults === null || videoDefaults === void 0 ? void 0 : videoDefaults.processor;
12199
- const clonedOptions = (_a = cloneDeep(optionsWithoutProcessor)) !== null && _a !== void 0 ? _a : {};
12205
+ const clonedOptions = optionsWithoutProcessor !== null && optionsWithoutProcessor !== void 0 ? optionsWithoutProcessor : {};
12200
12206
  if (clonedOptions.audio === true) clonedOptions.audio = {};
12201
12207
  if (clonedOptions.video === true) clonedOptions.video = {};
12202
12208
  // use defaults
12203
12209
  if (clonedOptions.audio) {
12204
12210
  mergeObjectWithoutOverwriting(clonedOptions.audio, audioDefaults);
12205
- (_b = (_d = clonedOptions.audio).deviceId) !== null && _b !== void 0 ? _b : _d.deviceId = {
12211
+ (_a = (_c = clonedOptions.audio).deviceId) !== null && _a !== void 0 ? _a : _c.deviceId = {
12206
12212
  ideal: 'default'
12207
12213
  };
12208
12214
  if (audioProcessor || defaultAudioProcessor) {
@@ -12211,7 +12217,7 @@ function mergeDefaultOptions(options, audioDefaults, videoDefaults) {
12211
12217
  }
12212
12218
  if (clonedOptions.video) {
12213
12219
  mergeObjectWithoutOverwriting(clonedOptions.video, videoDefaults);
12214
- (_c = (_e = clonedOptions.video).deviceId) !== null && _c !== void 0 ? _c : _e.deviceId = {
12220
+ (_b = (_d = clonedOptions.video).deviceId) !== null && _b !== void 0 ? _b : _d.deviceId = {
12215
12221
  ideal: 'default'
12216
12222
  };
12217
12223
  if (videoProcessor || defaultVideoProcessor) {
@@ -12334,6 +12340,18 @@ function getNewAudioContext() {
12334
12340
  return audioContext;
12335
12341
  }
12336
12342
  }
12343
+ /**
12344
+ * @internal
12345
+ */
12346
+ function kindToSource(kind) {
12347
+ if (kind === 'audioinput') {
12348
+ return Track.Source.Microphone;
12349
+ } else if (kind === 'videoinput') {
12350
+ return Track.Source.Camera;
12351
+ } else {
12352
+ return Track.Source.Unknown;
12353
+ }
12354
+ }
12337
12355
  /**
12338
12356
  * @internal
12339
12357
  */
@@ -12469,7 +12487,7 @@ function extractProcessorsFromOptions(options) {
12469
12487
  return {
12470
12488
  audioProcessor,
12471
12489
  videoProcessor,
12472
- optionsWithoutProcessor: newOptions
12490
+ optionsWithoutProcessor: cloneDeep(newOptions)
12473
12491
  };
12474
12492
  }
12475
12493
  function getTrackSourceFromProto(source) {
@@ -12966,7 +12984,7 @@ class AsyncQueue {
12966
12984
  }
12967
12985
 
12968
12986
  function createRtcUrl(url, searchParams) {
12969
- const urlObj = new URL(url);
12987
+ const urlObj = new URL(toWebsocketUrl(url));
12970
12988
  searchParams.forEach((value, key) => {
12971
12989
  urlObj.searchParams.set(key, value);
12972
12990
  });
@@ -19442,13 +19460,23 @@ class LocalTrackPublication extends TrackPublication {
19442
19460
  */
19443
19461
  function createLocalTracks(options, loggerOptions) {
19444
19462
  return __awaiter(this, void 0, void 0, function* () {
19445
- // set default options to true
19446
- const internalOptions = Object.assign({}, options !== null && options !== void 0 ? options : {});
19463
+ options !== null && options !== void 0 ? options : options = {};
19447
19464
  let attemptExactMatch = false;
19448
- let retryAudioOptions = options === null || options === void 0 ? void 0 : options.audio;
19449
- let retryVideoOptions = options === null || options === void 0 ? void 0 : options.video;
19465
+ const {
19466
+ audioProcessor,
19467
+ videoProcessor,
19468
+ optionsWithoutProcessor: internalOptions
19469
+ } = extractProcessorsFromOptions(options);
19470
+ let retryAudioOptions = internalOptions.audio;
19471
+ let retryVideoOptions = internalOptions.video;
19472
+ if (audioProcessor && typeof internalOptions.audio === 'object') {
19473
+ internalOptions.audio.processor = audioProcessor;
19474
+ }
19475
+ if (videoProcessor && typeof internalOptions.video === 'object') {
19476
+ internalOptions.video.processor = videoProcessor;
19477
+ }
19450
19478
  // if the user passes a device id as a string, we default to exact match
19451
- if (internalOptions.audio && typeof internalOptions.audio === 'object' && typeof internalOptions.audio.deviceId === 'string') {
19479
+ if (options.audio && typeof internalOptions.audio === 'object' && typeof internalOptions.audio.deviceId === 'string') {
19452
19480
  const deviceId = internalOptions.audio.deviceId;
19453
19481
  internalOptions.audio.deviceId = {
19454
19482
  exact: deviceId
@@ -19483,10 +19511,6 @@ function createLocalTracks(options, loggerOptions) {
19483
19511
  deviceId: 'default'
19484
19512
  };
19485
19513
  }
19486
- const {
19487
- audioProcessor,
19488
- videoProcessor
19489
- } = extractProcessorsFromOptions(internalOptions);
19490
19514
  const opts = mergeDefaultOptions(internalOptions, audioDefaults, videoDefaults);
19491
19515
  const constraints = constraintsForOptions(opts);
19492
19516
  // Keep a reference to the promise on DeviceManager and await it in getLocalDevices()
@@ -22795,7 +22819,7 @@ class Room extends eventsExports.EventEmitter {
22795
22819
  }
22796
22820
  };
22797
22821
  this.handleDeviceChange = () => __awaiter(this, void 0, void 0, function* () {
22798
- var _a, _b;
22822
+ var _a, _b, _c;
22799
22823
  const previousDevices = DeviceManager.getInstance().previousDevices;
22800
22824
  // check for available devices, but don't request permissions in order to avoid prompts for kinds that haven't been used before
22801
22825
  const availableDevices = yield DeviceManager.getInstance().getDevices(undefined, false);
@@ -22812,15 +22836,20 @@ class Room extends eventsExports.EventEmitter {
22812
22836
  }
22813
22837
  }
22814
22838
  }
22815
- // inputs are automatically handled via TrackEvent.Ended causing a TrackEvent.Restarted. Here we only need to worry about audiooutputs changing
22816
22839
  const kinds = ['audiooutput', 'audioinput', 'videoinput'];
22817
22840
  for (let kind of kinds) {
22841
+ const targetSource = kindToSource(kind);
22842
+ const targetPublication = this.localParticipant.getTrackPublication(targetSource);
22843
+ if (targetPublication && ((_a = targetPublication.track) === null || _a === void 0 ? void 0 : _a.isUserProvided)) {
22844
+ // if the track is user provided, we don't want to switch devices on behalf of the user
22845
+ continue;
22846
+ }
22818
22847
  const devicesOfKind = availableDevices.filter(d => d.kind === kind);
22819
22848
  const activeDevice = this.getActiveDevice(kind);
22820
- if (activeDevice === ((_a = previousDevices.filter(info => info.kind === kind)[0]) === null || _a === void 0 ? void 0 : _a.deviceId)) {
22849
+ if (activeDevice === ((_b = previousDevices.filter(info => info.kind === kind)[0]) === null || _b === void 0 ? void 0 : _b.deviceId)) {
22821
22850
  // in Safari the first device is always the default, so we assume a user on the default device would like to switch to the default once it changes
22822
22851
  // FF doesn't emit an event when the default device changes, so we perform the same best effort and switch to the new device once connected and if it's the first in the array
22823
- if (devicesOfKind.length > 0 && ((_b = devicesOfKind[0]) === null || _b === void 0 ? void 0 : _b.deviceId) !== activeDevice) {
22852
+ if (devicesOfKind.length > 0 && ((_c = devicesOfKind[0]) === null || _c === void 0 ? void 0 : _c.deviceId) !== activeDevice) {
22824
22853
  yield this.switchActiveDevice(kind, devicesOfKind[0].deviceId);
22825
22854
  continue;
22826
22855
  }