Source: cordova-plugin-bbd-media-capture/www/capture.js

/*
 *
 * Copyright (c) 2021 BlackBerry Limited. All Rights Reserved.
 * Some modifications to the original Cordova File plugin
 * from https://github.com/apache/cordova-plugin-media-capture
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
*/

var exec = require('cordova/exec');
var helpers = require('./helpers');

/**
 * Launches a capture of different types.
 *
 * @param (DOMString} type
 * @param {Function} successCB
 * @param {Function} errorCB
 * @param {CaptureVideoOptions} options
 */
function _capture (type, successCallback, errorCallback, options) {
    var win = function (pluginResult) {
        successCallback(helpers.wrapMediaFiles(pluginResult));
    };
    exec(win, errorCallback, 'BBDCapture', type, [options]);
}

/**
 * The Capture interface exposes an interface to the camera and microphone of the hosting device.
 */
function Capture () {
    this.supportedAudioModes = [];
    this.supportedImageModes = [];
    this.supportedVideoModes = [];
}

/**
 * Launch audio recorder application for recording audio clip(s).
 *
 * @param {Function} successCB
 * @param {Function} errorCB
 * @param {CaptureAudioOptions} options
 */
Capture.prototype.captureAudio = function (successCallback, errorCallback, options) {
    _capture('captureAudio', successCallback, errorCallback, options);
};

/**
 * Launch camera application for taking image(s).
 *
 * @param {Function} successCB
 * @param {Function} errorCB
 * @param {CaptureImageOptions} options
 */
Capture.prototype.captureImage = function (successCallback, errorCallback, options) {
    _capture('captureImage', successCallback, errorCallback, options);
};

/**
 * Launch device camera application for recording video(s).
 *
 * @param {Function} successCB
 * @param {Function} errorCB
 * @param {CaptureVideoOptions} options
 */
Capture.prototype.captureVideo = function (successCallback, errorCallback, options) {
    _capture('captureVideo', successCallback, errorCallback, options);
};

/**
 * @constant Capture#storageLocation
 * @type {string}
 * @description Use this constant to get platform specific Media storage root location
 *  via resolveLocalFileSystemURL from cordova-plugin-bbd-file.
 *
 * @example
 *  <pre class="prettyprint"><code>
 *      resolveLocalFileSystemURL(navigator.device.capture.storageLocation,
 *          function(directoryEntry) {
 *              var mediaDirectoryReader = directoryEntry.createReader();
 *              mediaDirectoryReader.readEntries(function (entries) {
 *                  console.log("Media storage entries: ", entries);
 *              }, function(error) {
 *                  console.log("Error: ", error);
 *              });
 *          }, function(error) {
 *              console.log("resolveLocalFileSystemURL error: ", error)
 *          }
 *      );
 *  </code></pre>
 */
Capture.prototype.storageLocation = 'cdvfile://localhost/media/';

module.exports = new Capture();