Skip to main content

Session

Struct Session 

Source
pub struct Session { /* private fields */ }
Expand description

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.

Implementations§

Source§

impl Session

Source

pub fn url(&self) -> &str

The session’s WebSocket, for more clients (Client::connect): a second view of the same session, or a browser page (/stream/ beside it).

Source

pub fn token(&self) -> &str

The session’s token, for more clients.

Source

pub fn pid(&self) -> Option<u32>

The app’s process id.

Source

pub fn shutdown(self, timeout: Duration) -> Result<ExitStatus>

End the app and wait for it, up to timeout; kill it after that.

Examples found in repository?
examples/snapshot.rs (line 35)
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}

Methods from Deref<Target = Client>§

Source

pub fn session_id(&self) -> &str

The server’s session id.

Source

pub fn send(&self, input: Input)

Send one input. Applies only while this client controls the session.

Examples found in repository?
examples/snapshot.rs (line 23)
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}
Source

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.

Source

pub fn take_control(&self)

Become the controlling client (the current one becomes a viewer).

Source

pub fn set_quality(&self, jpeg: u8)

JPEG quality (10-95) of the 3D view’s tiles while it moves.

Source

pub fn role(&self) -> Role

Source

pub fn closed(&self) -> Option<String>

Why the connection ended, once it has.

Source

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.

Source

pub fn frame(&self) -> MutexGuard<'_, Frame>

The current picture. Hold the guard briefly: frames wait for it.

Examples found in repository?
examples/snapshot.rs (line 15)
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}
Source

pub fn take_update(&self) -> Option<Update>

What changed since the last call (None: nothing).

Source

pub fn poll_events(&self) -> Vec<Event>

The events that arrived since the last call.

Source

pub fn wait_frame(&self, timeout: Duration) -> Result<(), Error>

Wait until a frame newer than the one held now arrives.

Examples found in repository?
examples/snapshot.rs (line 26)
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}
Source

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?
examples/snapshot.rs (line 13)
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}

Trait Implementations§

Source§

impl Deref for Session

Source§

type Target = Client

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Client

Dereferences the value.
Source§

impl Drop for Session

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl Forget for Session

§

impl Freeze for Session
where I32NotAllOnes: Freeze, *mut Counter<Channel<String>>: Freeze, *mut Counter<Channel<String>>: Freeze, *mut Counter<Channel<String>>: Freeze, *const ArcInner<Shared> is !null: Freeze, PhantomData<ArcInner<Shared>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const ArcInner<Atomic<bool>> is !null: Freeze, PhantomData<ArcInner<Atomic<bool>>>: Freeze,

§

impl Move for Session

§

impl RefUnwindSafe for Session

§

impl Send for Session
where I32NotAllOnes: Send, Sender<String>: Send, Arc<Shared>: Send, RawVecInner: Send, Arc<Atomic<bool>>: Send,

§

impl Sync for Session
where I32NotAllOnes: Sync, Sender<String>: Sync, Arc<Shared>: Sync, RawVecInner: Sync, Arc<Atomic<bool>>: Sync,

§

impl Unpin for Session
where I32NotAllOnes: Unpin, *mut Counter<Channel<String>>: Unpin, *mut Counter<Channel<String>>: Unpin, *mut Counter<Channel<String>>: Unpin, Arc<Shared>: Unpin, *const u8 is !null: Unpin, Arc<Atomic<bool>>: Unpin,

§

impl UnsafeUnpin for Session
where I32NotAllOnes: UnsafeUnpin, *mut Counter<Channel<String>>: UnsafeUnpin, *mut Counter<Channel<String>>: UnsafeUnpin, *mut Counter<Channel<String>>: UnsafeUnpin, *const ArcInner<Shared> is !null: UnsafeUnpin, PhantomData<ArcInner<Shared>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const ArcInner<Atomic<bool>> is !null: UnsafeUnpin, PhantomData<ArcInner<Atomic<bool>>>: UnsafeUnpin,

§

impl UnwindSafe for Session
where I32NotAllOnes: UnwindSafe, Sender<String>: UnwindSafe, Arc<Shared>: UnwindSafe, RawVecInner: UnwindSafe, Arc<Atomic<bool>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V