manual submission redesign phase C
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
const form = document.querySelector("#manual-report-form");
|
||||
const form = document.querySelector("#manual-report-form");
|
||||
|
||||
export function createBurstListener() {
|
||||
if (!form) return null;
|
||||
const start = document.querySelector("#burst-start");
|
||||
const container = start.closest(".burst-listener");
|
||||
const section = start.closest(".manual-report__supporting");
|
||||
const stateLabel = document.querySelector("#burst-state");
|
||||
const panel = document.querySelector("#burst-panel");
|
||||
const heading = document.querySelector("#burst-heading");
|
||||
const detail = document.querySelector("#burst-detail");
|
||||
@@ -42,6 +45,9 @@ export function createBurstListener() {
|
||||
|
||||
function setState(next) {
|
||||
state = next;
|
||||
if (container) container.dataset.state = next;
|
||||
if (section) section.dataset.state = next;
|
||||
if (stateLabel) stateLabel.textContent = next === "listening" ? "Listening for the next bang" : next === "tail" ? "Sound detected" : next === "captured" ? "Sound captured" : "Not listening";
|
||||
start.hidden = next !== "off";
|
||||
panel.hidden = next === "off";
|
||||
resume.hidden = discard.hidden = next !== "captured";
|
||||
@@ -73,6 +79,9 @@ export function createBurstListener() {
|
||||
async function begin() {
|
||||
error.hidden = true;
|
||||
start.disabled = true;
|
||||
if (container) container.dataset.state = "starting";
|
||||
if (section) section.dataset.state = "starting";
|
||||
if (stateLabel) stateLabel.textContent = "Starting microphone…";
|
||||
try {
|
||||
if (!navigator.mediaDevices?.getUserMedia || !window.AudioWorkletNode) throw new Error("Microphone listening is unavailable in this browser or connection.");
|
||||
stream = await navigator.mediaDevices.getUserMedia({ audio: { channelCount: 1 }, video: false });
|
||||
@@ -111,6 +120,9 @@ export function createBurstListener() {
|
||||
setState("listening");
|
||||
} catch (cause) {
|
||||
await end();
|
||||
if (container) container.dataset.state = "error";
|
||||
if (section) section.dataset.state = "error";
|
||||
if (stateLabel) stateLabel.textContent = "Microphone unavailable";
|
||||
error.textContent = cause.name === "NotAllowedError" ? "Microphone permission was denied. Manual reporting is still available." : (cause.message || "Microphone capture failed.");
|
||||
error.hidden = false;
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user