pub struct Client { /* private fields */ }Expand description
A connection to a streamed session. Cheap to share by reference; every
method takes &self. Its threads end when it is dropped.
Implementations§
Source§impl Client
impl Client
Sourcepub fn connect(
url: &str,
token: &str,
options: ConnectOptions,
) -> Result<Client, Error>
pub fn connect( url: &str, token: &str, options: ConnectOptions, ) -> Result<Client, Error>
Connect to a running brep-app --stream: url is its WebSocket
(ws://127.0.0.1:8770/stream/ws) or its address (127.0.0.1:8770),
token the session token from its token file.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
The server’s session id.
Sourcepub fn send(&self, input: Input)
pub fn send(&self, input: Input)
Send one input. Applies only while this client controls the session.
Examples found in repository?
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9 let program = std::env::args().nth(1).unwrap_or_else(|| "brep-app".into());
10 let started = Instant::now();
11 // 1280 x 800 logical pixels at density 1. The app ends with the session.
12 let session = Launcher::new(&program).size(1280.0, 800.0, 1.0).launch()?;
13 session.wait_still(Duration::from_millis(1500), Duration::from_secs(120))?;
14 let (width, height) = {
15 let frame = session.frame();
16 (frame.width, frame.height)
17 };
18 println!("ready in {:.1} s: {width} x {height} pixels", started.elapsed().as_secs_f32());
19
20 // The File menu sits at (148, 19) in the default layout.
21 let (x, y) = (148.0, 19.0);
22 let clicked = Instant::now();
23 session.send(Input::PointerMove { x, y });
24 session.send(Input::Button { x, y, button: PointerButton::Primary, down: true, mods: Mods::NONE });
25 session.send(Input::Button { x, y, button: PointerButton::Primary, down: false, mods: Mods::NONE });
26 session.wait_frame(Duration::from_secs(10))?;
27 println!("the click came back as a new frame in {} ms", clicked.elapsed().as_millis());
28 session.wait_still(Duration::from_millis(500), Duration::from_secs(30))?;
29
30 {
31 let frame = session.frame();
32 image::save_buffer("brep-cad.png", &frame.rgba, frame.width, frame.height, image::ColorType::Rgba8)?;
33 println!("saved brep-cad.png after {} frames", frame.frames);
34 }
35 let status = session.shutdown(Duration::from_secs(15))?;
36 println!("the app exited: {status}");
37 Ok(())
38}Sourcepub fn resize(&self, width: f32, height: f32, density: f32)
pub fn resize(&self, width: f32, height: f32, density: f32)
Ask for the session at this size (logical pixels) and density. The
next frames arrive at width * density by height * density pixels.
Sourcepub fn take_control(&self)
pub fn take_control(&self)
Become the controlling client (the current one becomes a viewer).
Sourcepub fn set_quality(&self, jpeg: u8)
pub fn set_quality(&self, jpeg: u8)
JPEG quality (10-95) of the 3D view’s tiles while it moves.
pub fn role(&self) -> Role
Sourcepub fn set_waker(&self, waker: impl Fn() + Send + Sync + 'static)
pub fn set_waker(&self, waker: impl Fn() + Send + Sync + 'static)
Called (on the connection’s threads) whenever a frame or an event arrives: a GUI host asks itself to repaint here.
Sourcepub fn frame(&self) -> MutexGuard<'_, Frame>
pub fn frame(&self) -> MutexGuard<'_, Frame>
The current picture. Hold the guard briefly: frames wait for it.
Examples found in repository?
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9 let program = std::env::args().nth(1).unwrap_or_else(|| "brep-app".into());
10 let started = Instant::now();
11 // 1280 x 800 logical pixels at density 1. The app ends with the session.
12 let session = Launcher::new(&program).size(1280.0, 800.0, 1.0).launch()?;
13 session.wait_still(Duration::from_millis(1500), Duration::from_secs(120))?;
14 let (width, height) = {
15 let frame = session.frame();
16 (frame.width, frame.height)
17 };
18 println!("ready in {:.1} s: {width} x {height} pixels", started.elapsed().as_secs_f32());
19
20 // The File menu sits at (148, 19) in the default layout.
21 let (x, y) = (148.0, 19.0);
22 let clicked = Instant::now();
23 session.send(Input::PointerMove { x, y });
24 session.send(Input::Button { x, y, button: PointerButton::Primary, down: true, mods: Mods::NONE });
25 session.send(Input::Button { x, y, button: PointerButton::Primary, down: false, mods: Mods::NONE });
26 session.wait_frame(Duration::from_secs(10))?;
27 println!("the click came back as a new frame in {} ms", clicked.elapsed().as_millis());
28 session.wait_still(Duration::from_millis(500), Duration::from_secs(30))?;
29
30 {
31 let frame = session.frame();
32 image::save_buffer("brep-cad.png", &frame.rgba, frame.width, frame.height, image::ColorType::Rgba8)?;
33 println!("saved brep-cad.png after {} frames", frame.frames);
34 }
35 let status = session.shutdown(Duration::from_secs(15))?;
36 println!("the app exited: {status}");
37 Ok(())
38}Sourcepub fn take_update(&self) -> Option<Update>
pub fn take_update(&self) -> Option<Update>
What changed since the last call (None: nothing).
Sourcepub fn poll_events(&self) -> Vec<Event>
pub fn poll_events(&self) -> Vec<Event>
The events that arrived since the last call.
Sourcepub fn wait_frame(&self, timeout: Duration) -> Result<(), Error>
pub fn wait_frame(&self, timeout: Duration) -> Result<(), Error>
Wait until a frame newer than the one held now arrives.
Examples found in repository?
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9 let program = std::env::args().nth(1).unwrap_or_else(|| "brep-app".into());
10 let started = Instant::now();
11 // 1280 x 800 logical pixels at density 1. The app ends with the session.
12 let session = Launcher::new(&program).size(1280.0, 800.0, 1.0).launch()?;
13 session.wait_still(Duration::from_millis(1500), Duration::from_secs(120))?;
14 let (width, height) = {
15 let frame = session.frame();
16 (frame.width, frame.height)
17 };
18 println!("ready in {:.1} s: {width} x {height} pixels", started.elapsed().as_secs_f32());
19
20 // The File menu sits at (148, 19) in the default layout.
21 let (x, y) = (148.0, 19.0);
22 let clicked = Instant::now();
23 session.send(Input::PointerMove { x, y });
24 session.send(Input::Button { x, y, button: PointerButton::Primary, down: true, mods: Mods::NONE });
25 session.send(Input::Button { x, y, button: PointerButton::Primary, down: false, mods: Mods::NONE });
26 session.wait_frame(Duration::from_secs(10))?;
27 println!("the click came back as a new frame in {} ms", clicked.elapsed().as_millis());
28 session.wait_still(Duration::from_millis(500), Duration::from_secs(30))?;
29
30 {
31 let frame = session.frame();
32 image::save_buffer("brep-cad.png", &frame.rgba, frame.width, frame.height, image::ColorType::Rgba8)?;
33 println!("saved brep-cad.png after {} frames", frame.frames);
34 }
35 let status = session.shutdown(Duration::from_secs(15))?;
36 println!("the app exited: {status}");
37 Ok(())
38}Sourcepub fn wait_still(
&self,
quiet: Duration,
timeout: Duration,
) -> Result<(), Error>
pub fn wait_still( &self, quiet: Duration, timeout: Duration, ) -> Result<(), Error>
Wait until no frame has arrived for quiet (the picture is still), or
fail after timeout.
Examples found in repository?
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9 let program = std::env::args().nth(1).unwrap_or_else(|| "brep-app".into());
10 let started = Instant::now();
11 // 1280 x 800 logical pixels at density 1. The app ends with the session.
12 let session = Launcher::new(&program).size(1280.0, 800.0, 1.0).launch()?;
13 session.wait_still(Duration::from_millis(1500), Duration::from_secs(120))?;
14 let (width, height) = {
15 let frame = session.frame();
16 (frame.width, frame.height)
17 };
18 println!("ready in {:.1} s: {width} x {height} pixels", started.elapsed().as_secs_f32());
19
20 // The File menu sits at (148, 19) in the default layout.
21 let (x, y) = (148.0, 19.0);
22 let clicked = Instant::now();
23 session.send(Input::PointerMove { x, y });
24 session.send(Input::Button { x, y, button: PointerButton::Primary, down: true, mods: Mods::NONE });
25 session.send(Input::Button { x, y, button: PointerButton::Primary, down: false, mods: Mods::NONE });
26 session.wait_frame(Duration::from_secs(10))?;
27 println!("the click came back as a new frame in {} ms", clicked.elapsed().as_millis());
28 session.wait_still(Duration::from_millis(500), Duration::from_secs(30))?;
29
30 {
31 let frame = session.frame();
32 image::save_buffer("brep-cad.png", &frame.rgba, frame.width, frame.height, image::ColorType::Rgba8)?;
33 println!("saved brep-cad.png after {} frames", frame.frames);
34 }
35 let status = session.shutdown(Duration::from_secs(15))?;
36 println!("the app exited: {status}");
37 Ok(())
38}