-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputOutput.js
70 lines (63 loc) · 1.96 KB
/
inputOutput.js
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
const audioInputEl = document.querySelector("#audio-input");
const audioOutputEl = document.querySelector("#audio-output");
const videoInputEl = document.querySelector("#video-input");
const getDevices = async () => {
try {
const devices = await navigator.mediaDevices.enumerateDevices();
console.log(devices);
devices.forEach((d) => {
const option = document.createElement("option"); // create the option tag
option.value = d.deviceId;
option.text = d.label;
// add the option we just created to the right select
if (d.kind === "audioinput") {
audioInputEl.appendChild(option);
} else if (d.kind === "audiooutput") {
audioOutputEl.appendChild(option);
} else if (d.kind === "videoinput") {
videoInputEl.appendChild(option);
}
});
} catch (error) {
console.log(error);
}
};
const chnageAudioInput = async (e) => {
// user has changed audio input
const deviceId = e.target.value;
console.log("ye hai selected audio input device id: ", deviceId);
const newConstraints = {
audio: { deviceId: { exact: deviceId } },
video: true,
};
try {
stream = await navigator.mediaDevices.getUserMedia(newConstraints);
console.log(stream);
const tracks = stream.getAudioTracks();
console.log(tracks);
} catch (error) {
console.log(error);
}
};
const chnageAudioOutput = async (e) => {
await videoEl.setSinkId(e.target.value);
console.log("changed audio device!");
};
const chnageVideo = async (e) => {
// user has changed video input
const deviceId = e.target.value;
console.log("ye hai selected audio input device id: ", deviceId);
const newConstraints = {
audio: true,
video: { deviceId: { exact: deviceId } },
};
try {
stream = await navigator.mediaDevices.getUserMedia(newConstraints);
console.log(stream);
const tracks = stream.getVideoTracks();
console.log(tracks);
} catch (error) {
console.log(error);
}
};
getDevices();