Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-vnc

roerohan41.6k3.1.0TypeScript support: included

A React Component to connect to a websockified VNC client using noVNC.

vnc, noVNC, react-vnc, websocket, websockify

readme

Issues


react-vnc

A React Component to connect to a websockified VNC client using noVNC.
Explore the docs »

View Demo · Report Bug · Request Feature

Table of Contents

About The Project

noVNC is a VNC client web application using which you can view a VNC stream directly on a browser. It uses websockify to convert the VNC stream into a websocket stream, which can be viewed on a browser. This library provides a React component wrapper around the noVNC web client.

Using this library, you can easily display a VNC stream on a page of your web application. Here is an example.

Demo

A demo website using the react-vnc library is hosted on https://roerohan.github.io/react-vnc/. The source for this application can be found in src/App.tsx.

demo

Built With

Getting Started

Installation

To install the library, you can run the following command:

npm i react-vnc

Contribution

In order to run the project locally, follow these steps:

  1. Clone the repository.

    git clone git@github.com:roerohan/react-vnc.git
    cd react-vnc
  2. Install the packages and submodules.

    npm install
    git submodule update --init --recursive
  3. To run the sample react-vnc web application:

    echo "REACT_APP_VNC_URL=ws://your-vnc-url.com" > .env
    npm start
  4. To build the library, make changes inside the lib folder, then run:

    npm run build:lib

Usage

A VncScreen component is exposed from the library, to which you can pass the required and optional props. For example,

import React, { useRef } from 'react';
import { VncScreen } from 'react-vnc';

function App() {
  const ref = useRef();

  return (
    <VncScreen
      url='ws://your-vnc-url.com'
      scaleViewport
      background="#000000"
      style={{
        width: '75vw',
        height: '75vh',
      }}
      ref={ref}
    />
  );
}

export default App;

The only required parameter is url, which must be a ws:// or a wss:// (websocket) URL for the library to function properly. noVNC can display only websocket URLs. All other props to VncScreen are optional. The following is a list (an interface) of all props along with their types.

type EventListeners = { [T in NoVncEventType]?: (event: NoVncEvents[T]) => void };

interface Props {
    url: string;
    style?: object;
    className?: string;
    viewOnly?: boolean;
    rfbOptions?: Partial<NoVncOptions>;
    focusOnClick?: boolean;
    clipViewport?: boolean;
    dragViewport?: boolean;
    scaleViewport?: boolean;
    resizeSession?: boolean;
    showDotCursor?: boolean;
    background?: string;
    qualityLevel?: number;
    compressionLevel?: number;
    autoConnect?: boolean;
    retryDuration?: number;
    debug?: boolean;
    onConnect?: EventListeners['connect'];
    onDisconnect?: EventListeners['disconnect'];
    onCredentialsRequired?: EventListeners['credentialsrequired'];
    onSecurityFailure?: EventListeners['securityfailure'];
    onClipboard?: EventListeners['clipboard'];
    onBell?: EventListeners['bell'];
    onDesktopName?: EventListeners['desktopname'];
    onCapabilities?: EventListeners['capabilities'];
    onClippingViewport?: EventListeners['clippingviewport'];
}

// The types NoVncOptions, NoVncEventType and NoVncEvents are from the
// @novnc/novnc library.

To know more about these props, check out API.md.

You can pass a ref to the VncScreen component, and access the connect() and disconnect() methods from the library. Check out #18 for more details.

The ref object has the following type:

type VncScreenHandle = {
    connect: () => void;
    disconnect: () => void;
    connected: boolean;
    sendCredentials: (credentials: NoVncOptions["credentials"]) => void;
    sendKey: (keysym: number, code: string, down?: boolean) => void;
    sendCtrlAltDel: () => void;
    focus: () => void;
    blur: () => void;
    machineShutdown: () => void;
    machineReboot: () => void;
    machineReset: () => void;
    clipboardPaste: (text: string) => void;
    rfb: RFB | null;
    loading: boolean;
    eventListeners: EventListeners;
};

The onConnect, onDisconnect, onCredentialsRequired, and onDesktopName props are optional, and there are existing defaults set for them. For example, the default onDisconnect function consists of some logic to retry connecting after a certain timeout (specified by retryDuration). Check out the default _onConnect and _onDisconnect functions in VncScreen.tsx for more details.

The onConnect, onDisconnect, and onCredentialsRequired callbacks can accept a single parameter rfb. This parameter is the RFB object, which is described by noVNC. Learn more about the RFB object here.

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'feat: Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

You are requested to follow the contribution guidelines specified in CONTRIBUTING.md while contributing to the project :smile:.

License

Distributed under the MIT License. See LICENSE for more information.

changelog

3.1.0 (2025-04-24)

Features

  • add new event "onClippingViewport" (5270246)

3.0.8 (2025-03-31)

Bug Fixes

  • remove outer div to give more control over component (e1e134d)

