New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-webcam

Package Overview
Dependencies
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-webcam - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

.babelrc

340

dist/react-webcam.js

@@ -1,157 +0,241 @@

'use strict';
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("react"));
else if(typeof define === 'function' && define.amd)
define(["react"], factory);
else if(typeof exports === 'object')
exports["Webcam"] = factory(require("react"));
else
root["Webcam"] = factory(root["React"]);
})(this, function(__WEBPACK_EXTERNAL_MODULE_1__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
Object.defineProperty(exports, '__esModule', {
value: true
});
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; desc = parent = getter = undefined; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
/******/ // Flag the module as loaded
/******/ module.loaded = true;
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; }
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
function hasGetUserMedia() {
return !!(navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
}
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
var Webcam = (function (_Component) {
function Webcam() {
_classCallCheck(this, Webcam);
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
_get(Object.getPrototypeOf(Webcam.prototype), 'constructor', this).call(this);
this.state = {
on: false
};
}
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ function(module, exports, __webpack_require__) {
_inherits(Webcam, _Component);
'use strict';
_createClass(Webcam, [{
key: 'componentWillMount',
value: function componentWillMount() {
Webcam.mountedInstances.push(this);
}
}, {
key: 'componentDidMount',
value: function componentDidMount() {
self = this;
exports.__esModule = true;
if (!hasGetUserMedia()) return;
if (Webcam.userMediaRequested) return;
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
if (this.props.audioSource && this.props.videoSource) {
sourceSelected(this.props.audioSource, this.props.videoSource);
} else {
MediaStreamTrack.getSources(function (sourceInfos) {
var audioSource = null;
var videoSource = null;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
sourceInfos.forEach(function (sourceInfo) {
if (sourceInfo.kind === 'audio') {
audioSource = sourceInfo.id;
} else if (sourceInfo.kind === 'video') {
videoSource = sourceInfo.id;
}
});
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
sourceSelected(audioSource, videoSource);
});
}
var _react = __webpack_require__(1);
function sourceSelected(audioSource, videoSource) {
var constraints = {
video: {
optional: [{ sourceId: videoSource }]
}
};
var _react2 = _interopRequireDefault(_react);
if (self.props.audio) constraints.audio = {
optional: [{ sourceId: audioSource }]
};
function hasGetUserMedia() {
return !!(navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
}
navigator.getUserMedia(constraints, function (stream) {
Webcam.mountedInstances.forEach(function (instance) {
instance._successCallback(stream);
});
}, function (e) {
Webcam.mountedInstances.forEach(function (instance) {
instance._errorCallback(e);
});
});
}
var Webcam = (function (_Component) {
_inherits(Webcam, _Component);
Webcam.userMediaRequested = true;
}
}, {
key: '_successCallback',
value: function _successCallback(stream) {
var src = window.URL.createObjectURL(stream);
_createClass(Webcam, null, [{
key: 'defaultProps',
value: {
audio: true,
height: 480,
width: 640
},
enumerable: true
}, {
key: 'propTypes',
value: {
audio: _react.PropTypes.bool,
height: _react.PropTypes.oneOfType([_react.PropTypes.number, _react.PropTypes.string]),
width: _react.PropTypes.oneOfType([_react.PropTypes.number, _react.PropTypes.string])
},
enumerable: true
}, {
key: 'mountedInstances',
value: [],
enumerable: true
}, {
key: 'userMediaRequested',
value: false,
enumerable: true
}]);
this.setState({
hasUserMedia: true,
src: src
});
}
}, {
key: '_errorCallback',
value: function _errorCallback(e) {
this.setState({
src: this.state.src
});
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
if (this.state.hasUserMedia) {
window.URL.revokeObjectURL(this.state.src);
}
}
}, {
key: 'getScreenshot',
value: function getScreenshot() {
if (!this.state.hasUserMedia) return;
function Webcam() {
_classCallCheck(this, Webcam);
var canvas = document.createElement('canvas');
canvas.height = video.clientHeight;
canvas.width = video.clientWidth;
_Component.call(this);
this.state = {
hasUserMedia: false
};
}
var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
Webcam.prototype.componentDidMount = function componentDidMount() {
if (!hasGetUserMedia()) return;
return canvas.toDataURL('image/webp');
}
}, {
key: 'render',
value: function render() {
return _react2['default'].createElement('video', {
autoPlay: true,
width: this.props.width,
height: this.props.height,
src: this.state.src
});
}
}]);
Webcam.mountedInstances.push(this);
return Webcam;
})(_react.Component);
if (!this.state.hasUserMedia && !Webcam.userMediaRequested) {
this.requestUserMedia();
}
};
Webcam.defaultProps = {
audio: true,
height: 480,
width: 640
};
Webcam.mountedInstances = [];
Webcam.userMediaRequested = false;
Webcam.prototype.requestUserMedia = function requestUserMedia() {
var _this = this;
exports['default'] = Webcam;
module.exports = exports['default'];
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
var sourceSelected = function sourceSelected(audioSource, videoSource) {
var constraints = {
video: {
optional: [{ sourceId: videoSource }]
}
};
if (_this.props.audio) {
constraints.audio = {
optional: [{ sourceId: audioSource }]
};
}
navigator.getUserMedia(constraints, function (stream) {
Webcam.mountedInstances.forEach(function (instance) {
return instance.handleUserMedia(null, stream);
});
}, function (e) {
Webcam.mountedInstances.forEach(function (instance) {
return instance.handleUserMedia(error);
});
});
};
if (this.props.audioSource && this.props.videoSource) {
sourceSelected(this.props.audioSource, this.props.videoSource);
} else {
MediaStreamTrack.getSources(function (sourceInfos) {
var audioSource = null;
var videoSource = null;
sourceInfos.forEach(function (sourceInfo) {
if (sourceInfo.kind === 'audio') {
audioSource = sourceInfo.id;
} else if (sourceInfo.kind === 'video') {
videoSource = sourceInfo.id;
}
});
sourceSelected(audioSource, videoSource);
});
}
Webcam.userMediaRequested = true;
};
Webcam.prototype.handleUserMedia = function handleUserMedia(error, stream) {
if (error) {
this.setState({
hasUserMedia: false
});
return;
}
var src = window.URL.createObjectURL(stream);
this.setState({
hasUserMedia: true,
src: src
});
};
Webcam.prototype.componentWillUnmount = function componentWillUnmount() {
var index = Webcam.mountedInstances.indexOf(this);
Webcam.mountedInstances.splice(index, 1);
if (Webcam.mountedInstances.length === 0 && this.state.hasUserMedia) {
window.URL.revokeObjectURL(this.state.src);
}
};
Webcam.prototype.getScreenshot = function getScreenshot() {
if (!this.state.hasUserMedia) return;
var canvas = document.createElement('canvas');
var video = _react2['default'].findDOMNode(this);
console.log(video);
canvas.height = video.clientHeight;
canvas.width = video.clientWidth;
var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
return canvas.toDataURL('image/webp');
};
Webcam.prototype.render = function render() {
return _react2['default'].createElement('video', {
autoPlay: true,
width: this.props.width,
height: this.props.height,
src: this.state.src
});
};
return Webcam;
})(_react.Component);
exports['default'] = Webcam;
module.exports = exports['default'];
/***/ },
/* 1 */
/***/ function(module, exports) {
module.exports = __WEBPACK_EXTERNAL_MODULE_1__;
/***/ }
/******/ ])
});
;
{
"name": "react-webcam",
"version": "0.0.3",
"version": "0.0.4",
"description": "React webcam component",
"main": "dist/react-webcam.js",
"scripts": {
"build": "./node_modules/.bin/babel lib --out-dir dist"
"prepublish": "npm run build:umd",
"build": "babel src --out-dir lib",
"build:umd": "webpack src/react-webcam.js dist/react-webcam.js && NODE_ENV=production webpack src/react-webcam.js dist/react-webcam.min.js",
"lint": "eslint src"
},
"browserify": {
"transform": [
"reactify"
]
},
"repository": {

@@ -33,4 +31,12 @@ "type": "git",

"devDependencies": {
"babel": "^5.6.7"
"babel": "^5.6.7",
"babel-core": "^5.6.18",
"babel-eslint": "^3.1.15",
"babel-loader": "^5.1.4",
"eslint": "^0.23",
"eslint-config-airbnb": "0.0.6",
"eslint-plugin-react": "^2.3.0",
"webpack": "^1.9.6",
"webpack-dev-server": "^1.8.2"
}
}
# react-webcam
Webcam component for React
Webcam component for React. See [this](http://caniuse.com/#feat=stream)
for browser compatibility.

@@ -13,3 +14,3 @@ ## Installation

http://cezary.github.io/react-webcam/
http://cezary.github.io/react-webcam/examples

@@ -19,6 +20,6 @@ ## Example

```javascript
var React = require('react');
var Webcam = require('react-webcam');
import React from 'react';
import Webcam from 'react-webcam';
var Component = React.createClass({
class Component extends React.Component {
render: function() {

@@ -29,3 +30,3 @@ return (

}
});
}
```

@@ -32,0 +33,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc