-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutoStreaming.html
51 lines (50 loc) · 1.49 KB
/
tutoStreaming.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
<html>
<head>
<title>Video</title>
<style>
video{display: none;}
</style>
</head>
<body>
<video autoplay></video>
<canvas id='miCanvas' width='800' height='600'></canvas>
<script src="http://forasteyros.com:21109/socket.io/socket.io.js"></script>
<script>
var bandera=0;
var websocket = io.connect("http://forasteyros.com:21109");
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
navigator.getUserMedia({audio: true, video:true},function(vid){
bandera = 1;
document.querySelector('video').src = window.URL.createObjectURL(vid);
});
window.requestAnimFrame = (function(callback){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback){
window.setTimeout(callback, 1000 / 100);
};
})();
function dFrame(ctx,video,canvas)
{
ctx.drawImage(video,0,0);
var dataURL = canvas.toDataURL('image/jpeg',0.2);
if(bandera!=0) websocket.emit('newFrame',dataURL);
requestAnimFrame(function(){
setTimeout(function(){dFrame(ctx,video,canvas);},200)
});
}
window.addEventListener('load',init);
function init()
{
var canvas = document.querySelector('#miCanvas');
var video = document.querySelector('video');
var ctx = canvas.getContext('2d');
dFrame(ctx,video,canvas);
}
</script>
</body>
</html>