@flashphoner/websdk 2.0.247 → 2.0.249

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.
@@ -48,7 +48,7 @@ var createConnection = function (options) {
48
48
  var localVideo;
49
49
  //tweak for custom video players #WCS-1511
50
50
  var remoteVideo = options.remoteVideo;
51
- var switchCamCount = 0;
51
+ var switchCamIndex = 0;
52
52
  var switchMicCount = 0;
53
53
  var customStream = options.customStream;
54
54
  var currentAudioTrack;
@@ -136,7 +136,7 @@ var createConnection = function (options) {
136
136
  if (videoTrack) {
137
137
  videoCams.forEach((cam, index) => {
138
138
  if (videoTrack.label === cam.label) {
139
- switchCamCount = index;
139
+ switchCamIndex = index;
140
140
  }
141
141
  });
142
142
  }
@@ -615,12 +615,26 @@ var createConnection = function (options) {
615
615
  if (localVideo && localVideo.srcObject && videoCams.length > 1 && !customStream && !screenShare) {
616
616
  connection.getSenders().forEach(function (sender) {
617
617
  if (sender.track.kind === 'audio') return;
618
- switchCamCount = (switchCamCount + 1) % videoCams.length;
619
618
  sender.track.stop();
620
- var cam = (typeof deviceId !== "undefined") ? deviceId : videoCams[switchCamCount].id;
619
+ var cameraId;
620
+ if (typeof deviceId !== "undefined") {
621
+ videoCams.forEach((cam, index) => {
622
+ if (deviceId === cam.id) {
623
+ switchCamIndex = index;
624
+ }
625
+ });
626
+ cameraId = deviceId;
627
+ } else {
628
+ switchCamIndex = (switchCamIndex + 1) % videoCams.length;
629
+ cameraId = videoCams[switchCamIndex].id;
630
+ }
631
+ if (!cameraId) {
632
+ logger.error(LOG_PREFIX, "Can't detect camera to switch to");
633
+ reject(constants.ERROR_INFO.CAN_NOT_SWITCH_CAM);
634
+ }
621
635
  //use the settings that were set during connection initiation
622
636
  var clonedConstraints = Object.assign({}, constraints);
623
- clonedConstraints.video.deviceId = {exact: cam};
637
+ clonedConstraints.video.deviceId = {exact: cameraId};
624
638
  clonedConstraints.audio = false;
625
639
  navigator.mediaDevices.getUserMedia(clonedConstraints).then(function (newStream) {
626
640
  var newVideoTrack = newStream.getVideoTracks()[0];
@@ -632,8 +646,8 @@ var createConnection = function (options) {
632
646
  if (localVideo.srcObject.getAudioTracks().length == 0 && audioTrack) {
633
647
  localVideo.srcObject.addTrack(audioTrack);
634
648
  }
635
- logger.info(LOG_PREFIX, "Switch camera to " + cam);
636
- resolve(cam);
649
+ logger.info(LOG_PREFIX, "Switch camera to " + cameraId);
650
+ resolve(cameraId);
637
651
  }).catch(function (reason) {
638
652
  logger.error(LOG_PREFIX, reason);
639
653
  reject(reason);