3.0.7 (2025-02-24)

Bug Fixes

  • externalize react/jsx-runtime (f5b1283)

3.0.6 (2025-02-24)

Bug Fixes

3.0.5 (2025-02-24)

Bug Fixes

3.0.4 (2025-02-24)

Bug Fixes

  • remove npmignore to publish only dist (fa9011d)

3.0.3 (2025-02-24)

Bug Fixes

3.0.2 (2025-02-24)

Bug Fixes

  • builds and prepublish script (7e2761e)

3.0.1 (2025-02-24)

Bug Fixes

  • update prepublish to cjs (364bb5f)

3.0.0 (2025-02-24)

  • Merge pull request #63 from roerohan/feat-react-19 (44040fc)

Bug Fixes

  • remove rollup dep (cec8373)
  • update husky config, remove rollup (80a3dae)

Features

  • react-19: added support for react 19 (d716043)

BREAKING CHANGES

  • feat: added support for react 19
  • react-19: this will not work with older versions of react

2.0.3 (2025-02-24)

Bug Fixes

  • submodules: submodules were updated (e4ca572)
  • submodules: submodules were updated (bf50b94)
  • submodules: submodules were updated (8538b5d)
  • submodules: submodules were updated (09ab457)
  • submodules: submodules were updated (9db9c05)
  • submodules: submodules were updated (d50c8c5)
  • submodules: submodules were updated (8527c9f)
  • submodules: submodules were updated (2bf57ea)
  • update dep versions (7235abd)

2.0.2 (2024-07-02)

Bug Fixes

  • add types to exports to avoid typescript error in import (5147009)
  • submodules: submodules were updated (33a7c86)
  • submodules: submodules were updated (0b26f86)

2.0.1 (2024-06-10)

Bug Fixes

  • submodules: submodules were updated (9d33c98)

2.0.0 (2024-06-09)

Bug Fixes

  • submodules: submodules were updated (74804c9)
  • submodules: submodules were updated (e9020fd)
  • submodules: submodules were updated (ec90728)
  • submodules: submodules were updated (808c76c)
  • submodules: submodules were updated (e2fb418)
  • submodules: submodules were updated (c198283)
  • submodules: submodules were updated (4e6ddcf)
  • submodules: submodules were updated (225bd0b)
  • submodules: submodules were updated (7050d70)
  • submodules: submodules were updated (25fbd61)
  • submodules: submodules were updated (70fc377)
  • submodules: submodules were updated (86c63f2)
  • submodules: submodules were updated (7a4b8f5)
  • submodules: submodules were updated (a229dd2)
  • submodules: submodules were updated (7105728)
  • update configuration files (a255ed3)
  • update workflow versions in actions (cf4b243)

Features

  • update all dependencies (1539e24)

BREAKING CHANGES

  • This package will not work for older versions of node
  • Updating all dependencies, added node v20 support

1.0.0 (2023-10-05)

Bug Fixes

BREAKING CHANGES

  • releasing version 1, there are no breaking changes as such. Using the phrase to trigger semantic release to bump the version to v1.

0.5.16 (2023-10-03)

Bug Fixes

  • submodules: submodules were updated (32abf70)

0.5.15 (2023-09-27)

Bug Fixes

  • submodules: submodules were updated (15b955e)
  • submodules: submodules were updated (6638b1f)

0.5.14 (2023-08-01)

