Files
olivv-cs-ComfyUI-FunPack/app/shell/client.js
T
digital-garbage f37f526268 app: Generate wired to a real run -- queued, progress, cancel, result
ComfyUI's own queue and its own socket, not a second one alongside them. A
FunPack queue would be a second thing tracking what is running, and the one the
user believes is whichever spoke last -- so this speaks to /prompt, /interrupt
and /ws as any ComfyUI client does and holds only a view of the server's state.
The graph is asked for, never assembled here, for the same reason.

The client id is remembered: ComfyUI addresses progress to the client that
queued the run, so a reload with a fresh id hears nothing about the generation
already in flight -- the run continues, the GPU time is spent, and the app says
Ready.

Faults found on the way, each in code that already had passing tests:

* `[hidden]` was inert across the whole kit. The UA rule is element-level, so
  `.cx-btn { display: inline-flex }` beats it -- Cancel was marked hidden, sat
  there, and nothing reported anything. jsdom cannot see it: the attribute was
  always correct. One reset rule, and a browser test over four element kinds.
* A panel passed no height to its body and a split pane passed none to its
  panes, so the viewer asked for 100% of `auto` and collapsed to a single line
  inside a panel that was the right size around it.
* subscribe() delivered the first state outside the guard every later delivery
  gets, so one bad listener took down whoever was wiring the UI up -- at
  startup, before anything existed to report it.
* A whole tests directory was never run: the test script globbed
  composer/tests only. `node --test` discovers them itself now, so there is no
  list to forget.
* `empty` was not in the content rule's key list, so three elements were never
  asked to prove their empty-state text comes back as text rather than markup.

The dev server now mounts the REAL routes -- register() already took a route
table -- instead of reimplementing them over http.server. It answered POST
/api/pipeline with 501, so the edit-and-queue path could not be looked at, which
is the one thing the dev server exists for.
2026-08-30 03:36:40 +03:00

29 lines
1.2 KiB
JavaScript

// This browser's identity to ComfyUI, and its socket.
//
// The id is REMEMBERED. ComfyUI addresses progress and results to the client
// that queued the run, so a reload with a new id is a reload that hears nothing
// about the generation already in flight -- the run continues, the GPU time is
// spent, and the app sits there saying Ready. v4 learned this the hard way and
// kept a fixed id for exactly this reason.
const KEY = "funpack.client-id";
export function clientId() {
try {
const kept = window.localStorage.getItem(KEY);
if (kept) return kept;
} catch { /* private mode: a fresh id per load, which still works */ }
const fresh = (globalThis.crypto && globalThis.crypto.randomUUID)
? globalThis.crypto.randomUUID()
: `funpack-${Date.now()}-${Math.random().toString(36).slice(2)}`;
try { window.localStorage.setItem(KEY, fresh); } catch { /* not fatal */ }
return fresh;
}
/** ComfyUI's socket, on whatever origin served this page. */
export function connect(id) {
const scheme = window.location.protocol === "https:" ? "wss:" : "ws:";
return new WebSocket(`${scheme}//${window.location.host}/ws?clientId=${encodeURIComponent(id)}`);
}