Attempt to fix connection

This commit is contained in:
Pierre HUBERT 2023-10-18 18:13:10 +02:00
parent b87306f8ea
commit 197fbcf259

View File

@ -29,12 +29,16 @@ function VNCInner(p: { vm: VMInfo }): React.ReactElement {
const snackbar = useSnackbar(); const snackbar = useSnackbar();
const [url, setURL] = React.useState<string | undefined>(); const [url, setURL] = React.useState<string | undefined>();
const urlRef = React.useRef<string | undefined>();
const load = async () => { const load = async () => {
try { try {
const u = await VMApi.OneShotVNCURL(p.vm); const u = await VMApi.OneShotVNCURL(p.vm);
console.info(u); console.info(u);
if (urlRef.current === undefined) {
urlRef.current = u;
setURL(u); setURL(u);
}
} catch (e) { } catch (e) {
console.error(e); console.error(e);
snackbar("Failed to initialize VNC connection!"); snackbar("Failed to initialize VNC connection!");
@ -42,14 +46,10 @@ function VNCInner(p: { vm: VMInfo }): React.ReactElement {
}; };
React.useEffect(() => { React.useEffect(() => {
if (url !== undefined) {
return;
}
load(); load();
}); });
if (url === undefined) if (urlRef.current === undefined)
return ( return (
<div <div
style={{ style={{
@ -63,5 +63,24 @@ function VNCInner(p: { vm: VMInfo }): React.ReactElement {
</div> </div>
); );
return <VncScreen url={url} />; return (
<div
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
height: "100%",
}}
>
<VncScreen
url={urlRef.current}
onDisconnect={() => {
console.info("VNC disconnected " + urlRef.current);
urlRef.current = undefined;
load();
setURL(undefined);
}}
/>
</div>
);
} }