@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.cjs.js CHANGED
@@ -6637,6 +6637,9 @@ class Publisher {
6637
6637
  previousTrack.removeEventListener('ended', handleTrackEnded);
6638
6638
  track.addEventListener('ended', handleTrackEnded);
6639
6639
  }
6640
+ if (!track.enabled) {
6641
+ track.enabled = true;
6642
+ }
6640
6643
  yield transceiver.sender.replaceTrack(track);
6641
6644
  }
6642
6645
  yield this.notifyTrackMuteStateChanged(mediaStream, track, trackType, false);
@@ -6645,15 +6648,18 @@ class Publisher {
6645
6648
  * Stops publishing the given track type to the SFU, if it is currently being published.
6646
6649
  * Underlying track will be stopped and removed from the publisher.
6647
6650
  * @param trackType the track type to unpublish.
6651
+ * @param stopTrack specifies whether track should be stopped or just disabled
6648
6652
  */
6649
- this.unpublishStream = (trackType) => __awaiter(this, void 0, void 0, function* () {
6653
+ this.unpublishStream = (trackType, stopTrack) => __awaiter(this, void 0, void 0, function* () {
6650
6654
  const transceiver = this.pc
6651
6655
  .getTransceivers()
6652
6656
  .find((t) => t === this.transceiverRegistry[trackType] && t.sender.track);
6653
6657
  if (transceiver &&
6654
6658
  transceiver.sender.track &&
6655
6659
  transceiver.sender.track.readyState === 'live') {
6656
- transceiver.sender.track.stop();
6660
+ stopTrack
6661
+ ? transceiver.sender.track.stop()
6662
+ : (transceiver.sender.track.enabled = false);
6657
6663
  return this.notifyTrackMuteStateChanged(undefined, transceiver.sender.track, trackType, true);
6658
6664
  }
6659
6665
  });
@@ -9540,7 +9546,8 @@ const CallTypes = new CallTypesRegistry([
9540
9546
  ]);
9541
9547
 
9542
9548
  class InputMediaDeviceManagerState {
9543
- constructor() {
9549
+ constructor(disableMode = 'stop-tracks') {
9550
+ this.disableMode = disableMode;
9544
9551
  this.statusSubject = new rxjs.BehaviorSubject(undefined);
9545
9552
  this.mediaStreamSubject = new rxjs.BehaviorSubject(undefined);
9546
9553
  this.selectedDeviceSubject = new rxjs.BehaviorSubject(undefined);
@@ -9567,7 +9574,9 @@ class InputMediaDeviceManagerState {
9567
9574
  this.selectedDevice$ = this.selectedDeviceSubject
9568
9575
  .asObservable()
9569
9576
  .pipe(rxjs.distinctUntilChanged());
9570
- this.status$ = this.statusSubject.asObservable();
9577
+ this.status$ = this.statusSubject
9578
+ .asObservable()
9579
+ .pipe(rxjs.distinctUntilChanged());
9571
9580
  }
9572
9581
  /**
9573
9582
  * The device status
@@ -9615,7 +9624,7 @@ class InputMediaDeviceManagerState {
9615
9624
 
9616
9625
  class CameraManagerState extends InputMediaDeviceManagerState {
9617
9626
  constructor() {
9618
- super();
9627
+ super('stop-tracks');
9619
9628
  this.directionSubject = new rxjs.BehaviorSubject(undefined);
9620
9629
  this.direction$ = this.directionSubject
9621
9630
  .asObservable()
@@ -9928,12 +9937,13 @@ class InputMediaDeviceManager {
9928
9937
  if (this.state.status === 'enabled') {
9929
9938
  return;
9930
9939
  }
9931
- yield this.startStream();
9940
+ yield this.unmuteStream();
9932
9941
  this.state.setStatus('enabled');
9933
9942
  });
9934
9943
  }
9935
9944
  /**
9936
9945
  * Stops camera/microphone
9946
+ *
9937
9947
  * @returns
9938
9948
  */
9939
9949
  disable() {
@@ -9941,12 +9951,25 @@ class InputMediaDeviceManager {
9941
9951
  if (this.state.status === 'disabled') {
9942
9952
  return;
9943
9953
  }
9944
- yield this.stopStream();
9954
+ this.state.prevStatus = this.state.status;
9955
+ yield this.muteStream(this.state.disableMode === 'stop-tracks');
9945
9956
  this.state.setStatus('disabled');
9946
9957
  });
9947
9958
  }
9959
+ /**
9960
+ * If status was previously enabled, it will reenable the device.
9961
+ */
9962
+ resume() {
9963
+ return __awaiter(this, void 0, void 0, function* () {
9964
+ if (this.state.prevStatus === 'enabled' &&
9965
+ this.state.status === 'disabled') {
9966
+ this.enable();
9967
+ }
9968
+ });
9969
+ }
9948
9970
  /**
9949
9971
  * If current device statis is disabled, it will enable the device, else it will disable it.
9972
+ *
9950
9973
  * @returns
9951
9974
  */
9952
9975
  toggle() {
@@ -9981,32 +10004,40 @@ class InputMediaDeviceManager {
9981
10004
  applySettingsToStream() {
9982
10005
  return __awaiter(this, void 0, void 0, function* () {
9983
10006
  if (this.state.status === 'enabled') {
9984
- yield this.stopStream();
9985
- yield this.startStream();
10007
+ yield this.muteStream();
10008
+ yield this.unmuteStream();
9986
10009
  }
9987
10010
  });
9988
10011
  }
9989
- stopStream() {
10012
+ muteStream(stopTracks = true) {
9990
10013
  return __awaiter(this, void 0, void 0, function* () {
9991
10014
  if (!this.state.mediaStream) {
9992
10015
  return;
9993
10016
  }
9994
10017
  if (this.call.state.callingState === exports.CallingState.JOINED) {
9995
- yield this.stopPublishStream();
10018
+ yield this.stopPublishStream(stopTracks);
9996
10019
  }
9997
10020
  else if (this.state.mediaStream) {
9998
- disposeOfMediaStream(this.state.mediaStream);
10021
+ stopTracks
10022
+ ? disposeOfMediaStream(this.state.mediaStream)
10023
+ : this.muteTracks();
10024
+ }
10025
+ if (stopTracks) {
10026
+ this.state.setMediaStream(undefined);
9999
10027
  }
10000
- this.state.setMediaStream(undefined);
10001
10028
  });
10002
10029
  }
10003
- startStream() {
10030
+ unmuteStream() {
10004
10031
  return __awaiter(this, void 0, void 0, function* () {
10032
+ let stream;
10005
10033
  if (this.state.mediaStream) {
10006
- return;
10034
+ stream = this.state.mediaStream;
10035
+ this.unmuteTracks();
10036
+ }
10037
+ else {
10038
+ const constraints = { deviceId: this.state.selectedDevice };
10039
+ stream = yield this.getStream(constraints);
10007
10040
  }
10008
- const constraints = { deviceId: this.state.selectedDevice };
10009
- const stream = yield this.getStream(constraints);
10010
10041
  if (this.call.state.callingState === exports.CallingState.JOINED) {
10011
10042
  yield this.publishStream(stream);
10012
10043
  }
@@ -10058,30 +10089,23 @@ class CameraManager extends InputMediaDeviceManager {
10058
10089
  publishStream(stream) {
10059
10090
  return this.call.publishVideoStream(stream);
10060
10091
  }
10061
- stopPublishStream() {
10062
- return this.call.stopPublish(TrackType.VIDEO);
10092
+ stopPublishStream(stopTracks) {
10093
+ return this.call.stopPublish(TrackType.VIDEO, stopTracks);
10063
10094
  }
10064
- /**
10065
- * Disables the video tracks of the camera
10066
- */
10067
- pause() {
10095
+ muteTracks() {
10068
10096
  var _a;
10069
- (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks().forEach((track) => {
10070
- track.enabled = false;
10071
- });
10097
+ (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks().forEach((t) => (t.enabled = false));
10072
10098
  }
10073
- /**
10074
- * (Re)enables the video tracks of the camera
10075
- */
10076
- resume() {
10099
+ unmuteTracks() {
10077
10100
  var _a;
10078
- (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks().forEach((track) => {
10079
- track.enabled = true;
10080
- });
10101
+ (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getVideoTracks().forEach((t) => (t.enabled = true));
10081
10102
  }
10082
10103
  }
10083
10104
 
10084
10105
  class MicrophoneManagerState extends InputMediaDeviceManagerState {
10106
+ constructor() {
10107
+ super('disable-tracks');
10108
+ }
10085
10109
  getDeviceIdFromStream(stream) {
10086
10110
  var _a;
10087
10111
  return (_a = stream.getAudioTracks()[0]) === null || _a === void 0 ? void 0 : _a.getSettings().deviceId;
@@ -10101,26 +10125,16 @@ class MicrophoneManager extends InputMediaDeviceManager {
10101
10125
  publishStream(stream) {
10102
10126
  return this.call.publishAudioStream(stream);
10103
10127
  }
10104
- stopPublishStream() {
10105
- return this.call.stopPublish(TrackType.AUDIO);
10128
+ stopPublishStream(stopTracks) {
10129
+ return this.call.stopPublish(TrackType.AUDIO, stopTracks);
10106
10130
  }
10107
- /**
10108
- * Disables the audio tracks of the microphone
10109
- */
10110
- pause() {
10131
+ muteTracks() {
10111
10132
  var _a;
10112
- (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getAudioTracks().forEach((track) => {
10113
- track.enabled = false;
10114
- });
10133
+ (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getAudioTracks().forEach((t) => (t.enabled = false));
10115
10134
  }
10116
- /**
10117
- * (Re)enables the audio tracks of the microphone
10118
- */
10119
- resume() {
10135
+ unmuteTracks() {
10120
10136
  var _a;
10121
- (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getAudioTracks().forEach((track) => {
10122
- track.enabled = true;
10123
- });
10137
+ (_a = this.state.mediaStream) === null || _a === void 0 ? void 0 : _a.getAudioTracks().forEach((t) => (t.enabled = true));
10124
10138
  }
10125
10139
  }
10126
10140
 
@@ -10684,11 +10698,12 @@ class Call {
10684
10698
  *
10685
10699
  *
10686
10700
  * @param trackType the track type to stop publishing.
10701
+ * @param stopTrack if `true` the track will be stopped, else it will be just disabled
10687
10702
  */
10688
- this.stopPublish = (trackType) => __awaiter(this, void 0, void 0, function* () {
10703
+ this.stopPublish = (trackType, stopTrack = true) => __awaiter(this, void 0, void 0, function* () {
10689
10704
  var _j;
10690
10705
  this.logger('info', `stopPublish ${TrackType[trackType]}`);
10691
- yield ((_j = this.publisher) === null || _j === void 0 ? void 0 : _j.unpublishStream(trackType));
10706
+ yield ((_j = this.publisher) === null || _j === void 0 ? void 0 : _j.unpublishStream(trackType, stopTrack));
10692
10707
  });
10693
10708
  /**
10694
10709
  * Update track subscription configuration for one or more participants.
@@ -12461,7 +12476,7 @@ class WSConnectionFallback {
12461
12476
  }
12462
12477
  }
12463
12478
 
12464
- const version = '0.3.2';
12479
+ const version = '0.3.3';
12465
12480
 
12466
12481
  const logger = getLogger(['location']);
12467
12482
  const HINT_URL = `https://hint.stream-io-video.com/`;