Skip to content

modeling_commands_ws documents a nonexistent connect(); the WebRTC worker crashes on binary frames #660

Description

@sneg55

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions