capture.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. *
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. *
  20. */
  21. var exec = require('cordova/exec'),
  22. helpers = require('./helpers');
  23. /**
  24. * Launches a capture of different types.
  25. *
  26. * @param (DOMString} type
  27. * @param {Function} successCB
  28. * @param {Function} errorCB
  29. * @param {CaptureVideoOptions} options
  30. */
  31. function _capture(type, successCallback, errorCallback, options) {
  32. var win = function(pluginResult) {
  33. successCallback(helpers.wrapMediaFiles(pluginResult));
  34. };
  35. exec(win, errorCallback, "Capture", type, [options]);
  36. }
  37. /**
  38. * The Capture interface exposes an interface to the camera and microphone of the hosting device.
  39. */
  40. function Capture() {
  41. this.supportedAudioModes = [];
  42. this.supportedImageModes = [];
  43. this.supportedVideoModes = [];
  44. }
  45. /**
  46. * Launch audio recorder application for recording audio clip(s).
  47. *
  48. * @param {Function} successCB
  49. * @param {Function} errorCB
  50. * @param {CaptureAudioOptions} options
  51. */
  52. Capture.prototype.captureAudio = function(successCallback, errorCallback, options){
  53. _capture("captureAudio", successCallback, errorCallback, options);
  54. };
  55. /**
  56. * Launch camera application for taking image(s).
  57. *
  58. * @param {Function} successCB
  59. * @param {Function} errorCB
  60. * @param {CaptureImageOptions} options
  61. */
  62. Capture.prototype.captureImage = function(successCallback, errorCallback, options){
  63. _capture("captureImage", successCallback, errorCallback, options);
  64. };
  65. /**
  66. * Launch device camera application for recording video(s).
  67. *
  68. * @param {Function} successCB
  69. * @param {Function} errorCB
  70. * @param {CaptureVideoOptions} options
  71. */
  72. Capture.prototype.captureVideo = function(successCallback, errorCallback, options){
  73. _capture("captureVideo", successCallback, errorCallback, options);
  74. };
  75. module.exports = new Capture();