commit
e651ee1b53
@ -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
|
||||||
|
@ -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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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) {
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user