update vnc library

This commit is contained in:
Jovi Hsu 2023-03-17 05:15:19 +00:00
parent d36274cd33
commit 5d8ff7f22d
4 changed files with 84 additions and 28 deletions

View File

@ -1,34 +1,77 @@
[tasks.install-debug] [tasks.install-debug]
dependencies = ["websockify", "wasm-debug"] dependencies = ["websockify", "rdp-debug", "vnc-debug", "ssh-debug"]
[tasks.install-release] [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 = ''' script = '''
cd ${VNC} && cargo make install-debug && cd .. 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 .. cd ${SSH} && cargo make install-debug && cd ..
''' '''
[tasks.wasm-release] [tasks.rdp-release]
dependencies = ["install-dir"]
script = ''' script = '''
cd ${VNC} && cargo make install-release && cd ..
cd ${RDP} && 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] [tasks.websockify]
dependencies = ["install-dir"] dependencies = ["install-dir"]
script = ''' 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] [tasks.install-dir]
script = ''' script = '''
mkdir -p $INSTALL_PATH mkdir -p ${INSTALL_PATH}
cp assets/* $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] [env]

View File

@ -13,7 +13,7 @@ default = ["console_error_panic_hook"]
[dependencies] [dependencies]
wasm-bindgen = "0.2.63" wasm-bindgen = "0.2.63"
js-sys = "0.3" js-sys = "0.3"
vnc-rs = "^0.3" vnc-rs = "^0.4"
fluvio-wasm-timer = "0.2.5" fluvio-wasm-timer = "0.2.5"
# websocket # websocket

View File

@ -5,7 +5,8 @@ mod x11keyboard;
use ::vnc::{client::connector::VncConnector, PixelFormat, VncEncoding, VncEvent, X11Event}; use ::vnc::{client::connector::VncConnector, PixelFormat, VncEncoding, VncEvent, X11Event};
use canvas::CanvasUtils; use canvas::CanvasUtils;
use tracing::info; use futures::StreamExt;
use tracing::{error, info};
use tracing_wasm::WASMLayerConfigBuilder; use tracing_wasm::WASMLayerConfigBuilder;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
use wasm_bindgen_futures::spawn_local; use wasm_bindgen_futures::spawn_local;
@ -71,14 +72,8 @@ fn run() -> Result<(), JsValue> {
let vnc = vnc.unwrap().finish().unwrap(); let vnc = vnc.unwrap().finish().unwrap();
let (vnc_evnets_sender, mut vnc_events_receiver) = tokio::sync::mpsc::channel(4096); let (x11_events_sender, mut x11_events_receiver) = tokio::sync::mpsc::channel(4096);
let (x11_events_sender, 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()); let mut canvas = CanvasUtils::new(x11_events_sender.clone());
fn hande_vnc_event(event: VncEvent, canvas: &mut CanvasUtils) { fn hande_vnc_event(event: VncEvent, canvas: &mut CanvasUtils) {
@ -108,18 +103,38 @@ fn run() -> Result<(), JsValue> {
VncEvent::Text(string) => { VncEvent::Text(string) => {
setClipBoard(string); setClipBoard(string);
} }
VncEvent::Error(msg) => {
error!(msg);
alert(&msg);
panic!()
}
_ => unreachable!(), _ => unreachable!(),
} }
} }
while let Some(event) = vnc_events_receiver.recv().await { spawn_local(async move {
hande_vnc_event(event, &mut canvas); let mut interval =
while let Ok(e) = vnc_events_receiver.try_recv() { fluvio_wasm_timer::Interval::new(std::time::Duration::from_millis(1));
hande_vnc_event(e, &mut canvas); 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(()) Ok(())

View File

@ -1,5 +1,3 @@
pub struct MouseUtils; pub struct MouseUtils;
impl MouseUtils { impl MouseUtils {