Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Merge pull request #253 from daserge/win10-CameraStreamState
Browse files Browse the repository at this point in the history
[Windows10] Fix The request is invalid in the current state
  • Loading branch information
Vladimir Kotikov committed Jun 8, 2016
2 parents a3d4dfa + 2a3e4fd commit 5161af4
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/windows/BarcodeScannerProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

var urlutil = require('cordova/urlutil');

var CAMERA_STREAM_STATE_CHECK_RETRY_TIMEOUT = 200; // milliseconds

/**
* List of supported barcode formats from ZXing library. Used to return format
* name instead of number code as per plugin spec.
Expand Down Expand Up @@ -411,6 +413,30 @@ module.exports = {
Windows.Graphics.Display.DisplayInformation.getForCurrentView().addEventListener("orientationchanged", updatePreviewForRotation, false);
return updatePreviewForRotation();
})
.then(function () {

if (!Windows.Media.Devices.CameraStreamState) {
// CameraStreamState is available starting with Windows 10 so skip this check for 8.1
// https://msdn.microsoft.com/en-us/library/windows/apps/windows.media.devices.camerastreamstate
return WinJS.Promise.as();
}

function checkCameraStreamState() {
if (capture.cameraStreamState !== Windows.Media.Devices.CameraStreamState.streaming) {

// Using loop as MediaCapture.CameraStreamStateChanged does not fire with CameraStreamState.streaming state.
return WinJS.Promise.timeout(CAMERA_STREAM_STATE_CHECK_RETRY_TIMEOUT)
.then(function () {
return checkCameraStreamState();
});
}

return WinJS.Promise.as();
}

// Ensure CameraStreamState is Streaming
return checkCameraStreamState();
})
.then(function () {
return captureSettings;
});
Expand Down

0 comments on commit 5161af4

Please sign in to comment.