@stream-io/video-client 0.3.6 → 0.3.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.
package/dist/index.cjs.js CHANGED
@@ -9937,8 +9937,15 @@ class InputMediaDeviceManager {
9937
9937
  if (this.state.status === 'enabled') {
9938
9938
  return;
9939
9939
  }
9940
- yield this.unmuteStream();
9941
- this.state.setStatus('enabled');
9940
+ this.enablePromise = this.unmuteStream();
9941
+ try {
9942
+ yield this.enablePromise;
9943
+ this.state.setStatus('enabled');
9944
+ }
9945
+ catch (error) {
9946
+ this.enablePromise = undefined;
9947
+ throw error;
9948
+ }
9942
9949
  });
9943
9950
  }
9944
9951
  /**
@@ -9952,8 +9959,16 @@ class InputMediaDeviceManager {
9952
9959
  if (this.state.status === 'disabled') {
9953
9960
  return;
9954
9961
  }
9955
- yield this.muteStream(this.state.disableMode === 'stop-tracks');
9956
- this.state.setStatus('disabled');
9962
+ this.disablePromise = this.muteStream(this.state.disableMode === 'stop-tracks');
9963
+ try {
9964
+ yield this.disablePromise;
9965
+ this.state.setStatus('disabled');
9966
+ this.disablePromise = undefined;
9967
+ }
9968
+ catch (error) {
9969
+ this.disablePromise = undefined;
9970
+ throw error;
9971
+ }
9957
9972
  });
9958
9973
  }
9959
9974
  /**
@@ -10049,6 +10064,10 @@ class InputMediaDeviceManager {
10049
10064
  class CameraManager extends InputMediaDeviceManager {
10050
10065
  constructor(call) {
10051
10066
  super(call, new CameraManagerState());
10067
+ this.targetResolution = {
10068
+ width: 1280,
10069
+ height: 720,
10070
+ };
10052
10071
  }
10053
10072
  /**
10054
10073
  * Select the camera direaction
@@ -10074,10 +10093,37 @@ class CameraManager extends InputMediaDeviceManager {
10074
10093
  this.selectDirection(newDirection);
10075
10094
  });
10076
10095
  }
10096
+ /**
10097
+ * @internal
10098
+ */
10099
+ selectTargetResolution(resolution) {
10100
+ var _a;
10101
+ return __awaiter(this, void 0, void 0, function* () {
10102
+ this.targetResolution.height = resolution.height;
10103
+ this.targetResolution.width = resolution.width;
10104
+ if (this.enablePromise) {
10105
+ try {
10106
+ yield this.enablePromise;
10107
+ }
10108
+ catch (error) {
10109
+ // couldn't enable device, target resolution will be applied the next time user attempts to start the device
10110
+ }
10111
+ }
10112
+ if (this.state.status === 'enabled') {
10113
+ const { width, height } = (_a = this.state
10114
+ .mediaStream.getVideoTracks()[0]) === null || _a === void 0 ? void 0 : _a.getSettings();
10115
+ if (width !== this.targetResolution.width ||
10116
+ height !== this.targetResolution.height)
10117
+ yield this.applySettingsToStream();
10118
+ }
10119
+ });
10120
+ }
10077
10121
  getDevices() {
10078
10122
  return getVideoDevices();
10079
10123
  }
