-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebcam.js
46 lines (39 loc) · 1.35 KB
/
webcam.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Class baised component
import React, { Component } from 'react';
class Webcam extends Component {
render() {
if (navigator.getUserMedia) {
navigator.getUserMedia({video: true},
stream => {
let camera = document.getElementById('camera');
camera.srcObject = stream;
camera.onloadedmetadata = () => {
camera.play();
}
}, err => {
console.log(err)
}
);
}
return (
<div>
<video id="camera" width="640" height="480" autoPlay/>
</div>
);
}
}
export default Webcam;
// stream snippet
// if (navigator.getUserMedia) { // navigator.getUserMedia pass three arguments
// navigator.getUserMedia({video: true}, //if want audio can be true
// stream => {
// let camera = document.getElementById('camera'); //class or id for load stream on html
// camera.srcObject = stream; //src of stream
// camera.onloadedmetadata = () => {
// camera.play();
// }
// }, err => {
// console.log(err)
// }
// );
// }