browser audio processing phase 1
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
const PREFIX = "[BoomCast][BrowserBeta]";
|
||||
|
||||
export function readBrowserProcessingConfig() {
|
||||
const element = document.querySelector("#boomcast-browser-config");
|
||||
if (!element) return { browserProcessingBeta: false };
|
||||
try {
|
||||
return JSON.parse(element.textContent);
|
||||
} catch (error) {
|
||||
console.error(`${PREFIX} Configuration unavailable:`, error);
|
||||
return { browserProcessingBeta: false };
|
||||
}
|
||||
}
|
||||
|
||||
export class BrowserSubmissionProcessor {
|
||||
constructor(config = readBrowserProcessingConfig()) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
isEnabled() {
|
||||
return this.config.browserProcessingBeta === true;
|
||||
}
|
||||
|
||||
canProcess(file) {
|
||||
return this.isEnabled() && Boolean(file) && /^(audio|video)\//.test(file.type);
|
||||
}
|
||||
|
||||
async prepare(file) {
|
||||
if (!this.isEnabled()) return { file, metadata: null };
|
||||
console.log(`${PREFIX} Initialising beta submission pipeline.`);
|
||||
console.log(`${PREFIX} File selected:`, { type: file?.type || "", size: file?.size || 0 });
|
||||
if (!this.canProcess(file)) {
|
||||
console.log(`${PREFIX} Browser preprocessing unavailable; falling back.`);
|
||||
return { file, metadata: null };
|
||||
}
|
||||
let policyTimeout;
|
||||
try {
|
||||
const controller = new AbortController();
|
||||
policyTimeout = setTimeout(() => controller.abort(), 5000);
|
||||
const response = await fetch(this.config.policyUrl, {
|
||||
cache: "no-store", credentials: "same-origin", signal: controller.signal,
|
||||
});
|
||||
if (!response.ok) throw new Error(`Policy HTTP ${response.status}`);
|
||||
const policy = await response.json();
|
||||
if (!policy.browser_processing_beta_enabled || policy.version !== this.config.policyVersion) {
|
||||
console.log(`${PREFIX} Browser beta disabled or policy changed; using legacy submission flow.`);
|
||||
return { file, metadata: null };
|
||||
}
|
||||
// Pass 1 has no local classifier or transcoder. Keep the original file.
|
||||
console.log(`${PREFIX} Browser processing shell ready; using original recording.`);
|
||||
return {
|
||||
file,
|
||||
metadata: {
|
||||
browser_processing_used: false,
|
||||
browser_processing_version: policy.version,
|
||||
browser_gate_result: "unavailable",
|
||||
browser_override: false,
|
||||
},
|
||||
};
|
||||
} catch (error) {
|
||||
console.error(`${PREFIX} Initialisation failed:`, error);
|
||||
this.cleanup();
|
||||
console.log(`${PREFIX} Restoring legacy submission flow.`);
|
||||
return { file, metadata: null };
|
||||
} finally {
|
||||
clearTimeout(policyTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
cleanup() {
|
||||
// Future passes can release workers, object URLs, and model tensors here.
|
||||
console.log("[BoomCast][Cleanup] Browser beta resources released.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user