-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfallback.html
127 lines (106 loc) · 3.63 KB
/
fallback.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
<html>
<head>
<title>Fallback mock setup for getUserMedia - DEMO</title>
<script type="module">
import GetUserMediaMock from './index.js'
// Globals
window.video = video
window.audio = audio
window.videoAndAudio = videoAndAudio
window.invalid = invalid
window.addEventListener('load', onLoad);
function onLoad() {
setup();
}
function setup() {
window.getUserMediaMock = new GetUserMediaMock();
window.getUserMediaMock.fallbackMock();
}
function video() {
return _fallback({ video: true });
}
function audio() {
return _fallback({ audio: true });
}
function videoAndAudio() {
return _fallback({ video: true, audio: true });
}
function invalid() {
return _fallback('invalid');
}
/**
* @param {MediaStreamConstraints} constraints
**/
function _fallback(constraints) {
const methods = {
navigator: document.getElementById('method-navigator-getUserMedia').checked,
mediaDevices: document.getElementById('method-navigator-mediaDevices-getUserMedia').checked
};
if (methods.navigator) {
navigatorGetUserMedia(constraints);
} else {
mediaDevicesGetUserMedia(constraints);
}
}
/**
* @param {MediaStreamConstraints} constraints
**/
function navigatorGetUserMedia(constraints) {
navigator.getUserMedia(constraints, _onStream, console.error);
}
/**
* @param {MediaStreamConstraints} constraints
**/
function mediaDevicesGetUserMedia(constraints) {
navigator.mediaDevices.getUserMedia(constraints)
.then(_onStream)
.catch(console.error);
}
/**
* @param {MediaStream} constraints
**/
function _onStream(stream) {
const video = document.createElement('video');
video.autoplay = true;
video.srcObject = stream;
document.getElementById('stream-wrapper').innerHTML = '';
document.getElementById('stream-wrapper').appendChild(video);
}
</script>
<style>
#controls {
margin: 10px;
}
#method {
margin: 5px;
}
input[type=button] {
margin: 5px;
}
</style>
</head>
<body>
<h1>Fallback mock setup for getUserMedia - DEMO</title>
</h1>
<div>
Click the buttons below to test using different constraints.<br>
If the constraints pass, a stream using your device will be displayed.<br>
If the constraints fail, a mock stream will be displayed.
</div>
<div id="controls">
<div id="method">
Method:
<input type="radio" name="method" id="method-navigator-getUserMedia" checked> navigator.getUserMedia
<input type="radio" name="method" id="method-navigator-mediaDevices-getUserMedia">
navigator.mediaDevices.getUserMedia
</div>
<input type="button" value="Test for video" onclick="video()"><br>
<input type="button" value="Test for audio" onclick="audio()"><br>
<input type="button" value="Test for both video and audio" onclick="videoAndAudio()"><br>
<input type="button" value="Test for invalid constraints" onclick="invalid()"><br>
</div>
<div id="stream-wrapper">
<!-- STREAM ADDDED HERE -->
</div>
</body>
</html>