Skip to main content

Crate brep_stream_client

Crate brep_stream_client 

Source
Expand description

Embed the next.BREP.io CAD application in a Rust program.

brep-app --stream runs the CAD application with no window and no display and serves its whole user interface over a WebSocket: every frame it draws, as tiles, and every input it should take. This crate is the native end of that connection, so a Rust program can show the CAD session inside its own window (any toolkit: it hands you RGBA pixels) and drive it, with no browser.

use brep_stream_client::{Input, Launcher, Mods, PointerButton};
// Start the app (it must be installed: `cargo install BREP_app`, or the
// desktop download) at 1280 x 800 logical pixels, density 1.
let session = Launcher::new("brep-app").size(1280.0, 800.0, 1.0).launch()?;
session.wait_frame(std::time::Duration::from_secs(120))?;
{
    let frame = session.frame();
    println!("{} x {} pixels", frame.width, frame.height);
}
// Click the File menu.
session.send(Input::Button { x: 148.0, y: 19.0, button: PointerButton::Primary, down: true, mods: Mods::NONE });
session.send(Input::Button { x: 148.0, y: 19.0, button: PointerButton::Primary, down: false, mods: Mods::NONE });

Coordinates are logical pixels (egui points, CSS pixels) from the top-left of the session; frames are physical pixels, density times as many. Launcher starts brep-app as a child process that ends when the Session is dropped; Client::connect attaches to one already running (brep-app --stream ADDR), given its address and session token.

The protocol is version 1 of the stream. Plain ws:// only: put TLS in front of a remote session with a reverse proxy, or reach it over an SSH tunnel.

Structs§

Client
A connection to a streamed session. Cheap to share by reference; every method takes &self. Its threads end when it is dropped.
ConnectOptions
How Client::connect introduces itself.
Frame
The session’s picture as this client holds it.
Launcher
Starts brep-app --stream as a child process and connects to it.
Mods
Modifier keys held with an input. meta is Cmd on a Mac keyboard; the session treats it, like Ctrl, as the command key.
Rect
A pixel rectangle x, y, width, height.
Session
A launched app and the connection to it. Derefs to Client. Dropping it ends the app (it closes the app’s stdin; the app exits as when its window closes) and waits for it, briefly.
Update
What changed since the last Client::take_update.

Enums§

Error
What went wrong.
Event
Something the session told this client.
Input
One input for the session. Positions are logical pixels from the session’s top-left corner.
PointerButton
Role
This client’s part in the session: one client controls it (its input and size apply); the others watch.
TouchPhase
WheelUnit
What a wheel delta counts.

Constants§

PROTOCOL
The stream protocol version this crate speaks.
READY_PREFIX
The line brep-app --stream prints when the session accepts connections.