@computernewb/nodejs-rfb

中文文档
0.4.5发布于 2026/05/31MITTypeScriptES Module近 30 天下载 3.2万

纯节点VNC(RFC 6143 / RFB 协议)客户端,基于 vnc-rfb-客户端

中文使用文档
文档目录13 节
  1. 贷项
  2. 菲利佩·卡拉萨
  3. ayunami 2000 (英语)
  4. 双色猫
  5. 调制解调器80
  6. 以利亚R2411
  7. 安装
  8. 使用量
  9. 实例
  10. 将框架保存到 jpg
  11. 与 FRAMPEG 进行记录
  12. 方法
  13. 许可证

节点-rfb

纯节点.js 执行 RFC 6143(RFB Protocol / VNC)客户端,没有外部依赖性. 支持 Raw, CopyRect, Hextile 和 ZRLE 编码.

Filipe Calaça的原创作品"克克克"由Computernewb提供 vnc-rfb-客户端 项目主要用于CollabVM项目.

贷项

菲利佩·卡拉萨

  • 原始图书馆

ayunami 2000 (英语)

  • QEMU 音频( PCM)
  • QEMU 相对指针

双色猫

  • 修道- cursor 支持
  • 一般密码库改进

调制解调器80

  • 移植到类型脚本
  • 大量重构和改进

以利亚R2411

  • 安保/核证重构

安装

yarn add @computernewb/nodejs-rfb # Yarn
npm install @computernewb/nodejs-rfb # NPM

使用量

import { VncClient } from '@computernewb/nodejs-rfb';

const initOptions = {
    debug: false, // Set debug logging
    encodings: [ // Encodings sent to server, in order of preference
        VncClient.consts.encodings.copyRect,
        VncClient.consts.encodings.zrle,
        VncClient.consts.encodings.hextile,
        VncClient.consts.encodings.raw,
        VncClient.consts.encodings.pseudoDesktopSize,
    ]
};

const client = new VncClient(initOptions);

const connectionOptions = {
    host: '', // VNC Server
    path: null, // UNIX domain socket
    auth: {
      password: '' // Password
    },
    set8BitColor: false, // If set to true, client will request 8 bit color, only supported with Raw encoding
    port: 5900 // Remote server port
}
client.connect(connectionOptions);

// Client successfully connected
client.on('connected', () => {
    console.log('Client connected.');
});

// Connection timed out
client.on('connectTimeout', () => {
    console.log('Connection timeout.');
});

// Client successfully authenticated
client.on('authenticated', () => {
    console.log('Client authenticated.');
});

// Authentication error
client.on('authError', () => {
    console.log('Client authentication error.');
});

// Bell received from server
client.on('bell', () => {
    console.log('Bell received');
});

// Client disconnected
client.on('disconnect', () => {
    console.log('Client disconnected.');
    process.exit();
});

// Clipboard event on server
client.on('cutText', (text) => {
    console.log('clipboard text received: ' + text);
});

// Frame buffer updated
client.on('firstFrameUpdate', (fb) => {
   console.log('First Framebuffer update received.');
});

// Frame buffer updated
client.on('frameUpdated', (fb) => {
    console.log('Framebuffer updated.');
});

// Color map updated (8 bit color only)
client.on('colorMapUpdated', (colorMap) => {
    console.log('Color map updated. Colors: ' + colorMap.length);
});

// Rect processed
client.on('rectProcessed', (rect) => {
    console.log('rect processed');
});

实例

将框架保存到 jpg

import { VncClient } from '@computernewb/nodejs-rfb';
import { Jimp } from 'jimp';

const client = new VncClient();

// Just 1 update per second
client.changeFps(1);
client.connect({host: '127.0.0.1', port: 5900, path: null, password: 'abc123'});

client.on('frameUpdated', (data) => {
   new Jimp({width: client.clientWidth, height: client.clientHeight, data}, (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.');
});

与 FRAMPEG 进行记录

import { VncClient } from '@computernewb/nodejs-rfb';
import { spawn } from 'child_process';
const fps = 10;

let timerRef;
const client = new VncClient({fps});
let out;

client.connect({host: '127.0.0.1', port: 5900, path: null, 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.fb);
   }, 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();
});

方法

/**
 * Request a frame update to the server
 */
client.requestFrameUpdate(full, increment, x, y, width, height);

/**
 * Change the rate limit of frame buffer requests
 * If set to 0, a new update request will be sent as soon as the last update finish processing
 */
client.changeFps(10);

/**
 * Start the connection with the server
 */
const connectionOptions = {
    host: '', // VNC Server
    path: null, // UNIX domain socket
    auth: {
      password: '' // Password
    }
    set8BitColor: false, // If set to true, client will request 8 bit color, only supported with Raw encoding
    port: 5900 // Remote server port
}
client.connect(connectionOptions);

/**
 * Send a key board event
 * Check https://wiki.linuxquestions.org/wiki/List_of_keysyms for keycodes
 * down = true for keydown and down = false for keyup
 */
client.sendKeyEvent(keysym, down);

/**
 * Send pointer event (mouse or touch)
 * xPosition - X Position of the pointer
 * yPosition - Y Position of the pointer
 * button1 to button 8 - True for down, false for up
 */
client.sendPointerEvent(xPosition, yPosition, button1, button2, button3, button4, button5, button6, button7, button8);

/**
 * Send clipboard event to server
 * text - Text copied to clipboard
 */
client.clientCutText(text);

client.resetState(); // Reset the state of the client, clear the frame buffer and purge all data

许可证

根据麻省理工学院的许可证分发。 见 LICENSE 更多信息.

版本与发布记录

@computernewb/nodejs-rfb 共发布 7 个版本,首次发布于 2024/07/16;过去 12 个月发布了 3 个版本。

版本发布日期距今
0.4.5latest2026/05/315 个月前
0.4.42026/05/305 个月前
0.4.32026/05/305 个月前
0.4.22025/06/061.4 年前
0.4.12025/06/061.4 年前
0.4.02025/06/061.4 年前

关于 @computernewb/nodejs-rfb 的常见问题

@computernewb/nodejs-rfb 是什么?

纯节点VNC(RFC 6143 / RFB 协议)客户端,基于 vnc-rfb-客户端

如何安装 @computernewb/nodejs-rfb?

在项目目录运行 npm install @computernewb/nodejs-rfb,或使用 pnpm add / yarn add / bun add。

@computernewb/nodejs-rfb 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@computernewb/nodejs-rfb 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@computernewb/nodejs-rfb 可以商用吗?

@computernewb/nodejs-rfb 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@computernewb/nodejs-rfb 的下载量有多少?

根据 npm 官方下载统计,@computernewb/nodejs-rfb 在 2026/10/11 – 2026/11/09 这 30 天内被下载 31,704 次,日均约 1,057 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@computernewb/nodejs-rfb 还在维护吗?

最新版本 0.4.5 发布于 2026/05/31(5 个月前);至今共发布 7 个版本,其中过去 12 个月发布了 3 个;首次发布于 2024/07/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。