Bug Fixes

  • wsProtocols should take string|string[] (#47) (4235cce)

0.5.13 (2023-08-01)

Bug Fixes

  • submodules: submodules were updated (d72ced2)

0.5.12 (2023-07-13)

Bug Fixes

  • submodules: submodules were updated (7bd7dc5)

0.5.11 (2023-06-28)

Bug Fixes

  • submodules: submodules were updated (cecb9d4)

0.5.10 (2023-05-29)

Bug Fixes

  • submodules: submodules were updated (da59e5a)
  • submodules: submodules were updated (2227ff6)

0.5.9 (2023-05-09)

Bug Fixes

  • submodules: submodules were updated (2d60734)
  • submodules: submodules were updated (f8eeee1)
  • submodules: submodules were updated (7630851)
  • submodules: submodules were updated (324c8e6)

0.5.8 (2023-01-30)

Bug Fixes

  • submodules: submodules were updated (edd6c5b)
  • submodules: submodules were updated (62e3e79)

0.5.7 (2023-01-05)

Bug Fixes

  • submodules: submodules were updated (63be97b)
  • submodules: submodules were updated (29b3aeb)
  • submodules: submodules were updated (6974204)
  • submodules: submodules were updated (f129746)
  • submodules: submodules were updated (775a7e3)
  • submodules: submodules were updated (1096aae)
  • submodules: submodules were updated (5a84acf)
  • submodules: submodules were updated (13b710c)
  • submodules: submodules were updated (1d03f66)

0.5.6 (2022-12-12)

Bug Fixes

  • submodules: submodules were updated (dda58b1)

0.5.5 (2022-11-21)

Bug Fixes

  • submodules: submodules were updated (baf8dcf)
  • submodules: submodules were updated (207a519)
  • submodules: submodules were updated (36601ee)
  • submodules: submodules were updated (f9b6e6b)
  • submodules: submodules were updated (9c39b07)
  • submodules: submodules were updated (3172623)
  • submodules: submodules were updated (ba32bb0)
  • submodules: submodules were updated (582e268)
  • submodules: submodules were updated (d65c14f)
  • submodules: submodules were updated (743cab7)
  • submodules: submodules were updated (a72e189)
  • submodules: submodules were updated (1383a14)
  • submodules: submodules were updated (9ebaf64)
  • submodules: submodules were updated (fbca6be)
  • submodules: submodules were updated (1075542)
  • submodules: submodules were updated (fc3e61d)
  • submodules: submodules were updated (1034880)

0.5.4 (2022-09-19)

Bug Fixes

  • submodules: submodules were updated (28c8913)
  • submodules: submodules were updated (95f10f5)
  • submodules: submodules were updated (4acdefd)
  • submodules: submodules were updated (7c974e5)
  • submodules: submodules were updated (20d876a)
  • submodules: submodules were updated (a280eaf)

0.5.3 (2022-08-29)

Bug Fixes

  • create release (2422cad)
  • submodules: submodules were updated (9f2f324)

0.5.2 (2022-07-30)

Bug Fixes

0.5.1 (2022-06-14)

Bug Fixes

  • submodules: submodules were updated (c1224a3)
  • submodules: submodules were updated (e246f56)
  • submodules: submodules were updated (6cae515)
  • submodules: submodules were updated (b24dc21)
  • submodules: submodules were updated (279c166)
  • submodules: submodules were updated (60b01d7)
  • submodules: submodules were updated (32e527d)

0.5.0 (2022-02-27)

Features

  • imperativeHandles: implemented noVNC RFB methods (#28) (1c8c234)

0.4.4 (2022-02-27)

Bug Fixes

  • pr-template: added PR template (4a618fe)

0.4.3 (2022-02-27)

Bug Fixes

  • pr-template: added PR template (11d358f)

0.4.2 (2022-02-27)

Bug Fixes

  • funding: update funding.yml (b4488f8)

0.4.1 (2022-02-26)

Bug Fixes

  • rfb: expose rfb in VncScreen useImperativeHandle (#26) (53af884)

0.4.0 (2022-02-19)

Features

  • loading: added custom component that can be displayed in place of default loading UI (#23) (8005dd2)

0.3.0 (2022-02-19)

Bug Fixes

  • autoConnect: auto connect timeout issues fixed (8678abf)
  • onDesktopName: made params optional (a246aca)
  • rfb: use rfb as a ref so that it can be returned with onConnect (4df7d49)

Features

  • listeners: export onConnect, onDisconnect, etc (15cc8f4)

0.2.10 (2022-02-19)

Bug Fixes

  • prepublish: added module, and exports in prepublish script (#21) (611b86a)

0.2.9 (2022-02-19)

Bug Fixes

  • forwardRef: forward connect(), disconnect() and connected from VncScreen (#20) (9392ab3)

0.2.8 (2022-01-07)

Bug Fixes

  • submodules: submodules were updated (52a9985)
  • submodules: submodules were updated (01afe07)
  • submodules: submodules were updated (b22808a)
  • submodules: submodules were updated (476715e)
  • submodules: submodules were updated (5cfae44)
  • submodules: submodules were updated (6ddbf49)
  • submodules: submodules were updated (4449674)

0.2.7 (2021-11-20)

Bug Fixes

  • submodules: submodules were updated (850ab31)
  • submodules: submodules were updated (ed34335)
  • submodules: submodules were updated (ee24f5e)

0.2.6 (2021-11-08)

Bug Fixes

  • publish: allow publishing through repository dispatch (5dbd528)
  • submodules: submodules were updated (574b631)
  • submodules: submodules were updated (0fc1ee5)

0.2.5 (2021-10-02)

Bug Fixes

  • added npm test action and fixed failing tests (#14) (990eb86)
  • submodules: submodules were updated (ee59941)

0.2.4 (2021-09-26)

Bug Fixes

  • release: do not publish tarball inside the dist folder (#12) (844affd)

0.2.3 (2021-09-26)

Bug Fixes

  • config: added configurable retry duration and logging (#11) (25c2e4e), closes #3

0.2.2 (2021-09-26)

Bug Fixes

  • cron: update cron job to 00:00 everyday (#10) (1fae558)

0.2.1 (2021-09-26)

Bug Fixes

  • add entries to npmignore and update submodule (#8) (4096c1a)

0.2.0 (2021-09-26)

Features

  • release: setup semantic release, husky, and github actions (#7) (5380a75)