10080
10124
  getStream(constraints) {
10125
+ constraints.width = this.targetResolution.width;
10126
+ constraints.height = this.targetResolution.height;
10081
10127
  // We can't set both device id and facing mode
10082
10128
  // Device id has higher priority
10083
10129
  if (!constraints.deviceId && this.state.direction) {
@@ -11313,63 +11359,69 @@ class Call {
11313
11359
  return ((_a = this.state.createdBy) === null || _a === void 0 ? void 0 : _a.id) === this.currentUserId;
11314
11360
  }
11315
11361
  initCamera() {
11316
- var _a, _b, _c;
11362
+ var _a, _b, _c, _d, _e;
11317
11363
  return __awaiter(this, void 0, void 0, function* () {
11364
+ // Wait for any in progress camera operation
11365
+ if (this.camera.enablePromise) {
11366
+ yield this.camera.enablePromise;
11367
+ }
11368
+ if (this.camera.disablePromise) {
11369
+ yield this.camera.disablePromise;
11370
+ }
11318
11371
  if (((_a = this.state.localParticipant) === null || _a === void 0 ? void 0 : _a.videoStream) ||
11319
11372
  !this.permissionsContext.hasPermission('send-video')) {
11320
11373
  return;
11321
11374
  }
11322
11375
  // Set camera direction if it's not yet set
11323
- // This will also start publishing if camera is enabled
11324
11376
  if (!this.camera.state.direction && !this.camera.state.selectedDevice) {
11325
11377
  let defaultDirection = 'front';
11326
11378
  const backendSetting = (_b = this.state.settings) === null || _b === void 0 ? void 0 : _b.video.camera_facing;
11327
11379
  if (backendSetting) {
11328
11380
  defaultDirection = backendSetting === 'front' ? 'front' : 'back';
11329
11381
  }
11330
- this.camera.selectDirection(defaultDirection);
11331
- }
11332
- else if (this.camera.state.status === 'enabled') {
11333
- // Publish already started media streams (this is the case if there is a lobby screen before join)
11334
- // Wait for media stream
11335
- this.camera.state.mediaStream$
11336
- .pipe(rxjs.takeWhile((s) => s === undefined, true))
11337
- .subscribe((stream) => {
11338
- var _a;
11339
- if (!((_a = this.state.localParticipant) === null || _a === void 0 ? void 0 : _a.videoStream)) {
11340
- this.publishVideoStream(stream);
11341
- }
11342
- });
11382
+ this.camera.state.setDirection(defaultDirection);
11343
11383
  }
11344
- // Apply backend config (this is the case if there is no lobby screen before join)
11384
+ // Set target resolution
11385
+ const targetResolution = (_c = this.state.settings) === null || _c === void 0 ? void 0 : _c.video.target_resolution;
11386
+ if (targetResolution) {
11387
+ yield this.camera.selectTargetResolution(targetResolution);
11388
+ }
11389
+ // Publish already that was set before we joined
11390
+ if (this.camera.state.status === 'enabled' &&
11391
+ this.camera.state.mediaStream &&
11392
+ !((_d = this.publisher) === null || _d === void 0 ? void 0 : _d.isPublishing(TrackType.VIDEO))) {
11393
+ yield this.publishVideoStream(this.camera.state.mediaStream);
11394
+ }
11395
+ // Start camera if backend config speicifies, and there is no local setting
11345
11396
  if (this.camera.state.status === undefined &&
11346
- ((_c = this.state.settings) === null || _c === void 0 ? void 0 : _c.video.camera_default_on)) {
11397
+ ((_e = this.state.settings) === null || _e === void 0 ? void 0 : _e.video.camera_default_on)) {
11347
11398
  yield this.camera.enable();
11348
11399
  }
11349
11400
  });
11350
11401
  }
11351
11402
  initMic() {
11352
- var _a, _b;
11403
+ var _a, _b, _c;
11353
11404
  return __awaiter(this, void 0, void 0, function* () {
11405
+ // Wait for any in progress mic operation
11406
+ if (this.microphone.enablePromise) {
11407
+ yield this.microphone.enablePromise;
11408
+ }
11409
+ if (this.microphone.disablePromise) {
11410
+ yield this.microphone.disablePromise;
11411
+ }
11354
11412
  if (((_a = this.state.localParticipant) === null || _a === void 0 ? void 0 : _a.audioStream) ||
11355
11413
  !this.permissionsContext.hasPermission('send-audio')) {
11356
11414
  return;
11357
11415
  }
11358
- // Publish already started media streams (this is the case if there is a lobby screen before join)
11359
- if (this.microphone.state.status === 'enabled') {
11360
- // Wait for media stream
11361
- this.microphone.state.mediaStream$
11362
- .pipe(rxjs.takeWhile((s) => s === undefined, true))
11363
- .subscribe((stream) => {
11364
- var _a;
11365
- if (!((_a = this.state.localParticipant) === null || _a === void 0 ? void 0 : _a.audioStream)) {
11366
- this.publishAudioStream(stream);
11367
- }
11368
- });
11416
+ // Publish media stream that was set before we joined
11417
+ if (this.microphone.state.status === 'enabled' &&
11418
+ this.microphone.state.mediaStream &&
11419
+ !((_b = this.publisher) === null || _b === void 0 ? void 0 : _b.isPublishing(TrackType.AUDIO))) {
11420
+ this.publishAudioStream(this.microphone.state.mediaStream);
11369
11421
  }
11370
- // Apply backend config (this is the case if there is no lobby screen before join)
11422
+ // Start mic if backend config speicifies, and there is no local setting
11371
11423
  if (this.microphone.state.status === undefined &&
11372
- ((_b = this.state.settings) === null || _b === void 0 ? void 0 : _b.audio.mic_default_on)) {
11424
+ ((_c = this.state.settings) === null || _c === void 0 ? void 0 : _c.audio.mic_default_on)) {
11373
11425
  yield this.microphone.enable();
11374
11426
  }
11375
11427
  });
@@ -12485,7 +12537,7 @@ class WSConnectionFallback {
12485
12537
  }
12486
12538
  }
12487
12539
 
12488
- const version = '0.3.6';
12540
+ const version = '0.3.7';
12489
12541
 
12490
12542
  const logger = getLogger(['location']);
12491
12543
  const HINT_URL = `https://hint.stream-io-video.com/`;