mirror of
https://github.com/antos-rde/antosdk-apps.git
synced 2025-07-13 06:04:26 +02:00
update remoteDesktop
This commit is contained in:
74
libwvnc/build/debug/README.md
Normal file
74
libwvnc/build/debug/README.md
Normal file
@ -0,0 +1,74 @@
|
||||
# libwvnc
|
||||
|
||||
Overview about WVNC: [https://blog.lxsang.me/r/id/23](https://blog.lxsang.me/r/id/23)
|
||||
|
||||
**libwvnc** is the client side protocol API for my [Antd's **wvnc**](https://github.com/lxsang/antd-wvnc-plugin) server side plugin. It allows to acess VNC server from the web using websocket (via the **wvnc** server plugin).
|
||||
|
||||
Since the **wvnc** plugin offers data compression using JPEG, **wvnc.js** depends on the **libjpeg** package and **web worker** to speed up the data decoding process, thus speed up the screen rendering on HTML canvas.
|
||||
|
||||
|
||||
## Example
|
||||
It is straight forward to use the api:
|
||||
|
||||
Html code:
|
||||
|
||||
```html
|
||||
...
|
||||
<canvas id = "screen"></canvas>
|
||||
```
|
||||
|
||||
Javascript:
|
||||
|
||||
```javascript
|
||||
var args, client;
|
||||
args = {
|
||||
// the canvas element
|
||||
element: 'screen',
|
||||
// The websocket uri to the wvnc server side plugin
|
||||
ws: 'wss://localhost/wvnc',
|
||||
// the decoder worker
|
||||
libjpeg: 'path/to/jpg.js'
|
||||
};
|
||||
client = new WVNC(args);
|
||||
|
||||
// This function responds to a VNC server password request
|
||||
// should return a promise
|
||||
client.onpassword = function() {
|
||||
return new Promise(function(r, e) {
|
||||
return r('password');
|
||||
});
|
||||
};
|
||||
|
||||
// this function responds to the remote OS username and password request
|
||||
// should return a promise
|
||||
client.oncredential = function() {
|
||||
return new Promise(function(r, e) {
|
||||
return r('username', 'password');
|
||||
});
|
||||
};
|
||||
// event fired when a text is copied on
|
||||
// the remote computer
|
||||
client.oncopy = function(text) {
|
||||
console.log(text);
|
||||
};
|
||||
// init the WVNC client
|
||||
client.init()
|
||||
.then(function() {
|
||||
client.connect(
|
||||
// VNC server
|
||||
"192.168.1.20:5901",
|
||||
{
|
||||
// bits per pixel
|
||||
bbp: 32,
|
||||
// data compression flag
|
||||
// 1 is for both JPEG
|
||||
// 0 is for raw data
|
||||
flag: 1,
|
||||
// JPEG quality %
|
||||
quality: 50
|
||||
});
|
||||
})
|
||||
.catch(function(m, s) {
|
||||
return console.error(m, s);
|
||||
});
|
||||
```
|
112
libwvnc/build/debug/decoder.js
Normal file
112
libwvnc/build/debug/decoder.js
Normal file
@ -0,0 +1,112 @@
|
||||
let resolution;
|
||||
|
||||
decode_jpeg = (raw, msg) =>
|
||||
{
|
||||
if(!JpegImage)
|
||||
{
|
||||
console.error("The JPEG library is not available");
|
||||
return 0;
|
||||
}
|
||||
let jpeg = new JpegImage()
|
||||
jpeg.parse(raw)
|
||||
if(jpeg.width != msg.w || jpeg.height != msg.h)
|
||||
{
|
||||
console.error("Incorrect data size: expect " + msg.w*msg.h*4 + " got " + jpeg.width*jpeg.height*4);
|
||||
return 0;
|
||||
}
|
||||
msg.pixels = new Uint8Array(msg.w*msg.h*4);
|
||||
let data = jpeg.getData(msg.w, msg.h);
|
||||
for(let j = 0; j < msg.h; j++)
|
||||
{
|
||||
for(let i = 0; i < msg.w; i++)
|
||||
{
|
||||
let index = j*msg.w*4 + i*4;
|
||||
msg.pixels[index] = data[j*msg.w*3 + i*3];
|
||||
msg.pixels[index+1] = data[j*msg.w*3 + i*3 + 1];
|
||||
msg.pixels[index+2] = data[j*msg.w*3 + i*3 + 2];
|
||||
msg.pixels[index+3] = 255;
|
||||
}
|
||||
}
|
||||
return msg.pixels.length;
|
||||
}
|
||||
|
||||
decode_raw = (raw, msg) =>
|
||||
{
|
||||
let size =raw.length;
|
||||
if(resolution.depth == 32)
|
||||
{
|
||||
msg.pixels = new Uint8Array(raw);
|
||||
return size;
|
||||
}
|
||||
if(resolution.depth != 16)
|
||||
{
|
||||
console.error("Unsupported depth" + resolution.depth);
|
||||
return 0;
|
||||
}
|
||||
let bytes = resolution.depth/8;
|
||||
let npixels = size / bytes;
|
||||
let outsize = npixels*4;
|
||||
if(outsize != msg.w*msg.h*4)
|
||||
{
|
||||
console.error("Incorrect data size: expect " + msg.w*msg.h*4 + " got " + outsize);
|
||||
return 0;
|
||||
}
|
||||
msg.pixels = new Uint8Array(outsize);
|
||||
let value = 0;
|
||||
let px = {};
|
||||
for(let i = 0; i < npixels; i++)
|
||||
{
|
||||
value = 0;
|
||||
for(let j=0; j < bytes; j++ )
|
||||
value = (raw[i * bytes + j] << (j*8)) | value ;
|
||||
// lookup for pixel
|
||||
msg.pixels[i*4] = (value & 0x1F) * (255 / 31);
|
||||
msg.pixels[i*4+1] = ((value >> 5) & 0x3F) * (255 / 63);
|
||||
msg.pixels[i*4+2] = ((value >> 11) & 0x1F) * (255 / 31);
|
||||
msg.pixels[i*4+3] = 255;
|
||||
}
|
||||
return outsize;
|
||||
}
|
||||
|
||||
decode = (arr) =>
|
||||
{
|
||||
let datain = new Uint8Array(arr);
|
||||
let msg = {
|
||||
x: datain[1] | (datain[2] << 8),
|
||||
y: datain[3] | (datain[4] << 8),
|
||||
w: datain[5] | (datain[6] << 8),
|
||||
h: datain[7] | (datain[8] << 8),
|
||||
flag: datain[9],
|
||||
pixels: undefined
|
||||
}
|
||||
switch (msg.flag) {
|
||||
case 0x0:
|
||||
decode_raw(datain.subarray(10), msg);
|
||||
break;
|
||||
case 0x1:
|
||||
decode_jpeg(datain.subarray(10), msg);
|
||||
break;
|
||||
default:
|
||||
console.error("Unknow flag: " + msg.flag);
|
||||
}
|
||||
if(msg.pixels)
|
||||
{
|
||||
msg.pixels = msg.pixels.buffer;
|
||||
postMessage(msg, [msg.pixels]);
|
||||
}
|
||||
}
|
||||
|
||||
onmessage = (e) => {
|
||||
if(e.data.depth)
|
||||
{
|
||||
resolution = e.data;
|
||||
}
|
||||
else if(e.data.libjpeg)
|
||||
{
|
||||
importScripts(e.data.libjpeg);
|
||||
}
|
||||
else
|
||||
{
|
||||
decode(e.data);
|
||||
}
|
||||
}
|
1
libwvnc/build/debug/main.js
Normal file
1
libwvnc/build/debug/main.js
Normal file
File diff suppressed because one or more lines are too long
15
libwvnc/build/debug/package.json
Normal file
15
libwvnc/build/debug/package.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"pkgname": "libwvnc",
|
||||
"name":"libwvnc",
|
||||
"description":"libwvnc: client side VNC protocol via websocket",
|
||||
"info":{
|
||||
"author": "",
|
||||
"email": ""
|
||||
},
|
||||
"version":"0.1.2-a",
|
||||
"category":"Library",
|
||||
"iconclass":"fa fa-cog",
|
||||
"mimes":["none"],
|
||||
"dependencies":["libjpeg@0.1.1-a"],
|
||||
"locale": {}
|
||||
}
|
Reference in New Issue
Block a user