-
Notifications
You must be signed in to change notification settings - Fork 3
/
script.js
71 lines (59 loc) · 1.92 KB
/
script.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
71
console.log("Use deviceId query param to request a specific device.");
navigator.mediaDevices
.enumerateDevices()
.then((devices) =>
devices.filter((d) => d.kind === "videoinput" || d.kind === "audioinput")
)
.then((devices) =>
devices
.map((d) => {
return "[" + d.kind + "] " + d.label + ": " + d.deviceId;
})
.join("\n\n")
)
.then(console.log);
const urlParams = new URLSearchParams(window.location.search);
const videoDeviceId = urlParams.get("deviceId");
const videoDeviceLabelSearch = urlParams.get("deviceLabel");
const audioDeviceId = urlParams.get("audioDeviceId");
async function startVideo() {
// find video device by label search
let foundDevice = null
if (videoDeviceLabelSearch) {
const devices = await navigator.mediaDevices.enumerateDevices();
foundDevice = devices.find(d => d.label.includes(videoDeviceLabelSearch));
}
const constraints = {
video: { width: 1920, height: 1080 },
audio: false,
};
const finalVideoDeviceId = videoDeviceId || foundDevice.deviceId;
if (finalVideoDeviceId) {
constraints.video.deviceId = { exact: finalVideoDeviceId };
}
if (audioDeviceId) {
constraints.audio = {
deviceId: { exact: audioDeviceId },
autoGainControl: false,
echoCancellation: false,
googAutoGainControl: false,
noiseSuppression: false,
};
}
console.log({ constraints });
const stream = await navigator.mediaDevices.getUserMedia(constraints);
document.querySelector("video").srcObject = stream;
}
function enterFullscreen() {
const element = document.documentElement;
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
}
}
startVideo();