-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
55 lines (51 loc) · 1.91 KB
/
index.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
<!doctype html>
<html>
<head>
<title>Socket.IO chat</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font: 13px Helvetica, Arial; }
form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
#messages { list-style-type: none; margin: 0; padding: 0; }
#messages li { padding: 5px 10px; }
#messages li:nth-child(odd) { background: #eee; }
</style>
</head>
<body>
<video id="live" width="320" height="240" autoplay></video>
<canvas width="320" id="canvas" height="240" style="display:none;"></canvas>
<canvas width="320" id="canvas2" height="240"></canvas>
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
var socket = io();
var video = $("#live").get()[0];
var canvas = $("#canvas");
var canvas2 = $("#canvas2");
var ctx = canvas.get()[0].getContext('2d');
var ctx2 = canvas2.get()[0].getContext('2d');
var image = new Image();
image.onload = function() {
ctx2.drawImage(image, 0, 0);
};
navigator.getUserMedia = navigator.webkitGetUserMedia || navigator.getUserMedia;
var success = function(stream){
console.log (stream);
video.src = webkitURL.createObjectURL(stream);
}
var error = function(err){
console.log(err)
}
navigator.getUserMedia({video:true}, success, error);
setInterval(function(){
ctx.drawImage(video, 0, 0, 320,240);
var data = canvas[0].toDataURL("image/jpeg");
socket.emit('video', data);
// console.log(data);
// image.src = data;
},10);
</script>
</body>
</html>