Repository navigation
Commit b64d142
committed
feat: a wasm/Web-Worker transport — the host supplies the pipe
Third transport beside with_notebook (Jupyter Comm) and no_notebook
(http.server + autobahn in threads). In a Web Worker none of that exists — no
Jupyter, no servers, no threads — but the host JS environment has postMessage.
So the contract is two functions on the JS global scope:
* the host defines __trinket_vpython_send(jsonString) BEFORE importing vpython;
every outbound update package (and the 'trigger' handshake) goes through it
* this module sets __trinket_vpython_dispatch(jsonArrayOfEvents); the host calls
it as browser events arrive, and every call — including a bare trigger — is
answered with a flush, the same request/reply rhythm the websocket transport
uses, paced by the browser's ~33 ms canvas_update timer
Selection is sys.platform == 'emscripten' in baseObj.__init__, tried after
_isnotebook so a notebook running under Pyodide (JupyterLite) still gets its
Comm. Importing the module IS the setup, exactly like the other two: GlowWidget()
first (it nulls the module-global sender outside a notebook), then install ours,
then an initial trigger() so the scene canvas buffered during `import vpython`
flushes and baseObj.sent unblocks appendcmd.
Verified end-to-end in trinket's real #108 worker (Pyodide 3.13.2, this branch's
pure wheel, deps=False), with send captured on the Python side:
MSG 0: {"cmds": [{"cmd": "canvas", ...}, {"cmd": "distant_light", ...} x2]}
MSG 1: {"cmds": [{"cmd": "sphere", "idx": 4, "color": [1,0,0], ...}],
"attrs": ["a4a1,2,3"]}
MSG 1's attrs entry is ball.pos = vector(1,2,3) in the protocol's compact
per-attribute wire coding — constructors, attribute updates and the
browser-driven flush all cross the seam. What remains is the OTHER half of the
pipe: a browser-side consumer of this stream (glowcomm.js reads the identical
format from a Comm), which lives in the embedding host, not here.1 parent 3c06704 commit b64d142
2 files changed
Lines changed: 83 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
263 | 263 | | |
264 | 264 | | |
265 | 265 | | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
266 | 270 | | |
267 | 271 | | |
268 | 272 | | |
| |||
0 commit comments