commit
722c73f183
@ -162,7 +162,7 @@ fn vnc_out_handler(ws: &WebSocket, vnc: &Vnc) {
|
||||
vnc::VncOutput::Err(err) => {
|
||||
console_log!("Err {}", err);
|
||||
}
|
||||
vnc::VncOutput::WsBuf(buf) => match ws.send_with_u8_array(&buf) {
|
||||
vnc::VncOutput::WsBuf(buf) => match ws.send_with_u8_array(buf) {
|
||||
Ok(_) => {}
|
||||
Err(err) => console_log!("error sending message: {:?}", err),
|
||||
},
|
||||
@ -213,7 +213,7 @@ fn vnc_out_handler(ws: &WebSocket, vnc: &Vnc) {
|
||||
}
|
||||
}
|
||||
vnc::VncOutput::SetCanvas(x, y) => {
|
||||
set_canvas(&vnc, *x, *y);
|
||||
set_canvas(vnc, *x, *y);
|
||||
|
||||
let vnc_cloned = vnc.clone();
|
||||
let ws_cloned = ws.clone();
|
||||
@ -228,8 +228,7 @@ fn vnc_out_handler(ws: &WebSocket, vnc: &Vnc) {
|
||||
|
||||
let handler = Box::new(refresh) as Box<dyn FnMut()>;
|
||||
|
||||
let cb: wasm_bindgen::prelude::Closure<(dyn FnMut() + 'static)> =
|
||||
Closure::wrap(handler);
|
||||
let cb = Closure::wrap(handler);
|
||||
|
||||
setInterval(&cb, 20);
|
||||
cb.forget();
|
||||
@ -269,7 +268,6 @@ fn start_websocket() -> Result<(), JsValue> {
|
||||
|
||||
let vnc = Vnc::new();
|
||||
|
||||
let cloned_vnc = vnc.clone();
|
||||
// on message
|
||||
let cloned_ws = ws.clone();
|
||||
|
||||
@ -277,8 +275,8 @@ fn start_websocket() -> Result<(), JsValue> {
|
||||
if let Ok(abuf) = e.data().dyn_into::<js_sys::ArrayBuffer>() {
|
||||
let array = js_sys::Uint8Array::new(&abuf);
|
||||
// let mut canvas_ctx = None;
|
||||
cloned_vnc.do_input(array.to_vec());
|
||||
vnc_out_handler(&cloned_ws, &cloned_vnc);
|
||||
vnc.do_input(array.to_vec());
|
||||
vnc_out_handler(&cloned_ws, &vnc);
|
||||
} else {
|
||||
console_log!("message event, received Unknown: {:?}", e.data());
|
||||
}
|
||||
@ -306,5 +304,6 @@ fn start_websocket() -> Result<(), JsValue> {
|
||||
|
||||
#[wasm_bindgen(start)]
|
||||
pub fn run_app() -> Result<(), JsValue> {
|
||||
utils::set_panic_hook();
|
||||
start_websocket()
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
mod des;
|
||||
mod vnc;
|
||||
mod vnc_impl;
|
||||
mod x11cursor;
|
||||
mod x11keyboard;
|
||||
|
||||
@ -11,8 +11,6 @@ pub enum MouseEventType {
|
||||
|
||||
use std::{rc::Rc, sync::Mutex};
|
||||
|
||||
use crate::{console_log, log};
|
||||
|
||||
pub struct CanvasData {
|
||||
pub type_: u32,
|
||||
pub x: u16,
|
||||
@ -32,50 +30,45 @@ pub enum VncOutput {
|
||||
}
|
||||
|
||||
pub struct Vnc {
|
||||
inner: Rc<Mutex<vnc::Vnc>>,
|
||||
inner: Rc<Mutex<vnc_impl::Vnc>>,
|
||||
}
|
||||
|
||||
impl Vnc {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
inner: Rc::new(Mutex::new(vnc::Vnc::new())),
|
||||
inner: Rc::new(Mutex::new(vnc_impl::Vnc::new())),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn do_input(&self, input: Vec<u8>) {
|
||||
self.inner.as_ref().lock().unwrap().do_input(input);
|
||||
self.inner.lock().unwrap().do_input(input);
|
||||
}
|
||||
|
||||
pub fn get_output(&self) -> Vec<VncOutput> {
|
||||
self.inner.as_ref().lock().unwrap().get_output()
|
||||
self.inner.lock().unwrap().get_output()
|
||||
}
|
||||
|
||||
pub fn set_credential(&self, username: &str, password: &str) {
|
||||
self.inner
|
||||
.as_ref()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.set_credential(username, password);
|
||||
}
|
||||
|
||||
pub fn set_clipboard(&self, text: &str) {
|
||||
self.inner.as_ref().lock().unwrap().set_clipboard(text);
|
||||
self.inner.lock().unwrap().set_clipboard(text);
|
||||
}
|
||||
|
||||
pub fn require_frame(&self, incremental: u8) {
|
||||
self.inner
|
||||
.as_ref()
|
||||
.lock()
|
||||
.unwrap()
|
||||
.require_frame(incremental);
|
||||
self.inner.lock().unwrap().require_frame(incremental);
|
||||
}
|
||||
|
||||
pub fn key_press(&self, key: web_sys::KeyboardEvent, down: bool) {
|
||||
self.inner.as_ref().lock().unwrap().key_press(key, down);
|
||||
self.inner.lock().unwrap().key_press(key, down);
|
||||
}
|
||||
|
||||
pub fn mouse_event(&self, mouse: web_sys::MouseEvent, et: MouseEventType) {
|
||||
self.inner.as_ref().lock().unwrap().mouse_event(mouse, et);
|
||||
self.inner.lock().unwrap().mouse_event(mouse, et);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,6 @@ impl Vnc {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn do_input(&mut self, input: Vec<u8>) {
|
||||
// ConsoleService::info(&format!(
|
||||
// "VNC input {}, left {}, require {}",
|
||||
@ -135,9 +134,8 @@ impl Vnc {
|
||||
self.outbuf.clear();
|
||||
}
|
||||
return out;
|
||||
} else {
|
||||
return Vec::new();
|
||||
}
|
||||
};
|
||||
Vec::new()
|
||||
}
|
||||
|
||||
pub fn set_credential(&mut self, _username: &str, password: &str) {
|
||||
@ -544,11 +542,23 @@ impl Vnc {
|
||||
// }
|
||||
// }
|
||||
self.read_exact_vec(&mut image_data, self.require);
|
||||
for y in 0..rect.height {
|
||||
for x in 0..rect.width {
|
||||
let mut y = 0;
|
||||
let mut x = 0;
|
||||
|
||||
// for y in 0..rect.height {
|
||||
// for x in 0..rect.width {
|
||||
// let idx = (y as usize * rect.width as usize + x as usize) * 4;
|
||||
// image_data.swap(idx, idx + 2)
|
||||
// }
|
||||
// }
|
||||
while y < rect.height {
|
||||
while x < rect.width {
|
||||
let idx = (y as usize * rect.width as usize + x as usize) * 4;
|
||||
image_data.swap(idx, idx + 2)
|
||||
image_data.swap(idx, idx + 2);
|
||||
x += 1;
|
||||
}
|
||||
x = 0;
|
||||
y += 1;
|
||||
}
|
||||
}
|
||||
1 => {
|
||||
@ -557,15 +567,14 @@ impl Vnc {
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
self.outs
|
||||
.push(VncOutput::RenderCanvas(CanvasData {
|
||||
type_: rect.encoding_type,
|
||||
x: rect.x,
|
||||
y: rect.y,
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
data: image_data,
|
||||
}));
|
||||
self.outs.push(VncOutput::RenderCanvas(CanvasData {
|
||||
type_: rect.encoding_type,
|
||||
x: rect.x,
|
||||
y: rect.y,
|
||||
width: rect.width,
|
||||
height: rect.height,
|
||||
data: image_data,
|
||||
}));
|
||||
self.num_rect_left -= 1;
|
||||
if 0 == self.num_rect_left {
|
||||
self.msg_handling = ServerMessage::None;
|
||||
@ -708,7 +717,7 @@ impl Vnc {
|
||||
// 1 CARD8 green-shift
|
||||
// 1 CARD8 blue-shift
|
||||
// 1 CARD8 padding
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone, Copy, Default)]
|
||||
struct PixelFormat {
|
||||
// the number of bits used for each pixel value on the wire
|
||||
// 8, 16, 32(usually) only
|
||||
@ -788,26 +797,6 @@ impl From<&[u8; 16]> for PixelFormat {
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for PixelFormat {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
bits_per_pixel: 0,
|
||||
depth: 0,
|
||||
big_endian_flag: 0,
|
||||
true_color_flag: 0,
|
||||
red_max: 0,
|
||||
green_max: 0,
|
||||
blue_max: 0,
|
||||
red_shift: 0,
|
||||
green_shift: 0,
|
||||
blue_shift: 0,
|
||||
padding_1: 0,
|
||||
padding_2: 0,
|
||||
padding_3: 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct VncRect {
|
||||
x: u16,
|
||||
y: u16,
|
Loading…
Reference in New Issue
Block a user