-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathpepc.js
More file actions
64 lines (58 loc) · 1.85 KB
/
pepc.js
File metadata and controls
64 lines (58 loc) · 1.85 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const API_STATUS_TO_DISPLAY_TEXT = {
success: "🟢 success",
error: "🔴 error",
unknown: "⚫️ unknown",
};
// Display the feature access status (whether the feature can actually be accessed successfully in the browser)
function updateaccessStatus(permissionName, accessStatus, errorMessage) {
const textToDisplay = API_STATUS_TO_DISPLAY_TEXT[accessStatus];
document.querySelector(`#${permissionName}-access-status`).innerText =
textToDisplay;
if (errorMessage) {
document.querySelector(`#${permissionName}-error-message`).innerText =
errorMessage;
}
}
// Utils (copied from `index.js`)
function successCallback(permissionName) {
return () => updateaccessStatus(permissionName, "success");
}
function errorCallback(permissionName) {
return (error) => updateaccessStatus(permissionName, "error", error.message);
}
const PEPC_TYPES_WITH_GRANTED_HANDLER = {
geolocation: () => {
navigator.geolocation.getCurrentPosition(
successCallback("geolocation"),
errorCallback("geolocation"),
);
},
camera: () => {
// TODO: Verify camera API works.
},
microphone: () => {
// TODO: Verify microphone API works.
},
"camera-microphone": () => {
// TODO: Verify camera-microphone API works.
},
};
window.addEventListener("load", () => {
for (const [type, grantedHandler] of Object.entries(
PEPC_TYPES_WITH_GRANTED_HANDLER,
)) {
const pepc = document.getElementById(type);
pepc.addEventListener("promptdismiss", () => {
console.log("Dismiss, permission status: " + pepc.permissionStatus);
if (pepc.permissionStatus === "granted") {
grantedHandler();
}
});
pepc.addEventListener("promptaction", () => {
console.log("Action, permission status: " + pepc.permissionStatus);
if (pepc.permissionStatus === "granted") {
grantedHandler();
}
});
}
});