Hide waveform on iOS because Webkit is broken
This commit is contained in:
1 parent
ab8e2fdc41
commit
c2c5c5221d
1 file changed
+30
-2
+30
-2
@@ -206,6 +206,14 @@
|
||||
var dpr = window.devicePixelRatio || 1;
|
||||
var BAR = 3, GAP = 1;
|
||||
var winSec = Math.max(4, wcfg.window || 30);
|
||||
// Safari/WebKit (all iOS browsers) never delivers real analyser samples
|
||||
// for a *live* stream — getFloatTimeDomainData reads back hard zeros
|
||||
// forever, even though playback itself works fine. Wait a couple of
|
||||
// seconds for a genuine non-zero sample before ever showing the canvas;
|
||||
// if none arrives, treat it as unsupported and give up for the session
|
||||
// instead of displaying a permanently flat/broken-looking line.
|
||||
var startTs = null, sawSignal = false;
|
||||
var SILENCE_GRACE_MS = 2000;
|
||||
var color = wcfg.color || getComputedStyle(document.documentElement).getPropertyValue('--accent').trim() || '#e21d31';
|
||||
|
||||
function size() {
|
||||
@@ -236,6 +244,14 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
function fail() {
|
||||
graphFailed = true;
|
||||
running = false;
|
||||
if (rafId) cancelAnimationFrame(rafId);
|
||||
rafId = null;
|
||||
canvas.hidden = true;
|
||||
}
|
||||
|
||||
function draw(ts) {
|
||||
if (!running) return;
|
||||
rafId = requestAnimationFrame(draw);
|
||||
@@ -245,6 +261,16 @@
|
||||
for (i = 0; i < timeData.length; i++) { var v = Math.abs(timeData[i]); if (v > m) m = v; }
|
||||
if (m > runningMax) runningMax = m;
|
||||
|
||||
if (startTs === null) startTs = ts;
|
||||
if (m > 0 && !sawSignal) {
|
||||
sawSignal = true;
|
||||
if (canvas.hidden) { canvas.hidden = false; size(); }
|
||||
} else if (!sawSignal && ts - startTs >= SILENCE_GRACE_MS) {
|
||||
fail();
|
||||
return;
|
||||
}
|
||||
if (!sawSignal) return; // still in the grace window — nothing to draw yet
|
||||
|
||||
var cssW = canvas.width / dpr, cssH = canvas.height / dpr;
|
||||
var step = BAR + GAP;
|
||||
var maxBars = Math.max(1, Math.floor(cssW / step));
|
||||
@@ -270,8 +296,10 @@
|
||||
function start() {
|
||||
if (!ensureGraph()) return;
|
||||
if (audioCtx.state === 'suspended' && audioCtx.resume) audioCtx.resume();
|
||||
if (canvas.hidden) { canvas.hidden = false; size(); }
|
||||
if (!running) { running = true; lastCommit = 0; rafId = requestAnimationFrame(draw); }
|
||||
if (!running) {
|
||||
running = true; lastCommit = 0; startTs = null; sawSignal = false;
|
||||
rafId = requestAnimationFrame(draw);
|
||||
}
|
||||
}
|
||||
function stop() {
|
||||
running = false;
|
||||
|
||||
Reference in new issue
Block a user