forked from JohnAllsopp/webRTC-Security-Camera
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecuritycamera.html
59 lines (41 loc) · 1.14 KB
/
securitycamera.html
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
<!DOCTYPE html>
<html>
<title>webRTC</title>
<head>
<script>
var localMediaStream = null;
function init() {
video = document.querySelector('video');
canvas = document.querySelector('canvas');
ctx = canvas.getContext('2d');
navigator.getMedia = ( navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia);
//localMediaStream = null;
video.addEventListener('click', snapshot, false);
// Not showing vendor prefixes or code that works cross-browser.
navigator.getMedia({video: true}, function(stream) {
video.src = window.URL.createObjectURL(stream);
localMediaStream = stream;
}, onFailSoHard);
}
function onFailSoHard() {
alert("ouch")
}
function snapshot() {
if (localMediaStream) {
ctx.drawImage(video, 0, 0);
var shot = canvas.toDataURL('image/png');
document.querySelector('img').src = canvas.toDataURL('image/png');
}
}
window.onload = init
</script>
</head>
<body>
<video autoplay></video>
<img src="">
<canvas style="display:block;"></canvas>
</body>
</html>