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

Rebooting or Shutting Down Host #25

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

Rebooting or Shutting Down Host #25

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

Comments

@candiedoperation
Copy link

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

@roerohan
Copy link
Owner

roerohan commented Feb 26, 2022

Hey @candiedoperation

Currently, there are no methods in react-vnc which implement RFB.machineReboot() or RFB.machineShutdown(). However, the rfb object from noVNC is exposed when the 'connect' event is fired. So, you can do something like:

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

You can use a ref to set the RFB object to your component scope.

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

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

You can use this rfb object to run any method that is described in the noVNC API.

@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
@roerohan
Copy link
Owner

roerohan commented Feb 27, 2022

In #28 , I've also added support for the following methods from RFB

sendCredentials,
sendKey,
sendCtrlAltDel,
focus,
blur,
machineShutdown,
machineReboot,
machineReset,
clipboardPaste

So, you could just do vncScreenRef.current?.machineShutdown() from the above example.

Repository owner locked and limited conversation to collaborators Feb 27, 2022
@roerohan roerohan converted this issue into discussion #29 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