Closed candiedoperation closed 2 years ago
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.
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
.
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.
I do have a brief idea of implementing the disconnect method by
forwardRef()
but I do not find a way to implement theRFB.machineReboot()
orRFB.machineShutdown()
functions listed in the noVNC API.md