-
Notifications
You must be signed in to change notification settings - Fork 0
/
enumerate_bug.html
115 lines (104 loc) · 3.52 KB
/
enumerate_bug.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
<html>
<meta charset=utf-8>
<video id="video1" height="120" autoplay></video>
<video id="video2" height="120" autoplay></video><br>
<button id="gum_audio">Start Mic!</button>
<button id="gum_video">Start Cam!</button>
<button id="gum_both">Start Both!</button>
<button id="gdm_video">Present!</button>
<button id="stopp">Stop!</button>
<button id="micspeakers" disabled>Use Mic's speakers!</button>
<button id="speakers">Switch speakers!</button>
<button id="list">Enumerate Devices!</button>
<button id="reload">Reload!</button>
<label><input type="checkbox" id="muted">Face-muted</label>
<div id="div"><br></div>
<script>
const console = {log: msg => div.innerHTML += `${msg}<br>`};
let unstopped = [];
async function gum({audio, video}) {
try {
const stream = await navigator.mediaDevices.getUserMedia({audio, video});
if (video1.srcObject && !audio != !video) {
const [oldvideo] = video1.srcObject.getVideoTracks();
const [oldaudio] = video1.srcObject.getAudioTracks();
if (audio && oldvideo) {
stream.addTrack(oldvideo);
} else if (video && oldaudio) {
stream.addTrack(oldaudio);
}
}
video1.srcObject = stream;
unstopped.push(...video1.srcObject.getTracks());
if (stream.getAudioTracks().length) {
micspeakers.disabled = false;
}
} catch (e) {
console.log(e);
}
}
async function gdm(constraints) {
try {
video2.srcObject = await navigator.mediaDevices.getDisplayMedia(constraints);
unstopped.push(...video2.srcObject.getTracks());
} catch (e) {
console.log(e);
}
}
gum_audio.onclick = () => gum({audio: true});
gum_video.onclick = () => gum({video: true});
gum_both.onclick = () => gum({video: true, audio: true});
gdm_video.onclick = () => gdm();
stopp.onclick = () => {
unstopped.forEach(track => track.stop());
unstopped = [];
};
micspeakers.onclick = async () => {
try {
const groupId = video1.srcObject?.getAudioTracks()[0]?.getSettings().groupId;
if (!groupId) {
console.log(`Start mic first!`);
return;
}
const devices = await navigator.mediaDevices.enumerateDevices();
const mikespeakers = devices.find(d => d.kind == "audiooutput" && d.groupId == groupId);
if (!mikespeakers) {
console.log(`No speakers associated with this mic!`);
return;
}
// Microphone loophole (calling selectAudioOutput() is not needed)
//
// BUG REPRO: But calling selectAudioOutput({deviceId}) shouldn't prompt either.
const {deviceId, label} = await navigator.mediaDevices.selectAudioOutput({
deviceId: mikespeakers.deviceId
});
console.log(`Switching speakers to ${mikespeakers.label}`);
await video1.setSinkId(deviceId);
} catch (e) {
console.log(e);
}
}
speakers.onclick = async () => {
try {
const {deviceId, label} = await navigator.mediaDevices.selectAudioOutput();
console.log(`Switching speakers to ${label}`);
await video1.setSinkId(deviceId);
} catch (e) {
console.log(e);
}
}
muted.onclick = () => {
video1.srcObject.getTracks().forEach(track => track.enabled = !muted.checked);
video2.srcObject.getTracks().forEach(track => track.enabled = !muted.checked);
};
list.onclick = async () => {
const devices = await navigator.mediaDevices.enumerateDevices();
log(devices.length + " devices.");
for (const {kind, label, deviceId, groupId} of devices) {
console.log(`${kind}: ${label} id=${deviceId} group=${groupId}`);
}
}
reload.onclick = () => location.reload();
navigator.mediaDevices.ondevicechange = () => log("device change!");
</script>
</html>