diff --git a/Makefile.toml b/Makefile.toml index c98ae28..8bd1f8f 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -1,34 +1,77 @@ [tasks.install-debug] -dependencies = ["websockify", "wasm-debug"] +dependencies = ["websockify", "rdp-debug", "vnc-debug", "ssh-debug"] [tasks.install-release] -dependencies = ["websockify", "wasm-release"] +dependencies = ["websockify", "rdp-release", "vnc-release", "ssh-release"] -[tasks.wasm-debug] +[tasks.rdp-debug] +dependencies = ["install-dir"] +script = ''' +cd ${RDP} && cargo make install-debug && cd .. +''' + +[tasks.vnc-debug] +dependencies = ["install-dir"] script = ''' cd ${VNC} && cargo make install-debug && cd .. -cd ${RDP} && cargo make install-debug && cd .. +''' + +[tasks.ssh-debug] +dependencies = ["install-dir"] +script = ''' cd ${SSH} && cargo make install-debug && cd .. ''' -[tasks.wasm-release] +[tasks.rdp-release] +dependencies = ["install-dir"] script = ''' -cd ${VNC} && cargo make install-release && cd .. cd ${RDP} && cargo make install-release && cd .. -cd ${SSH} && cargo make install-release && cd .. ''' +[tasks.vnc-release] +dependencies = ["install-dir"] +script = ''' +cd ${VNC} && cargo make install-release && cd .. +''' + +[tasks.ssh-release] +dependencies = ["install-dir"] +script = ''' +cd ${SSH} && cargo make install-release && cd .. +''' [tasks.websockify] dependencies = ["install-dir"] script = ''' -cd ${WEBSOCKIFY} && cargo build --release --features ssl && cp ./target/release/${WEBSOCKIFY} $INSTALL_PATH/ +cd ${WEBSOCKIFY} && cargo build --release --features ssl && cp ./target/release/${WEBSOCKIFY} ${INSTALL_PATH}/ ''' [tasks.install-dir] script = ''' -mkdir -p $INSTALL_PATH -cp assets/* $INSTALL_PATH +mkdir -p ${INSTALL_PATH} +cp assets/* ${INSTALL_PATH} +''' + +[tasks.clean-rdp] +script = ''' +cd ${RDP} && cargo clean && cd .. +''' + +[tasks.clean-vnc] +script = ''' +cd ${VNC} && cargo clean && cd .. +''' + +[tasks.clean-ssh] +script = ''' +cd ${SSH} && cargo clean && cd .. +''' + +[tasks.clean-all] +dependencies = ["clean-ssh", "clean-vnc", "clean-rdp"] +script = ''' +rm -rf ${INSTALL_PATH} +cd ${WEBSOCKIFY} && cargo clean && cd .. ''' [env] diff --git a/webvnc/Cargo.toml b/webvnc/Cargo.toml index 2e45628..832359a 100644 --- a/webvnc/Cargo.toml +++ b/webvnc/Cargo.toml @@ -13,7 +13,7 @@ default = ["console_error_panic_hook"] [dependencies] wasm-bindgen = "0.2.63" js-sys = "0.3" -vnc-rs = "^0.3" +vnc-rs = "^0.4" fluvio-wasm-timer = "0.2.5" # websocket diff --git a/webvnc/src/lib.rs b/webvnc/src/lib.rs index bf2e257..4422fdf 100644 --- a/webvnc/src/lib.rs +++ b/webvnc/src/lib.rs @@ -5,7 +5,8 @@ mod x11keyboard; use ::vnc::{client::connector::VncConnector, PixelFormat, VncEncoding, VncEvent, X11Event}; use canvas::CanvasUtils; -use tracing::info; +use futures::StreamExt; +use tracing::{error, info}; use tracing_wasm::WASMLayerConfigBuilder; use wasm_bindgen::prelude::*; use wasm_bindgen_futures::spawn_local; @@ -71,14 +72,8 @@ fn run() -> Result<(), JsValue> { let vnc = vnc.unwrap().finish().unwrap(); - let (vnc_evnets_sender, mut vnc_events_receiver) = tokio::sync::mpsc::channel(4096); - let (x11_events_sender, x11_events_receiver) = tokio::sync::mpsc::channel(4096); + let (x11_events_sender, mut x11_events_receiver) = tokio::sync::mpsc::channel(4096); - spawn_local(async move { - vnc.run(vnc_evnets_sender, x11_events_receiver) - .await - .unwrap() - }); let mut canvas = CanvasUtils::new(x11_events_sender.clone()); fn hande_vnc_event(event: VncEvent, canvas: &mut CanvasUtils) { @@ -108,18 +103,38 @@ fn run() -> Result<(), JsValue> { VncEvent::Text(string) => { setClipBoard(string); } + VncEvent::Error(msg) => { + error!(msg); + alert(&msg); + panic!() + } _ => unreachable!(), } } - while let Some(event) = vnc_events_receiver.recv().await { - hande_vnc_event(event, &mut canvas); - while let Ok(e) = vnc_events_receiver.try_recv() { - hande_vnc_event(e, &mut canvas); + spawn_local(async move { + let mut interval = + fluvio_wasm_timer::Interval::new(std::time::Duration::from_millis(1)); + loop { + match vnc.poll_event().await { + Ok(Some(e)) => hande_vnc_event(e, &mut canvas), + Ok(None) => { + let _ = interval.next().await; + let _ = vnc.input(X11Event::Refresh).await; + } + Err(e) => { + alert(&e.to_string()); + break; + } + } + + while let Ok(x11event) = x11_events_receiver.try_recv() { + let _ = vnc.input(x11event).await; + } } - let _ = x11_events_sender.send(X11Event::Refresh).await; - } - canvas.close(); + canvas.close(); + let _ = vnc.close().await; + }) }); Ok(()) diff --git a/webvnc/src/x11cursor.rs b/webvnc/src/x11cursor.rs index c744c5e..adf593e 100644 --- a/webvnc/src/x11cursor.rs +++ b/webvnc/src/x11cursor.rs @@ -1,5 +1,3 @@ - - pub struct MouseUtils; impl MouseUtils {