Skip to content

Commit 99ca9ec

Browse files
committed
chore: log resume failures and lifeline resume
1 parent 9f95dc3 commit 99ca9ec

1 file changed

Lines changed: 43 additions & 30 deletions

File tree

web/assets/playframe.js

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,14 @@
8989
try {
9090
if (ctx.state !== "running") {
9191
logAudio("resume miniaudio device", idx, ctx.state);
92-
ctx.resume().catch(() => {});
92+
const p = ctx.resume();
93+
if (p && typeof p.catch === "function") {
94+
p.catch((err) => logAudio("resume miniaudio device failed", idx, err && err.message));
95+
}
9396
}
94-
} catch (_) {}
97+
} catch (err) {
98+
logAudio("resume miniaudio device threw", idx, err && err.message);
99+
}
95100
}
96101
idx++;
97102
}
@@ -183,6 +188,37 @@
183188
window.webkitAudioContext = WrappedAudioContext;
184189
}
185190

191+
const tryResumeContext = (ctx, label) => {
192+
if (!ctx || typeof ctx.resume !== "function") return;
193+
if (ctx.state === "closed") {
194+
logAudio("skip closed context", label);
195+
return;
196+
}
197+
if (ctx.state === "running") {
198+
logAudio("context already running", label);
199+
primeContext(ctx);
200+
reconnectScriptNodes(ctx);
201+
return;
202+
}
203+
logAudio("resuming AudioContext", label, ctx.state);
204+
try {
205+
const result = ctx.resume();
206+
const afterResume = () => {
207+
logAudio("context resumed", label, ctx.state);
208+
reconnectScriptNodes(ctx);
209+
primeContext(ctx);
210+
setTimeout(() => logAudio("context state post-resume delay", label, ctx.state), 250);
211+
};
212+
if (result && typeof result.then === "function") {
213+
result.then(afterResume).catch((err) => logAudio("resume failed", label, err && err.message));
214+
} else {
215+
afterResume();
216+
}
217+
} catch (err) {
218+
logAudio("resume threw", label, err && err.message);
219+
}
220+
};
221+
186222
const resumeAll = () => {
187223
if (contexts.size === 0) {
188224
logAudio("resumeAll: no contexts yet");
@@ -195,35 +231,12 @@
195231
logAudio("failed to create lifeline AudioContext", err && err.message);
196232
}
197233
}
198-
contexts.forEach((ctx) => {
199-
if (!ctx || typeof ctx.resume !== "function") return;
200-
if (ctx.state === "closed") {
201-
logAudio("skip closed context");
202-
return;
203-
}
204-
if (ctx.state === "running") {
205-
logAudio("context already running");
206-
primeContext(ctx);
207-
reconnectScriptNodes(ctx);
208-
return;
209-
}
210-
try {
211-
logAudio("resuming AudioContext", ctx.state);
212-
const result = ctx.resume();
213-
const afterResume = () => {
214-
logAudio("context resumed", ctx.state);
215-
reconnectScriptNodes(ctx);
216-
primeContext(ctx);
217-
};
218-
if (result && typeof result.then === "function") {
219-
result.then(afterResume).catch(() => {});
220-
} else {
221-
afterResume();
222-
}
223-
} catch (_) {
224-
/* ignore resume errors */
225-
}
234+
contexts.forEach((ctx, idx) => {
235+
tryResumeContext(ctx, idx);
226236
});
237+
if (lifeline) {
238+
tryResumeContext(lifeline, "lifeline");
239+
}
227240
resumeMiniaudioDevices();
228241
};
229242

0 commit comments

Comments
 (0)