-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcamera.js
executable file
·59 lines (51 loc) · 1.74 KB
/
camera.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
47
48
49
50
51
52
53
54
55
56
57
58
59
function hasGetUserMedia() {
// Note: Opera is unprefixed.
return !!(navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia);
}
if (hasGetUserMedia()) {
// Good to go!
} else {
alert('getUserMedia() is not supported in your browser');
}
var onFailSoHard = function(e) {
console.log('Reeeejected!', e);
};
var idx = 0;
var app = document.getElementById('app');
var filters = ['grayscale', 'sepia', 'blur', 'brightness', 'contrast', 'hue-rotate', 'hue-rotate2', 'hue-rotate3', 'saturate', 'invert', ''];
function changeFilter(e) {
var el = e.target;
el.className = '';
var effect = filters[idx++ % filters.length];
// loop through filters.
if (effect) {
el.classList.add(effect);
}
}
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
// Not showing vendor prefixes.
navigator.getUserMedia({
video : true,
audio : false,
mandatory: [
{ facingMode: "back" }
]
}, function(localMediaStream) {
var video = document.getElementById('monitor');
video.addEventListener('click', changeFilter, false);
video.src = window.URL.createObjectURL(localMediaStream);
console.log(localMediaStream);
console.log(localMediaStream.getVideoTracks());
// Note: onloadedmetadata doesn't fire in Chrome when using it with getUserMedia.
// See crbug.com/110938.
video.onloadedmetadata = function(e) {
// Ready to go. Do some stuff.
document.getElementById('app').hidden = false;
};
// Since video.onloadedmetadata isn't firing for getUserMedia video, we have
// to fake it.
setTimeout(function() {
document.getElementById('app').hidden = false;
}, 50);
}, onFailSoHard);