-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbridge.js
More file actions
44 lines (42 loc) · 1.33 KB
/
bridge.js
File metadata and controls
44 lines (42 loc) · 1.33 KB
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
(async () => {
try {
const result = await chrome.storage.local.get("camSpoofer");
const config = result.camSpoofer;
if (config && config.enabled && config.selectedLabel) {
document.documentElement.setAttribute(
"data-cam-spoofer",
JSON.stringify(config)
);
}
} catch (_) {}
})();
chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => {
if (msg.type === "getDevices") {
navigator.mediaDevices
.enumerateDevices()
.then((devices) => {
const cameras = devices
.filter((d) => d.kind === "videoinput")
.map((d) => ({ label: d.label, groupId: d.groupId }));
sendResponse({ cameras });
})
.catch(() => sendResponse({ cameras: [] }));
return true; // keep channel open for async response
}
if (msg.type === "requestCamera") {
navigator.mediaDevices
.getUserMedia({ video: true })
.then((stream) => {
stream.getTracks().forEach((t) => t.stop());
return navigator.mediaDevices.enumerateDevices();
})
.then((devices) => {
const cameras = devices
.filter((d) => d.kind === "videoinput")
.map((d) => ({ label: d.label, groupId: d.groupId }));
sendResponse({ cameras });
})
.catch(() => sendResponse({ cameras: [] }));
return true;
}
});