The modeling WebSocket wrapper documents a connect() method it does not have, and the worker crashes on binary frames
Context: API Makeathon participant. Found while reviewing the modeling websocket support.
1. The documented connect() does not exist
The official generated example calls:
await modeling.modeling_commands_ws.connect({ client })
but ModelingCommandsWs contains only urlConstructFrom, authenticate, toBSON, and parseMessage. It has no connect, send, recv, close handling, or async iteration (src/api/modeling/modeling_commands_ws.ts; example from gen/templates/exampleWs.hbs; the class is exported directly from src/index.ts). All generated websocket tests are excluded (gen/expectedToFail.ts), so the mismatch is never caught.
2. The worker crashes on binary frames
src/worker-webrtc.ts:123 does if (ev.data.indexOf(id) < 0), assuming string frames. The modeling websocket sends binary (BSON) frames for some responses (which is why parseMessage has Buffer/ArrayBuffer branches). Blob and ArrayBuffer have no indexOf, so the handler throws TypeError and the pending command promise never resolves.
Concrete failure
A user follows the official example and calls modeling_commands_ws.connect({ client }), which fails at compile time with TS2339 (or at runtime with "connect is not a function" from JavaScript). If they instead assemble the socket manually, a binary response frame makes the worker throw and the awaiting promise hangs.
Verify
Grep connect in src/api/modeling/modeling_commands_ws.ts and gen/templates/exampleWs.hbs: only the example contains it. For the worker, deliver a Blob/ArrayBuffer frame to the worker-webrtc.ts:123 handler and observe the thrown TypeError.
Suggested fix
Either implement a real connect/send/recv (or async-iterable) wrapper for ModelingCommandsWs and enable its tests, or fix the example to show the actual supported usage. In the worker, branch on frame type before calling string methods.
Environment
Reviewed against the current main of KittyCAD/kittycad.ts.
The modeling WebSocket wrapper documents a
connect()method it does not have, and the worker crashes on binary framesContext: API Makeathon participant. Found while reviewing the modeling websocket support.
1. The documented
connect()does not existThe official generated example calls:
but
ModelingCommandsWscontains onlyurlConstructFrom,authenticate,toBSON, andparseMessage. It has noconnect,send,recv, close handling, or async iteration (src/api/modeling/modeling_commands_ws.ts; example fromgen/templates/exampleWs.hbs; the class is exported directly fromsrc/index.ts). All generated websocket tests are excluded (gen/expectedToFail.ts), so the mismatch is never caught.2. The worker crashes on binary frames
src/worker-webrtc.ts:123doesif (ev.data.indexOf(id) < 0), assuming string frames. The modeling websocket sends binary (BSON) frames for some responses (which is whyparseMessagehas Buffer/ArrayBuffer branches).BlobandArrayBufferhave noindexOf, so the handler throwsTypeErrorand the pending command promise never resolves.Concrete failure
A user follows the official example and calls
modeling_commands_ws.connect({ client }), which fails at compile time with TS2339 (or at runtime with "connect is not a function" from JavaScript). If they instead assemble the socket manually, a binary response frame makes the worker throw and the awaiting promise hangs.Verify
Grep
connectinsrc/api/modeling/modeling_commands_ws.tsandgen/templates/exampleWs.hbs: only the example contains it. For the worker, deliver aBlob/ArrayBufferframe to theworker-webrtc.ts:123handler and observe the thrownTypeError.Suggested fix
Either implement a real
connect/send/recv(or async-iterable) wrapper forModelingCommandsWsand enable its tests, or fix the example to show the actual supported usage. In the worker, branch on frame type before calling string methods.Environment
Reviewed against the current
mainof KittyCAD/kittycad.ts.