-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | ||
} | ||
} |