UNPKG

mighty-webcamjs

Version:

HTML5 Webcam Image Capture Library with Flash Fallback

99 lines (84 loc) 4.18 kB
'use strict'; var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; var _atomJs = require('atom-js'); var _atomJs2 = _interopRequireDefault(_atomJs); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } module.exports = function (Webcam) { var videoParams = { video_recording_time: 10, // seconds // We assume bitrate 2500000 is OK for 640x480. // 640 * 480 * 8.2 ~= 2500000 // 1280 * 720 * 8.2 ~= 7500000 // fps should be also counted, but we don't have control over it. video_bitrate_per_pixel: 7.5, video_length: 2 * 60 * 1000 // 2 minutes to save some bandwith. }; var params = _extends({ capture_mode: Webcam.constants.CAPTURE_MODE_PHOTO, width: 0, height: 0, dest_width: 2560, // size of captured image. dest_height: 2560, // these default to width/height image_format: 'jpeg', // image format (may be jpeg or png) jpeg_quality: 90, // jpeg image quality from 0 (worst) to 100 (best) enable_flash: true, // enable flash fallback, force_flash: false, // force flash mode force_file: false, // force file upload mode flip_horiz: false, // flip image horiz (mirror mode) flip_horiz_back: undefined, // flip image horizontally on both: front and back camera flip_horiz_on_snap: false, // flip image horiz when snaped fps: 30, // camera frames per second (used in Flash) webcam_path: './', // URI to webcam.swf movie (defaults to the js location) flash_not_detected_text: 'ERROR: No Adobe Flash Player detected. Webcam.js relies on Flash for browsers that do not support getUserMedia (like yours).', enable_file_fallback: true, force_fresh_photo: false, // When true, it will disallow to Select Photo from Library on iOS no_interface_found_text: 'No supported webcam interface found.', unfreeze_snap: true, // Whether to unfreeze the camera after snap (defaults to true) camera: Webcam.constants.CAM_BACK, // "front" or "back" cameraDetectionMode: null, // Labels are more reliable than webrtc, but doesn't always work switch_camera_node: 'Switch camera', // Contents of "Switch Camera" button. React Node required maximum_blur_index: 0, // 0 to disable, less is better. Recommended value: 0.8 // read more and experiment: https://github.com/CezaryDanielNowak/inspector-bokeh verbose: true, // Set to false to hide logs. best_resolution_finder: true, // option that seeks higher resolution after detecting // one of preset one use_ImageCapture_API: false, flash_light_node: 'Enable Flash Light', // React Node required cameraId: undefined, // For browsers, that does not support facingMode cameraInfs: [] }, videoParams, { cameraMode: null, userMedia: true // true when getUserMedia is supported natively; }); // state is cleared after reset (rotate, reattach etc) var state = { load: false, // true when webcam movie finishes loading live: false, // true when webcam is initialized and ready to snap videoRecording: false, loadedVideoDimensions: {}, photoCapabilities: {} // https://developer.mozilla.org/en-US/docs/Web/API/PhotoCapabilities }; var defaults = _extends({}, params, state); var initialisation = true; var model = _atomJs2.default.setup({ onChange: function onChange(field, value) { !initialisation && Webcam.dispatch(field, value); } })(defaults); initialisation = false; model.resetState = function () { // clear data marked as state, keep params. Object.keys(model.get()).forEach(function (key) { var isParam = key in params; var isDefaultState = key in state; isParam || model.set(key, isDefaultState ? state[key] : undefined); }); }; model.on('use_ImageCapture_API', function (value) { if (value && typeof ImageCapture === 'undefined') { // eslint-disable-next-line no-console console.warn('ImageCapture is not available. `use_ImageCapture_API` passed to webcamjs reset to `false`.'); model.set('use_ImageCapture_API', false); } }); return model; };