-
Notifications
You must be signed in to change notification settings - Fork 1
/
sourcesdemo.html
103 lines (90 loc) · 2.71 KB
/
sourcesdemo.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
<!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, video:true},
function(stream) {
stream.getAudioTracks()[0].stop();
console.log("stream closed");
refreshDeviceList(true,device_list);
},
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 );
}
}
enumGS = function(callback) {
navigator.mediaDevices.enumerateDevices().then(function(devices) {
var results = [];
for (var i in devices) {
var device = devices[i]
if (device.kind != "audioinput" && device.kind != "videoinput")
continue;
var facing = "";
if (device.kind == "videoinput" && navigator.userAgent.indexOf("Android") >= 0) {
if (device.label.indexOf("facing front") >= 0)
facing = "user";
else if (device.label.indexOf("facing back") >= 0)
facing = "environment";
}
results.push({
'id': device.deviceId,
'kind': device.kind == "audioinput" ? "audio" : "video",
'label': device.label,
'facing': facing
});
}
callback(results);
}, function(e) {
callback([]);
});
}
function refreshDeviceList(selectFirst) {
clearItems()
if (!navigator.mediaDevices) {
addItem('navigator.mediaDevices not supported');
return;
}
if (!navigator.mediaDevices.enumerateDevices) {
addItem('enumerateDevices not supported');
return;
}
MediaStreamTrack.getSources( function(infos) {
addItem('Output of MediaStreamTrack.getSources()')
var count = 0;
for (var i = 0; i < infos.length; i++) {
count++;
addItem('' + (count) + 'kind: ' + infos[i].kind + ', id: ' + infos[i].id + ', label: ' + infos[i].label + ', facing: ' + infos[i].facing);
}
});
enumGS( function(infos) {
addItem('Output of getSources shim based on enumerateDevices')
var count = 0;
for (var i = 0; i < infos.length; i++) {
count++;
addItem('' + (count) + 'kind: ' + infos[i].kind + ', id: ' + infos[i].id + ', label: ' + infos[i].label + ', facing: ' + infos[i].facing);
}
});
}
</script>
</body>
</html>