Skip to content

Commit

Permalink
Implement vncclient creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteOtter committed Jul 19, 2024
1 parent e3f32fb commit c17ebc5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions isototest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ repository = "https://github.com/ByteOtter/isotest-ng/tree/main/isototest"
license = "GPL-2.0"

[dependencies]
libvnc = "0.1.3"
ruperl = "0.0.1-alpha.1"
tokio = "1.38.1"
vnc-rs = "0.5.1"
33 changes: 26 additions & 7 deletions isototest/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,33 @@
pub fn add(left: usize, right: usize) -> usize {
left + right
use vnc::{PixelFormat, VncClient, VncConnector, VncError};
use tokio::{self, net::TcpStream};

pub async fn create_vnc_client(target_ip: String, psw: Option<String>) -> Result<VncClient, VncError> {
let tcp: TcpStream = TcpStream::connect(target_ip).await?;
let vnc: VncClient = VncConnector::new(tcp)
.set_auth_method(async move { Ok(psw.unwrap())})
.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(vnc)
}

#[cfg(test)]
mod tests {
use super::*;
use std::any::type_name_of_val;


#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
#[tokio::test]
async fn test_build_client() {
let res = create_vnc_client("192.168.0.1".to_string(), Some("Hello".to_string()));
assert!(type_name_of_val(&res).contains("VncClient"));
}
}

0 comments on commit c17ebc5

Please sign in to comment.