Support vnc password
This commit is contained in:
parent
722c73f183
commit
94a58c4d62
@ -13,7 +13,6 @@ default = ["console_error_panic_hook"]
|
||||
[dependencies]
|
||||
wasm-bindgen = "0.2.83"
|
||||
js-sys = "0.3"
|
||||
anyhow="1"
|
||||
# bytes="1"
|
||||
|
||||
# The `console_error_panic_hook` crate provides better debugging of panics by
|
||||
|
@ -16,9 +16,11 @@ macro_rules! console_log {
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
fn setInterval(closure: &Closure<dyn FnMut()>, millis: u32) -> f64;
|
||||
fn setTimeout(closure: &Closure<dyn FnMut()>, millis: u32) -> f64;
|
||||
fn cancelInterval(token: f64);
|
||||
#[wasm_bindgen(js_namespace = console)]
|
||||
pub fn log(s: &str);
|
||||
pub fn prompt(s: &str) -> String;
|
||||
}
|
||||
|
||||
fn bind_mouse_and_key(vnc: &Vnc, canvas: &HtmlCanvasElement) {
|
||||
@ -166,9 +168,23 @@ fn vnc_out_handler(ws: &WebSocket, vnc: &Vnc) {
|
||||
Ok(_) => {}
|
||||
Err(err) => console_log!("error sending message: {:?}", err),
|
||||
},
|
||||
// vnc::VncOutput::RequirePassword => {
|
||||
// self.request_password = true;
|
||||
// }
|
||||
vnc::VncOutput::RequirePassword => {
|
||||
let vnc_cloned = vnc.clone();
|
||||
let ws_cloned = ws.clone();
|
||||
// set a interval for fps enhance
|
||||
let get_pwd = move || {
|
||||
let pwd = prompt("Please input the password");
|
||||
vnc_cloned.set_credential(&pwd);
|
||||
vnc_out_handler(&ws_cloned, &vnc_cloned);
|
||||
};
|
||||
|
||||
let handler = Box::new(get_pwd) as Box<dyn FnMut()>;
|
||||
|
||||
let cb = Closure::wrap(handler);
|
||||
|
||||
setTimeout(&cb, 20);
|
||||
cb.forget();
|
||||
}
|
||||
vnc::VncOutput::RenderCanvas(cr) => {
|
||||
let canvas = find_canvas();
|
||||
let ctx = canvas
|
||||
|
@ -48,11 +48,8 @@ impl Vnc {
|
||||
self.inner.lock().unwrap().get_output()
|
||||
}
|
||||
|
||||
pub fn set_credential(&self, username: &str, password: &str) {
|
||||
self.inner
|
||||
.lock()
|
||||
.unwrap()
|
||||
.set_credential(username, password);
|
||||
pub fn set_credential(&self, password: &str) {
|
||||
self.inner.lock().unwrap().set_credential(password);
|
||||
}
|
||||
|
||||
pub fn set_clipboard(&self, text: &str) {
|
||||
|
@ -138,7 +138,7 @@ impl Vnc {
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
pub fn set_credential(&mut self, _username: &str, password: &str) {
|
||||
pub fn set_credential(&mut self, password: &str) {
|
||||
// referring
|
||||
// https://github.com/whitequark/rust-vnc/blob/0697238f2706dd34a9a95c1640e385f6d8c02961/src/client.rs
|
||||
// strange behavior
|
||||
|
Loading…
Reference in New Issue
Block a user