-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathenumdemo2.html
66 lines (57 loc) · 1.5 KB
/
enumdemo2.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
<!DOCTYPE html>
<html>
<head>
<title>enumeration demo</title>
</head>
<body>
Devices:
<ul id="devicelist"></ul>
<button id="refresh" onclick="refreshDeviceList(false);">Refresh device list</button><br>
<script>
var device_list = null;
window.onload = onLoad;
function onLoad() {
device_list = document.getElementById("devicelist");
navigator.webkitGetUserMedia(
{audio:true},
function(stream) {
refreshDeviceList(true,device_list);
stream.getAudioTracks()[0].stop();
console.log("stream closed");
},
function(err) {addItem(err + ' ' + err.name + ': ' + err.message);}
);
}
function addItem(strItem) {
var item = document.createElement("li");
item.innerHTML = strItem;
device_list.appendChild(item);
}
function clearItems() {
while (device_list.firstChild ){
device_list.removeChild(device_list.firstChild );
}
}
function refreshDeviceList(selectFirst) {
clearItems()
if (!navigator.mediaDevices) {
addItem('navigator.mediaDevices not supported');
return;
}
if (!navigator.mediaDevices.enumerateDevices) {
addItem('enumerateDevices not supported');
return;
}
navigator.mediaDevices.enumerateDevices().then( function(infos) {
var count = 0;
for (var i = 0; i < infos.length; i++) {
count++;
addItem('' + (count) + ' - ' + infos[i].kind + ' - ' + infos[i].deviceId + ' - ' + infos[i].label);
}
}, function(msg) {
alert('Something wrong: ' + msg);
});
}
</script>
</body>
</html>