-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathwebcam.html
84 lines (76 loc) · 2 KB
/
webcam.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<title>Canvas Cast</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name = "viewport" content = "width = device-width, initial-scale = 1.0, maximum-scale = 1.0, user-scalable=0">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
</head>
<body>
<div class="wsBar">
<div class="brightness">
Matrix brightness:
<small>0%</small>
<input id="matrix-brightness" type="range" min="0" max="255" step="1" value="127" >
<small>100%</small>
</div>
<h4><a href="https://github.com/owenmcateer/canvas-cast" target="_blank">Canvas Cast</a></h4>
<div class="status"></div>
<div class="statusTxt"></div>
<div class="statusIP"></div>
</div>
<script src="../src/App.js"></script>
<script>
// Config
const matrix = {
// Matrix IP & port
ip: '192.168.1.94:81',
// Matrix pixel size
width: 15,
height: 15,
// Matrix brightness 0-255
brightness: 127,
// Context type (2d/webgl)
type: '2d',
};
// Start WS Matrix
canvasCast.init(matrix);
// Create Canvas
const canvas = document.createElement('canvas');
canvas.width = matrix.width;
canvas.height = matrix.height;
document.body.appendChild(canvas);
context = canvas.getContext('2d');
/**
* Webcam test
*/
const video = document.createElement('video');
document.body.appendChild(video);
function getVideo() {
navigator.mediaDevices.getUserMedia({ video: true, audio: false })
.then(localMediaStream => {
try {
video.srcObject = localMediaStream;
} catch (error) {
video.src = window.URL.createObjectURL(localMediaStream);
}
video.play();
})
.catch(err => {
console.error(`No access to webcam`, err);
});
}
function paintToCanvas() {
// Add video
context.drawImage(video, 0, 0, matrix.width, matrix.height);
// Cast data
canvasCast.cast(canvas);
}
// Get video
getVideo();
video.addEventListener('canplay', () => {
setInterval(paintToCanvas, 1000 / 30);
});
</script>
</body>
</html>