-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
141 lines (126 loc) · 4.98 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<link rel="shortcut icon" type="image/x-icon" href="https://production-assets.codepen.io/assets/favicon/favicon-8ea04875e70c4b0bb41da869e81236e54394d63638a1ef12fa558a4a835f1164.ico" />
<link rel="mask-icon" type="" href="https://production-assets.codepen.io/assets/favicon/logo-pin-f2d2b6d2c61838f7e76325261b7195c27224080bc099486ddd6dccb469b8e8e6.svg" color="#111" />
<meta name="robots" content="noindex">
<title>CodePen - Hello, WebRTC on Safari 11</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css">
<script src="https://webrtc.github.io/adapter/adapter-latest.js"></script>
<script src="diff-cam-engine.js"></script>
<style>
html,
body {
height: 100%;
overflow: hidden;
width: 100%;
display: flex;
justify-content: center;
align-items: center;
}
#cam-stream__video {
width: 50%;
}
figure {
display: inline-block;
margin: 10px;
vertical-align: top;
}
figcaption {
text-align: left;
font-weight: bold;
}
cam-stream__video,
cam-stream__motion {
width: 480px;
height: 360px;
background-color: #999;
}
#cam-stream__motion {
image-rendering: pixelated;
}
</style>
</head>
<body>
<figure id="live">
<figcaption>Live Video</figcaption>
</figure>
<figure>
<canvas id="cam-stream__motion"></canvas>
<figcaption>
Motion Heatmap
<br> Score: <span id="score">?</span>
<p id="erro"></p>
</figcaption>
</figure>
<script>
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
var video = document.createElement('video');
video.style.width = document.width + 'px';
video.style.height = document.height + 'px';
video.setAttribute('autoplay', '');
video.setAttribute('muted', '');
video.setAttribute('playsinline', '');
video.setAttribute('id', 'cam-stream__video')
var facingMode = "user";
var errorElement = document.getElementById("erro");
var errorElement = document.getElementById("erro");
var constraints = {
audio: false,
video: true
}
function success(stream) {
var videoTracks = stream.getVideoTracks();
console.log('Got stream with constraints:', constraints);
console.log('Using video device: ' + videoTracks[0].label);
stream.oninactive = function() {
console.log('Stream inactive');
};
window.stream = stream; // make variable available to browser console
video.srcObject = stream;
}
function errorMsg(msg, error) {
errorElement.innerHTML += '<p>' + msg + '</p>';
if (typeof error !== 'undefined') {
console.error(error);
}
}
function initError(error) {
if (error.name === 'ConstraintNotSatisfiedError') {
errorMsg('The resolution ' + constraints.video.width.exact + 'x' +
constraints.video.width.exact + ' px is not supported by your device.');
} else if (error.name === 'PermissionDeniedError') {
errorMsg('Permissions have not been granted to use your camera and ' +
'microphone, you need to allow the page access to your devices in ' +
'order for the demo to work.');
}
errorMsg('getUserMedia error: ' + error.name, error);
}
navigator.mediaDevices.getUserMedia(constraints)
.then(success)
.catch(initError);
document.getElementById("live").appendChild(video);
var myStream = document.getElementById("cam-stream__video");
var myMotion = document.getElementById("cam-stream__motion");
var score = document.getElementById('score');
function initSuccess() {
DiffCamEngine.start();
}
function initError() {
alert('Something went wrong.');
}
function capture(payload) {
console.log(score.textContent = payload.score);
}
DiffCamEngine.init({
video: myStream,
motionCanvas: myMotion,
initSuccessCallback: initSuccess,
initErrorCallback: initError,
captureCallback: capture
});
</script>
</body>
</html>