-
Notifications
You must be signed in to change notification settings - Fork 1
/
camera.js
68 lines (37 loc) · 1.38 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
60
61
62
63
64
65
66
67
68
var webcam = (function(){
var video = document.createElement('video');
function play() {
if (navigator.getUserMedia) {
navigator.getUserMedia({video: true, audio: true, toString : function() {return "video,audio";} }, onSuccess, onError);
} else {
changeStatus('getUserMedia is not supported in this browser.', true);
}
}
function onSuccess(stream) {
var source;
if (window.webkitURL) {
source = window.webkitURL.createObjectURL(stream);
} else {
source = stream; // Opera and Firefox
}
video.autoplay = true;
video.src = source;
changeStatus('Connected.', false);
}
function onError() {
changeStatus('Please accept the getUserMedia permissions! Refresh to try again.', true);
}
function changeStatus(msg, error) {
var status = document.getElementById('status');
status.innerHTML = msg;
status.style.color = (error) ? 'red' : 'green';
}
return {
init: function() {
changeStatus('Please accept the permissions dialog.', true);
document.body.appendChild(video);
navigator.getUserMedia || (navigator.getUserMedia = navigator.mozGetUserMedia || navigator.webkitGetUserMedia || navigator.msGetUserMedia);
play();
}()
}
})();