Merge pull request #22 from HsuJv/dev

Support vnc password
This commit is contained in:
Jovi Hsu 2022-09-27 15:42:01 +08:00 committed by GitHub
commit e651ee1b53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 13 deletions

View File

@ -13,7 +13,6 @@ default = ["console_error_panic_hook"]
[dependencies] [dependencies]
wasm-bindgen = "0.2.83" wasm-bindgen = "0.2.83"
js-sys = "0.3" js-sys = "0.3"
anyhow="1"
# bytes="1" # bytes="1"
# The `console_error_panic_hook` crate provides better debugging of panics by # The `console_error_panic_hook` crate provides better debugging of panics by

View File

@ -16,9 +16,11 @@ macro_rules! console_log {
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { extern "C" {
fn setInterval(closure: &Closure<dyn FnMut()>, millis: u32) -> f64; fn setInterval(closure: &Closure<dyn FnMut()>, millis: u32) -> f64;
// fn setTimeout(closure: &Closure<dyn FnMut()>, millis: u32) -> f64;
fn cancelInterval(token: f64); fn cancelInterval(token: f64);
#[wasm_bindgen(js_namespace = console)] #[wasm_bindgen(js_namespace = console)]
pub fn log(s: &str); pub fn log(s: &str);
pub fn prompt(s: &str) -> String;
} }
fn bind_mouse_and_key(vnc: &Vnc, canvas: &HtmlCanvasElement) { fn bind_mouse_and_key(vnc: &Vnc, canvas: &HtmlCanvasElement) {
@ -166,9 +168,11 @@ fn vnc_out_handler(ws: &WebSocket, vnc: &Vnc) {
Ok(_) => {} Ok(_) => {}
Err(err) => console_log!("error sending message: {:?}", err), Err(err) => console_log!("error sending message: {:?}", err),
}, },
// vnc::VncOutput::RequirePassword => { vnc::VncOutput::RequirePassword => {
// self.request_password = true; let pwd = prompt("Please input the password");
// } vnc.set_credential(&pwd);
vnc_out_handler(ws, vnc);
}
vnc::VncOutput::RenderCanvas(cr) => { vnc::VncOutput::RenderCanvas(cr) => {
let canvas = find_canvas(); let canvas = find_canvas();
let ctx = canvas let ctx = canvas
@ -214,15 +218,15 @@ fn vnc_out_handler(ws: &WebSocket, vnc: &Vnc) {
} }
vnc::VncOutput::SetCanvas(x, y) => { vnc::VncOutput::SetCanvas(x, y) => {
set_canvas(vnc, *x, *y); set_canvas(vnc, *x, *y);
vnc.require_frame(0);
vnc_out_handler(ws, vnc);
let vnc_cloned = vnc.clone(); let vnc_cloned = vnc.clone();
let ws_cloned = ws.clone(); let ws_cloned = ws.clone();
let mut incremental = 0;
// set a interval for fps enhance // set a interval for fps enhance
let refresh = move || { let refresh = move || {
vnc_cloned.require_frame(incremental); vnc_cloned.require_frame(1);
incremental = if incremental > 0 { incremental } else { 1 };
vnc_out_handler(&ws_cloned, &vnc_cloned); vnc_out_handler(&ws_cloned, &vnc_cloned);
}; };

View File

@ -48,11 +48,8 @@ impl Vnc {
self.inner.lock().unwrap().get_output() self.inner.lock().unwrap().get_output()
} }
pub fn set_credential(&self, username: &str, password: &str) { pub fn set_credential(&self, password: &str) {
self.inner self.inner.lock().unwrap().set_credential(password);
.lock()
.unwrap()
.set_credential(username, password);
} }
pub fn set_clipboard(&self, text: &str) { pub fn set_clipboard(&self, text: &str) {

View File

@ -138,7 +138,7 @@ impl Vnc {
Vec::new() Vec::new()
} }
pub fn set_credential(&mut self, _username: &str, password: &str) { pub fn set_credential(&mut self, password: &str) {
// referring // referring
// https://github.com/whitequark/rust-vnc/blob/0697238f2706dd34a9a95c1640e385f6d8c02961/src/client.rs // https://github.com/whitequark/rust-vnc/blob/0697238f2706dd34a9a95c1640e385f6d8c02961/src/client.rs
// strange behavior // strange behavior