Struct VncConnector

Source
pub struct VncConnector<S, F>
where S: AsyncRead + AsyncWrite + Unpin + Send + 'static, F: Future<Output = Result<String, VncError>> + Send + Sync + 'static,
{ /* private fields */ }
Expand description

Connection Builder to setup a vnc client

Implementations§

Source§

impl<S, F> VncConnector<S, F>
where S: AsyncRead + AsyncWrite + Unpin + Send + Sync + 'static, F: Future<Output = Result<String, VncError>> + Send + Sync + 'static,

Source

pub fn new(stream: S) -> Self

To new a vnc client configuration with stream S

S should implement async I/O methods

use vnc::{PixelFormat, VncConnector, VncError};
use tokio::{self, net::TcpStream};

#[tokio::main]
async fn main() -> Result<(), VncError> {
    let tcp = TcpStream::connect("127.0.0.1:5900").await?;
    let vnc = VncConnector::new(tcp)
        .set_auth_method(async move { Ok("password".to_string()) })
        .add_encoding(vnc::VncEncoding::Tight)
        .add_encoding(vnc::VncEncoding::Zrle)
        .add_encoding(vnc::VncEncoding::CopyRect)
        .add_encoding(vnc::VncEncoding::Raw)
        .allow_shared(true)
        .set_pixel_format(PixelFormat::bgra())
        .build()?
        .try_start()
        .await?
        .finish()?;
    Ok(())
}
Source

pub fn set_auth_method(self, auth_callback: F) -> Self

An async callback which is used to query credentials if the vnc server has set

connector = connector.set_auth_method(async move { Ok("password".to_string()) })

if you’re building a wasm app, the async callback also allows you to combine it to a promise

#[wasm_bindgen]
extern "C" {
    fn get_password() -> js_sys::Promise;
}

connector = connector
       .set_auth_method(async move {
           let auth = JsFuture::from(get_password()).await.unwrap();
           Ok(auth.as_string().unwrap())
    });

While in the js code

var password = '';
function get_password() {
    return new Promise((reslove, reject) => {
       document.getElementById("submit_password").addEventListener("click", () => {
            password = window.document.getElementById("input_password").value
            reslove(password)
        })
    });
}

The future won’t be polled if the sever doesn’t apply any password protections to the session

Source

pub fn set_version(self, version: VncVersion) -> Self

The max vnc version that we supported

Version should be one of the VncVersion

Source

pub fn set_pixel_format(self, pf: PixelFormat) -> Self

Set the rgb order which you will use to resolve the image data

In most of the case, use PixelFormat::bgra() on little endian PCs

And use PixelFormat::rgba() on wasm apps (with canvas)

Also, customized format is allowed

Will use the default format informed by the vnc server if not set

In this condition, the client will get a crate::VncEvent::SetPixelFormat event notified

Source

pub fn allow_shared(self, allow_shared: bool) -> Self

Shared-flag is non-zero (true) if the server should try to share the

desktop by leaving other clients connected, and zero (false) if it

should give exclusive access to this client by disconnecting all

other clients.

Source

pub fn add_encoding(self, encoding: VncEncoding) -> Self

Client encodings that we want to use

One of VncEncoding

VncEncoding::Raw must be sent as the RFC required

The order to add encodings is the order to inform the server

Source

pub fn build(self) -> Result<VncState<S, F>, VncError>

Complete the client configuration

Auto Trait Implementations§

§

impl<S, F> Freeze for VncConnector<S, F>
where S: Freeze, F: Freeze,

§

impl<S, F> RefUnwindSafe for VncConnector<S, F>

§

impl<S, F> Send for VncConnector<S, F>

§

impl<S, F> Sync for VncConnector<S, F>
where S: Sync,

§

impl<S, F> Unpin for VncConnector<S, F>
where F: Unpin,

§

impl<S, F> UnwindSafe for VncConnector<S, F>
where S: UnwindSafe, F: 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more