-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
92 lines (82 loc) · 3.06 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
<html>
<head>
<title>A mock library for getUserMedia and other stream device functions - DEMO</title>
<script type="module">
import GetUserMediaMock from './index.js'
window.addEventListener('load', onLoad);
// Globals
window.updateDevices = updateDevices
window.hiddenTests = hiddenTests
function onLoad() {
console.log('onLoad')
setup();
testGetUserMedia();
}
function setup(){
window.getUserMediaMock = new GetUserMediaMock();
getUserMediaMock.mock();
}
function testGetUserMedia(){
// navigator.getUserMedia({video: true}, function(stream){ // NOT USED ANYMORE.
navigator.mediaDevices.getUserMedia({video: true})
.then(function(stream){
const video = document.createElement('video');
video.autoplay = true;
video.srcObject = stream;
document.getElementById('stream-wrapper').appendChild(video);
})
.catch(console.error);
}
function updateDevices(){
navigator.mediaDevices.enumerateDevices()
.then(function(devices){
document.getElementById('devices').textContent = JSON.stringify(devices)
});
}
function hiddenTests(){
const best1 = window.getUserMediaMock.getConstraintBestValue({
video: {
width: {
ideal: 111,
min: 11
}
},
audio: true
}, 'video', 'width')
const best2 = window.getUserMediaMock.getConstraintBestValue({
video: {
width: {
min: 11
}
},
audio: true
}, 'video', 'width')
console.log({
best1,
best2
})
}
</script>
</head>
<body>
<h1>A mock library for getUserMedia and other stream device functions - DEMO</h1>
<div>
Click <a href="./fallback.html">here</a> for fallback(Only use this library if getUserMedia fails.) functionality.<br>
Click <a href="./video.html">here</a> for video demo.
</div>
<div>
This page should automatically mock getUserMedia.<br>
The stream will be placed in the area below.
</div>
<div id="stream-wrapper">
<!-- STREAM ADDDED HERE -->
</div>
<div>
<h2>Devices</h2>
<input type="button" value="Update Devices" onclick="updateDevices()">
<div id="devices">
<!-- DEVICES -->
</div>
</div>
</body>
</html>