@stream-io/video-client 0.3.2 → 0.3.3

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.es.js CHANGED
@@ -6617,6 +6617,9 @@ class Publisher {
6617
6617
  previousTrack.removeEventListener('ended', handleTrackEnded);
6618
6618
  track.addEventListener('ended', handleTrackEnded);
6619
6619
  }
6620
+ if (!track.enabled) {
6621
+ track.enabled = true;
6622
+ }
6620
6623
  yield transceiver.sender.replaceTrack(track);
6621
6624
  }
6622
6625
  yield this.notifyTrackMuteStateChanged(mediaStream, track, trackType, false);
@@ -6625,15 +6628,18 @@ class Publisher {
6625
6628
  * Stops publishing the given track type to the SFU, if it is currently being published.
6626
6629
  * Underlying track will be stopped and removed from the publisher.
6627
6630
  * @param trackType the track type to unpublish.
6631
+ * @param stopTrack specifies whether track should be stopped or just disabled
6628
6632
  */
6629
- this.unpublishStream = (trackType) => __awaiter(this, void 0, void 0, function* () {
6633
+ this.unpublishStream = (trackType, stopTrack) => __awaiter(this, void 0, void 0, function* () {
6630
6634
  const transceiver = this.pc
6631
6635
  .getTransceivers()
6632
6636
  .find((t) => t === this.transceiverRegistry[trackType] && t.sender.track);
6633
6637
  if (transceiver &&
6634
6638
  transceiver.sender.track &&
6635
6639
  transceiver.sender.track.readyState === 'live') {
6636
- transceiver.sender.track.stop();
6640
+ stopTrack
6641
+ ? transceiver.sender.track.stop()
6642
+ : (transceiver.sender.track.enabled = false);
6637
6643
  return this.notifyTrackMuteStateChanged(undefined, transceiver.sender.track, trackType, true);
6638
6644
  }
6639
6645
  });
@@ -9520,7 +9526,8 @@ const CallTypes = new CallTypesRegistry([
9520
9526
  ]);
9521
9527
 
9522
9528
  class InputMediaDeviceManagerState {
9523
- constructor() {
9529
+ constructor(disableMode = 'stop-tracks') {
9530
+ this.disableMode = disableMode;
9524
9531
  this.statusSubject = new BehaviorSubject(undefined);
9525
9532
  this.mediaStreamSubject = new BehaviorSubject(undefined);
9526
9533
  this.selectedDeviceSubject = new BehaviorSubject(undefined);
@@ -9547,7 +9554,9 @@ class InputMediaDeviceManagerState {
9547
9554
  this.selectedDevice$ = this.selectedDeviceSubject
9548
9555
  .asObservable()
9549
9556
  .pipe(distinctUntilChanged$1());
9550
- this.status$ = this.statusSubject.asObservable();
9557
+ this.status$ = this.statusSubject
9558
+ .asObservable()
9559
+ .pipe(distinctUntilChanged$1());
9551
9560
  }
9552
9561
  /**
9553
9562
  * The device status
@@ -9595,7 +9604,7 @@ class InputMediaDeviceManagerState {
9595
9604
 
9596
9605
  class CameraManagerState extends InputMediaDeviceManagerState {
9597
9606
  constructor() {
9598
- super();
9607
+ super('stop-tracks');
9599
9608
  this.directionSubject = new BehaviorSubject(undefined);
9600
9609
  this.direction$ = this.directionSubject
9601
9610
  .asObservable()
@@ -9908,12 +9917,13 @@ class InputMediaDeviceManager {
9908
9917
  if (this.state.status === 'enabled') {
9909
9918
  return;
9910
9919
  }
9911
- yield this.startStream();
9920
+ yield this.unmuteStream();
9912
9921
  this.state.setStatus('enabled');
9913
9922
  });
9914
9923
  }
9915
9924
  /**
9916
9925
  * Stops camera/microphone
9926
+ *
9917
9927
  * @returns
9918
9928
  */
9919
9929
  disable() {
@@ -9921,12 +9931,25 @@ class InputMediaDeviceManager {
9921
9931
  if (this.state.status === 'disabled') {
9922
9932
  return;
9923
9933
  }
9924
- yield this.stopStream();
9934
+ this.state.prevStatus = this.state.status;
9935
+ yield this.muteStream(this.state.disableMode === 'stop-tracks');
9925
9936
  this.state.setStatus('disabled');
9926
9937
  });
9927
9938
  }
9939
+ /**
9940
+ * If status was previously enabled, it will reenable the device.
9941
+ */
9942
+ resume() {
9943
+ return __awaiter(this, void 0, void 0, function* () {
9944
+ if (this.state.prevStatus === 'enabled' &&
9945
+ this.state.status === 'disabled') {
9946
+ this.enable();
9947
+ }
9948
+ });
9949
+ }
9928
9950
  /**
9929
9951
  * If current device statis is disabled, it will enable the device, else it will disable it.
9952
+ *
9930
9953
  * @returns
9931
9954
  */
9932
9955
  toggle() {
@@ -9961,32 +9984,40 @@ class InputMediaDeviceManager {
9961
9984
  applySettingsToStream() {
9962
9985
  return __awaiter(this, void 0, void 0, function* () {
9963
9986
  if (this.state.status === 'enabled') {
9964
- yield this.stopStream();
9965
- yield this.startStream();
9987
+ yield this.muteStream();
9988
+ yield this.unmuteStream();
9966
9989
  }
9967
9990
  });
9968
9991
  }
9969
- stopStream() {
9992
+ muteStream(stopTracks = true) {
9970
9993
  return __awaiter(this, void 0, void 0, function* () {
9971
9994
  if (!this.state.mediaStream) {
9972
9995
  return;
9973
9996
  }
9974
9997
  if (this.call.state.callingState === CallingState.JOINED) {
9975
- yield this.stopPublishStream();
9998
+ yield this.stopPublishStream(stopTracks);
9976
9999
  }
9977
10000
  else if (this.state.mediaStream) {
9978
- disposeOfMediaStream(this.state.mediaStream);
10001
+ stopTracks
10002
+ ? disposeOfMediaStream(this.state.mediaStream)
10003
+ : this.muteTracks();
10004
+ }
10005
+ if (stopTracks) {
10006
+ this.state.setMediaStream(undefined);
9979
10007
  }
9980
- this.state.setMediaStream(undefined);
9981
10008
  });
9982
10009
  }
9983
- startStream() {
10010
+ unmuteStream() {
9984
10011
  return __awaiter(this, void 0, void 0, function* () {
10012
+ let stream;
9985
10013
  if (this.state.mediaStream) {
9986
- return;
10014
+ stream = this.state.mediaStream;
10015
+ this.unmuteTracks();
10016
+ }
10017
+ else {
10018
+ const constraints = { deviceId: this.state.selectedDevice };
10019
+ stream = yield this.getStream(constraints);
9987
10020
  }
9988
- const constraints = { deviceId: this.state.selectedDevice };
9989
- const stream = yield this.getStream(constraints);
9990
10021
  if (this.call.state.callingState === CallingState.JOINED) {
9991
10022
  yield this.publishStream(stream);
9992
10023
  }
@@ -10038,30 +10069,23 @@ class CameraManager extends InputMediaDeviceManager {
10038
10069
  publishStream(stream) {
10039
10070
  return this.call.publishVideoStream(stream);
10040
10071
  }
10041
- stopPublishStream() {
10042
- return this.call.stopPublish(TrackType.VIDEO);
10072
+ stopPublishStream(stopTracks) {
10073
+ return this.call.stopPublish(TrackType.VIDEO, stopTracks);
10043
10074
  }
10044
- /**
10045
- * Disables the video tracks of the camera
10046
- */
10047
- pause() {
10075
+ muteTracks() {
10048
10076
  var _a;
10049
- (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks().forEach((track) => {
10050
- track.enabled = false;
10051
- });
10077
+ (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks().forEach((t) => (t.enabled = false));
10052
10078
  }
10053
- /**
10054
- * (Re)enables the video tracks of the camera
10055
- */
10056
- resume() {
10079
+ unmuteTracks() {
10057
10080
  var _a;
10058
- (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks().forEach((track) => {
10059
- track.enabled = true;
10060
- });
10081
+ (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks().forEach((t) => (t.enabled = true));
10061
10082
  }
10062
10083
  }
10063
10084
 
10064
10085
  class MicrophoneManagerState extends InputMediaDeviceManagerState {
10086
+ constructor() {
10087
+ super('disable-tracks');
10088
+ }
10065
10089
  getDeviceIdFromStream(stream) {
10066
10090
  var _a;
10067
10091
  return (_a = stream.getAudioTracks()[0]) === null || _a === void 0 ? void 0 : _a.getSettings().deviceId;
@@ -10081,26 +10105,16 @@ class MicrophoneManager extends InputMediaDeviceManager {
10081
10105
  publishStream(stream) {
10082
10106
  return this.call.publishAudioStream(stream);
10083
10107
  }
10084
- stopPublishStream() {
10085
- return this.call.stopPublish(TrackType.AUDIO);
10108
+ stopPublishStream(stopTracks) {
10109
+ return this.call.stopPublish(TrackType.AUDIO, stopTracks);
10086
10110
  }
10087
- /**
10088
- * Disables the audio tracks of the microphone
10089
- */
10090
- pause() {
10111
+ muteTracks() {
10091
10112
  var _a;
10092
- (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getAudioTracks().forEach((track) => {
10093
- track.enabled = false;
10094
- });
10113
+ (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getAudioTracks().forEach((t) => (t.enabled = false));
10095
10114
  }
10096
- /**
10097
- * (Re)enables the audio tracks of the microphone
10098
- */
10099
- resume() {
10115
+ unmuteTracks() {
10100
10116
  var _a;
10101
- (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getAudioTracks().forEach((track) => {
10102
- track.enabled = true;
10103
- });
10117
+ (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getAudioTracks().forEach((t) => (t.enabled = true));
10104
10118
  }
10105
10119
  }
10106
10120
 
@@ -10664,11 +10678,12 @@ class Call {
10664
10678
  *
10665
10679
  *
10666
10680
  * @param trackType the track type to stop publishing.
10681
+ * @param stopTrack if `true` the track will be stopped, else it will be just disabled
10667
10682
  */
10668
- this.stopPublish = (trackType) => __awaiter(this, void 0, void 0, function* () {
10683
+ this.stopPublish = (trackType, stopTrack = true) => __awaiter(this, void 0, void 0, function* () {
10669
10684
  var _j;
10670
10685
  this.logger('info', `stopPublish ${TrackType[trackType]}`);
10671
- yield ((_j = this.publisher) === null || _j === void 0 ? void 0 : _j.unpublishStream(trackType));
10686
+ yield ((_j = this.publisher) === null || _j === void 0 ? void 0 : _j.unpublishStream(trackType, stopTrack));
10672
10687
  });
10673
10688
  /**
10674
10689
  * Update track subscription configuration for one or more participants.
@@ -12441,7 +12456,7 @@ class WSConnectionFallback {
12441
12456
  }
12442
12457
  }
12443
12458
 
12444
- const version = '0.3.2';
12459
+ const version = '0.3.3';
12445
12460
 
12446
12461
  const logger = getLogger(['location']);
12447
12462
  const HINT_URL = `https://hint.stream-io-video.com/`;