captureImage: function()

in src/windows/CaptureProxy.js [394:477]


    captureImage: function (successCallback, errorCallback, args) {
        const CaptureNS = Windows.Media.Capture;

        function fail (code, data) {
            const err = new CaptureError(code);
            err.message = data;
            errorCallback(err);
        }

        // Check if necessary API available
        if (!CaptureNS.CameraCaptureUI) {
            // We are running on WP8.1 which lacks CameraCaptureUI class
            // so we need to use MediaCapture class instead and implement custom UI for camera

            const proxy = new MediaCaptureProxy();

            proxy.capturePhoto(
                function (photoFile) {
                    photoFile.getBasicPropertiesAsync().done(
                        function (basicProperties) {
                            const result = new MediaFile(
                                photoFile.name,
                                'ms-appdata:///local/' + photoFile.name,
                                photoFile.contentType,
                                basicProperties.dateModified,
                                basicProperties.size
                            );
                            result.fullPath = photoFile.path;
                            successCallback([result]);
                        },
                        function (err) {
                            fail(CaptureError.CAPTURE_INTERNAL_ERR, err);
                        }
                    );
                },
                function (err) {
                    fail(err);
                }
            );
        } else {
            const cameraCaptureUI = new Windows.Media.Capture.CameraCaptureUI();
            cameraCaptureUI.photoSettings.allowCropping = true;
            cameraCaptureUI.photoSettings.maxResolution = Windows.Media.Capture.CameraCaptureUIMaxPhotoResolution.highestAvailable;
            cameraCaptureUI.photoSettings.format = Windows.Media.Capture.CameraCaptureUIPhotoFormat.jpeg;
            cameraCaptureUI.captureFileAsync(Windows.Media.Capture.CameraCaptureUIMode.photo).done(
                function (file) {
                    if (file) {
                        file.moveAsync(
                            Windows.Storage.ApplicationData.current.localFolder,
                            'cameraCaptureImage.jpg',
                            Windows.Storage.NameCollisionOption.generateUniqueName
                        ).then(
                            function () {
                                file.getBasicPropertiesAsync().then(
                                    function (basicProperties) {
                                        const result = new MediaFile(
                                            file.name,
                                            'ms-appdata:///local/' + file.name,
                                            file.contentType,
                                            basicProperties.dateModified,
                                            basicProperties.size
                                        );
                                        result.fullPath = file.path;
                                        successCallback([result]);
                                    },
                                    function () {
                                        errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
                                    }
                                );
                            },
                            function () {
                                errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
                            }
                        );
                    } else {
                        errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
                    }
                },
                function () {
                    errorCallback(new CaptureError(CaptureError.CAPTURE_NO_MEDIA_FILES));
                }
            );
        }
    },