Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Screenshot Feature #24

Closed
candiedoperation opened this issue Feb 23, 2022 · 2 comments
Closed

Screenshot Feature #24

candiedoperation opened this issue Feb 23, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@candiedoperation
Copy link

candiedoperation commented Feb 23, 2022

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

@roerohan
Copy link
Owner

roerohan commented Feb 26, 2022

Hello @candiedoperation

The canvas element is inserted by the RFB object in the noVNC library itself, I do not create a canvas on my own. Here's what I do:

<div
style={style}
className={className}
ref={screen}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
/>

And then, the screen reference is passed to the RFB constructor:

const _rfb = new RFB(screen.current, url);

Now, there are 2 ways to resolve your issue:

  1. I could accept a canvasId prop, and set:
_rfb._canvas.id = canvasId;
  1. You could use the rfb object that's exposed with the onConnect method:
function App() {
  const vncRfb = useRef(null);
  const vncScreenRef = useRef<React.ElementRef<typeof VncScreen>>(null);

  useEffect(() => {
    // Assuming that `canvasId` is defined
    vncRfb.current?._canvas?.id = canvasId;
  }, [vncRfb.current]);

  return (
    <VncScreen
      url={vncUrl}
      scaleViewport
      debug
      ref={vncScreenRef}
      onConnect={(rfb) => {
        console.log('connected', rfb);
        vncRfb.current = rfb;
      }}
    />
  )
}

I think you could use the second approach here, I'm not really in favor of adding a canvasId prop in the library - unless you can tell me if there are any issues with this approach, or if assigning it in the library is better in any way.

@roerohan roerohan added the question Further information is requested label Feb 26, 2022
@roerohan roerohan added the enhancement New feature or request label Feb 26, 2022
@roerohan
Copy link
Owner

In #26, I've exposed the rfb object. So, if you have a code snippet like:

function App() {
  const vncScreenRef = useRef<React.ElementRef<typeof VncScreen>>(null);

  return (
    <VncScreen
      url={vncUrl}
      scaleViewport
      debug
      ref={vncScreenRef}
    />
  )
}

You can access the rfb object using vncScreenRef.current?.rfb. If the rfb object isn't set, it's value is null.

@roerohan roerohan self-assigned this Feb 26, 2022
Repository owner locked and limited conversation to collaborators Feb 27, 2022
@roerohan roerohan converted this issue into discussion #30 Feb 27, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants