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>
impl<S, F> VncConnector<S, F>
Sourcepub fn new(stream: S) -> Self
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(())
}Sourcepub fn set_auth_method(self, auth_callback: F) -> Self
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
Sourcepub fn set_version(self, version: VncVersion) -> Self
pub fn set_version(self, version: VncVersion) -> Self
The max vnc version that we supported
Version should be one of the VncVersion
Sourcepub fn set_pixel_format(self, pf: PixelFormat) -> Self
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
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.
Sourcepub fn add_encoding(self, encoding: VncEncoding) -> Self
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