A new radio mode sends each spoken row as ggwave frames of at most 140 bytes: frame 1 carries the full session id, later frames its 8-character prefix, each with n/m. engines.sound_of() gives every speaker one of the four audible ggwave protocols that decode every frame length, plus its own stereo position, by a stable hash. The vendored ggwave 0.4.0 (MIT, LICENSE kept, sha256 pinned in test_hub_artifacts) runs only in the /gibberlink encoder page, sandboxed into an opaque origin with eval and WebAssembly but no connection; the hub page frames it (frame-src 'self') and review pages refuse framing (frame-ancestors 'none'). The radio gear gains a fallback selector (Gibberlink, Morse, Hiss) for rows that speech cannot play. Accepted MEDUSA false positives (security.py accept after kvb-think-criticize, 2026-11-17): engines.py FTSCAN-231 INF-SCAN-2638 INF-SCAN-2057 STG009 B603; handler.py FTSC-SCAN-089 B105 EXA002 EXA006; view.py WEB-FLASK-004 FINE-043 LO002. 🎯 Fix: 91 % 💥 Break: 4 % 💸 Tokens: – ⏱️ Velocity: – 🛡️ Security: 100 % 🏆 Score: 87 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
51 lines
2.1 KiB
JavaScript
51 lines
2.1 KiB
JavaScript
const Gibberlink = (() => {
|
|
"use strict";
|
|
const VOLUME = 50;
|
|
const PREFIX = "GGWAVE_PROTOCOL_";
|
|
|
|
/**
|
|
* @param {object} ggwave the loaded ggwave module.
|
|
* @param {object} request protocol, a ggwave protocol name without its prefix, and frames, the frame texts.
|
|
* @returns {object} rate and samples: the samples of each frame at ggwave's own output rate; the vendored build's frames at 44.1 kHz do not decode, so the page resamples instead.
|
|
*/
|
|
function encode(ggwave, request) {
|
|
const {protocol, frames} = request;
|
|
const key = `${PREFIX}${protocol}`;
|
|
if (typeof protocol !== "string" || !Object.hasOwn(ggwave.ProtocolId, key) || !Array.isArray(frames) || !frames.every((frame) => typeof frame === "string")) {
|
|
throw new Error("refused: the request needs a known protocol and text frames");
|
|
}
|
|
const parameters = ggwave.getDefaultParameters();
|
|
const instance = ggwave.init(parameters);
|
|
try {
|
|
return {rate: parameters.sampleRateOut, samples: frames.map((frame) => {
|
|
const wave = ggwave.encode(instance, frame, ggwave.ProtocolId[key], VOLUME);
|
|
return new Float32Array(wave.buffer.slice(wave.byteOffset, wave.byteOffset + wave.length));
|
|
})};
|
|
} finally {
|
|
ggwave.free(instance);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @param {Window} scope the encoder frame's window; it answers only its parent.
|
|
* @param {Promise<object>} ready the ggwave module once loaded.
|
|
*/
|
|
function serve(scope, ready) {
|
|
scope.addEventListener("message", (event) => {
|
|
if (event.source !== scope.parent || !event.data || typeof event.data.id !== "number") {
|
|
return;
|
|
}
|
|
const {id} = event.data;
|
|
ready.then((ggwave) => encode(ggwave, event.data)).then(
|
|
({rate, samples}) => scope.parent.postMessage({id, rate, samples}, "*", samples.map((part) => part.buffer)),
|
|
(error) => scope.parent.postMessage({id, error: String((error && error.message) || error)}, "*"),
|
|
);
|
|
});
|
|
}
|
|
|
|
return {VOLUME, encode, serve};
|
|
})();
|
|
if (typeof module === "object" && module.exports) {
|
|
module.exports = Gibberlink;
|
|
}
|