Giter Site home page Giter Site logo

roerohan / react-vnc Goto Github PK

View Code? Open in Web Editor NEW
70.0 2.0 20.0 2.28 MB

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

Home Page: https://roerohan.github.io/react-vnc/

License: MIT License

HTML 22.96% CSS 4.16% TypeScript 65.53% JavaScript 6.33% Shell 1.01%
javascript react typescript npm-package hacktoberfest

react-vnc's Introduction

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 [email protected]:roerohan/react-vnc.git
cd react-vnc
  1. Install the packages and submodules.
npm install
git submodule update --init --recursive
  1. To run the sample react-vnc web application:
echo "REACT_APP_VNC_URL=ws://your-vnc-url.com" > .env
npm start
  1. 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.

interface Props {
  url: string;
  style?: object;
  className?: string;
  viewOnly?: boolean;
  rfbOptions?: Partial<RFBOptions>;
  focusOnClick?: boolean;
  clipViewport?: boolean;
  dragViewport?: boolean;
  scaleViewport?: boolean;
  resizeSession?: boolean;
  showDotCursor?: boolean;
  background?: string;
  qualityLevel?: number;
  compressionLevel?: number;
  autoConnect?: number; // defaults to true
  retryDuration?: number; // in milliseconds
  debug?: boolean; // show logs in the console
  loadingUI?: React.ReactNode; // custom component that is displayed when loading
  onConnect?: (rfb?: RFB) => void;
  onDisconnect?: (rfb?: RFB) => void;
  onCredentialsRequired?: (rfb?: RFB) => void;
  onSecurityFailure?: (e?: { detail: { status: number, reason: string } }) => void;
  onClipboard?: (e?: { detail: { text: string } }) => void;
  onBell?: () => void;
  onDesktopName?: (e?: { detail: { name: string } }) => void;
  onCapabilities?: (e?: { detail: { capabilities: RFB["capabilities"] } }) => void;
}

// The rfbOptions object in Props is of type Partial<RFBOptions>
interface RFBOptions {
    shared: boolean;
    credentials: {
        username?: string;
        password?: string;
        target?: string;
    };
    repeaterID: string;
    wsProtocols: string | string[];
}

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 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 😄.

License

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

react-vnc's People

Contributors

github-actions[bot] avatar roerohan avatar semantic-release-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-vnc's Issues

With scaleviewport set to true, vnc screen (sometimes) becomes empty, and needs window scale change to be visible

Are you certain it's a bug?

  • Yes, it looks like a bug

Are you sure this is not an issue in noVNC?

  • It is not a noVNC issue

Is there an existing issue for this?

  • I have searched existing issues, it hasn't been reported yet

Issue description

I ran into this issue, while I was developing an application that contains tabs. The vnc_screen works fine, so as the scaleviewport option. However when I changed tabs and then went back, the vnc_screen was nowhere. When I opened the devtools it reappeared.

After this I realized that setting scaleviewport attribute, it sometimes works like this. Other times it's completely normal.
If the screen resolution somehow changes, for example putting the app in fullscreen mode, the vnc screen reappears.

Can I work around this?

Dynamically setting the size of the vnc_screen does not seem to solve the problem

bug: typescript should be a dev dependency

"typescript": "^4.2.4",

Since typescript is a dependency, any project using a different version of typescript will fail to run npm install react-vnc and throw an error like the following:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: [email protected]
npm ERR! node_modules/typescript
npm ERR!   typescript@"^4.0.3" from the root project
npm ERR!   typescript@"^4.2.4" from [email protected]
npm ERR!   node_modules/react-vnc
npm ERR!     react-vnc@"0.2.5" from the root project

Screenshot Feature

@roerohan, Assigning an ID (taking it from the props) for the canvas helps capture a screen shot by using the canvas.toDataURL(type, encoderOptions); browser API

This would be a really useful feature.

How to disconnect a session ?

Hi,
How can i disconnect a session from a noVNC client ?
I noticed when i'm not disconnecting and move to other page in my application and then trying to reconnect again its getting stuck cause the session is still there.

How to make Changes to React Component

How do I make changes to the React Component for my project needs?

I cloned the repository, installed packages and submodules, then copied over the React Component from lib folder, and all the files in the noVNC folder to my project. However that doesn't work. Running it gives errors.

can not change clipViewport and dragViewport state

hello , I noticed a button in pure no-vnc sdk which could change the state of clipViewport and dragViewport (true <=> false)

I implemented same strategy to get the same result but changing the state of these props does not change the behavior of vnc screen,
I faced this issue since the height of vnc screen is always more than the device and some time there is a need to drag the view to see the bottom of screen but when the clipViewport and dragViewport is true scrolling with touch events in mobile devices does not scroll the content of shared application

Accept rawChannel or url for VncScreen component

Is there an existing issue for this?

  • I have searched existing issues, it hasn't been reported yet

Use case description

Basically we have our own required implementation of creating a ws connection. We are not relying on third-part libraries to do it for us. It covers for us security and auth etc.
noVnc package has support for accepting either url or already created ws channel to work with.

export default class RFB extends EventTargetMixin {
    constructor(target, urlOrChannel, options)     

So i am offering to accept not only url as string but alrerady created data channel and pass it to a rfb constructor.
Wath do you think ?

Thank you!

Proposed solution (optional)

No response

Pass multiple protocols in rfbOptions.wsProtocols

Is there an existing issue for this?

  • I have searched existing issues, it hasn't been reported yet

Use case description

If I have multiple protocols to pass its not working out with wsProtocols: string. On noVnc they are accepting array for wsProtocols. this._wsProtocols = options.wsProtocols || [];
https://github.com/novnc/noVNC/blob/295004cabe262367a4df32257d8eb8517bfc4ae1/core/rfb.js#L119

Proposed solution (optional)

Therefore I'm proposing to add wsOptions: string | string[] type in RFBOptions

Rebooting or Shutting Down Host

I do have a brief idea of implementing the disconnect method by forwardRef() but I do not find a way to implement the RFB.machineReboot() or RFB.machineShutdown() functions listed in the noVNC API.md

image

Fix failing `npm test` command, add CI action to run tests

Currently, the entire semantic release process has been set up. However, an essential check missing in merging PRs is to see if automated tests run properly.

At the moment, the automated tests are for the default react page. This must be modified, and action should be added to run the npm test command.

Make it compatible with TS 5

Is there an existing issue for this?

  • I have searched existing issues, it hasn't been reported yet

Use case description

Newer projects are mostly created with TS 5 it will be nice to have support for it, without forcing peer installations

Proposed solution (optional)

No response

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.