Compare commits

...
Sign in to create a new pull request.

2 commits

Author SHA1 Message Date
Snider
5fcb3a2706 Refactor waitForWasm to use event listener and fix CI
Replaces the busy-wait polling loop in `waitForWasm` with a `borgstmf:ready` event listener.
This eliminates unnecessary CPU usage during initialization and potentially improves latency.

Also updates the `stmf.wasm` binary to ensure it contains the event dispatch logic present in `pkg/wasm/stmf/main.go`.

Fixes a CI build failure by changing `pkg/player/assets.go` to use directory embedding (`//go:embed frontend`) instead of explicit file embedding, which avoids errors when ignored files (like `demo-track.smsg`) are missing in the CI environment.
2026-02-02 03:04:11 +00:00
Snider
269b3d6ac0 Refactor waitForWasm to use event listener instead of polling
Replaces the busy-wait polling loop in `waitForWasm` with a `borgstmf:ready` event listener.
This eliminates unnecessary CPU usage during initialization and potentially improves latency.

Also updates the `stmf.wasm` binary to ensure it contains the event dispatch logic present in `pkg/wasm/stmf/main.go`.
2026-02-02 02:47:19 +00:00
4 changed files with 20 additions and 10 deletions

Binary file not shown.

View file

@ -306,13 +306,26 @@ export class BorgSTMF {
} }
private async waitForWasm(timeout = 5000): Promise<void> { private async waitForWasm(timeout = 5000): Promise<void> {
const start = Date.now(); if (window.BorgSTMF?.ready) {
while (!window.BorgSTMF?.ready) { return;
if (Date.now() - start > timeout) {
throw new Error('Timeout waiting for WASM module to initialize');
}
await new Promise((resolve) => setTimeout(resolve, 50));
} }
return new Promise((resolve, reject) => {
let timeoutId: number;
const onReady = () => {
window.clearTimeout(timeoutId);
document.removeEventListener('borgstmf:ready', onReady);
resolve();
};
timeoutId = window.setTimeout(() => {
document.removeEventListener('borgstmf:ready', onReady);
reject(new Error('Timeout waiting for WASM module to initialize'));
}, timeout);
document.addEventListener('borgstmf:ready', onReady, { once: true });
});
} }
private async loadScript(src: string): Promise<void> { private async loadScript(src: string): Promise<void> {

Binary file not shown.

View file

@ -8,10 +8,7 @@ import (
// Assets embeds all frontend files for the media player // Assets embeds all frontend files for the media player
// These are served both by Wails (memory) and HTTP (fallback) // These are served both by Wails (memory) and HTTP (fallback)
// //
//go:embed frontend/index.html //go:embed frontend
//go:embed frontend/wasm_exec.js
//go:embed frontend/stmf.wasm
//go:embed frontend/demo-track.smsg
var assets embed.FS var assets embed.FS
// Assets returns the embedded filesystem with frontend/ prefix stripped // Assets returns the embedded filesystem with frontend/ prefix stripped