![LinkedIn](https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555)
pure-vnc-client
Pure node.js implementation of RFC 6143 (RFB Protocol / VNC) client with no external dependencies. Supports Raw, CopyRect, Hextile and ZRLE encodings.
Report Bug or Request Feature
User Contributions
ayunami2000
- qemu audio (PCM)
- qemu relative pointer
- documentation for these WIP
Getting Started
Requirements
Node.js >= 14
Installation
- Install NPM packages
npm install pure-vnc-client
Usage
const VncClient = require('pure-vnc-client');
const initOptions = {
debug: false,
encodings: [
VncClient.consts.encodings.copyRect,
VncClient.consts.encodings.zrle,
VncClient.consts.encodings.hextile,
VncClient.consts.encodings.raw,
VncClient.consts.encodings.pseudoDesktopSize,
VncClient.consts.encodings.pseudoCursor
],
debugLevel: 1
};
const client = new VncClient(initOptions);
const connectionOptions = {
host: '',
password: '',
set8BitColor: false,
port: 5900
}
client.connect(connectionOptions);
client.on('connected', () => {
console.log('Client connected.');
});
client.on('connectTimeout', () => {
console.log('Connection timeout.');
});
client.on('authenticated', () => {
console.log('Client authenticated.');
});
client.on('authError', () => {
console.log('Client authentication error.');
});
client.on('bell', () => {
console.log('Bell received');
});
client.on('disconnect', () => {
console.log('Client disconnected.');
process.exit();
});
client.on('cutText', (text) => {
console.log('clipboard text received: ' + text);
});
client.on('firstFrameUpdate', (fb) => {
console.log('First Framebuffer update received.');
});
client.on('frameUpdated', (fb) => {
console.log('Framebuffer updated.');
});
client.on('colorMapUpdated', (colorMap) => {
console.log('Color map updated. Colors: ' + colorMap.length);
});
client.on('rectProcessed', (rect) => {
console.log('rect processed');
});
Examples
Save frame to jpg
const VncClient = require('pure-vnc-client');
const Jimp = require('jimp');
const client = new VncClient();
client.changeFps(1);
client.connect({host: '127.0.0.1', port: 5900, password: 'abc123'});
client.on('frameUpdated', (data) => {
new Jimp({width: client.clientWidth, height: client.clientHeight, data: client.getFb()}, (err, image) => {
if (err) {
console.log(err);
}
const fileName = `${Date.now()}.jpg`;
console.log(`Saving frame to file. ${fileName}`);
image.write(`${fileName}`);
});
});
client.on('connectError', (err) => {
console.log(err);
});
client.on('authError', () => {
console.log('Authentication failed.');
});
Record session with FFMPEG
const VncClient = require('pure-vnc-client');
const spawn = require('child_process').spawn;
const fps = 10;
let timerRef;
const client = new VncClient({fps});
let out;
client.connect({host: '127.0.0.1', port: 5900, password: 'abc123'});
client.on('firstFrameUpdate', () => {
console.log('Start recording...');
out = spawn('./ffmpeg.exe',
`-loglevel error -hide_banner -y -f rawvideo -vcodec rawvideo -an -pix_fmt rgba -s ${client.clientWidth}x${client.clientHeight} -r ${fps} -i - -an -r ${fps} -vcodec libx264rgb session.h264`.split(' '));
timer();
});
process.on('SIGINT', function () {
console.log("Exiting.");
close();
});
function timer() {
timerRef = setTimeout(() => {
timer();
out?.stdin?.write(client.getFb());
}, 1000 / fps);
}
function close() {
if (timerRef) {
clearTimeout(timerRef);
}
if (out) {
out.kill('SIGINT');
out.on('exit', () => {
process.exit(0);
});
}
}
client.on('disconnect', () => {
console.log('Client disconnected.');
close();
});
Methods
client.requestFrameUpdate(full, increment, x, y, width, height);
client.changeFps(10);
const connectionOptions = {
host: '',
password: '',
set8BitColor: false,
port: 5900
}
client.connect(connectionOptions);
client.sendKeyEvent(keysym, down);
client.sendPointerEvent(xPosition, yPosition, button1, button2, button3, button4, button5, button6, button7, button8);
client.clientCutText(text);
client.resetState();
client.getFb();
Roadmap
Done
Encodings Supported
Raw
CopyRect
Hextile
ZRLE
PseudoDesktopSize
Pseudo Cursor Encoding
QEMU Audio
QEMU Relative Pointer
3.7 and 3.8 protocol implementations
TODO:
Tight Encoding
Save session data to file
Replay session from rect data saved to file
License
Distributed under the MIT License. See LICENSE
for more information.
Contact
Felipe Polo-Wood
Project Link: https://gitlab.migrandama.com/foss/pure-vnc-client.git