mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-07 21:19:03 +02:00
Add some connection feedback
This commit is contained in:
@@ -80,6 +80,7 @@ export default function VncClient({
|
|||||||
}, [form, target?.authToken]);
|
}, [form, target?.authToken]);
|
||||||
|
|
||||||
const [connected, setConnected] = useState(false);
|
const [connected, setConnected] = useState(false);
|
||||||
|
const [connecting, setConnecting] = useState(false);
|
||||||
const [connectError, setConnectError] = useState<string | null>(null);
|
const [connectError, setConnectError] = useState<string | null>(null);
|
||||||
const rfbRef = useRef<any>(null);
|
const rfbRef = useRef<any>(null);
|
||||||
const screenRef = useRef<HTMLDivElement>(null);
|
const screenRef = useRef<HTMLDivElement>(null);
|
||||||
@@ -89,6 +90,7 @@ export default function VncClient({
|
|||||||
rfbRef.current.disconnect();
|
rfbRef.current.disconnect();
|
||||||
rfbRef.current = null;
|
rfbRef.current = null;
|
||||||
}
|
}
|
||||||
|
setConnecting(false);
|
||||||
setConnected(false);
|
setConnected(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -97,12 +99,19 @@ export default function VncClient({
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const connect = async (values: VncCredentialsForm) => {
|
const connect = async (values: VncCredentialsForm) => {
|
||||||
|
setConnecting(true);
|
||||||
|
|
||||||
if (!target) {
|
if (!target) {
|
||||||
setConnectError(t("vncNoResourceTarget"));
|
setConnectError(t("vncNoResourceTarget"));
|
||||||
|
setConnecting(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!screenRef.current) return;
|
if (!screenRef.current) {
|
||||||
|
setConnectError(t("sshErrorConnectionClosed"));
|
||||||
|
setConnecting(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
disconnect();
|
disconnect();
|
||||||
|
|
||||||
@@ -116,6 +125,8 @@ export default function VncClient({
|
|||||||
const mod = await import("@novnc/novnc");
|
const mod = await import("@novnc/novnc");
|
||||||
RFB = mod.default ?? mod;
|
RFB = mod.default ?? mod;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
setConnecting(false);
|
||||||
|
setConnectError(t("sshErrorWebSocket"));
|
||||||
toast({
|
toast({
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
title: t("vncFailedToLoadNovnc"),
|
title: t("vncFailedToLoadNovnc"),
|
||||||
@@ -140,7 +151,16 @@ export default function VncClient({
|
|||||||
options.credentials = { password: values.password };
|
options.credentials = { password: values.password };
|
||||||
}
|
}
|
||||||
|
|
||||||
const rfb: any = new RFB(screenRef.current, wsUrl, options);
|
let rfb: any;
|
||||||
|
try {
|
||||||
|
rfb = new RFB(screenRef.current, wsUrl, options);
|
||||||
|
} catch {
|
||||||
|
setConnecting(false);
|
||||||
|
setConnectError(t("sshErrorWebSocket"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let authConfirmed = false;
|
||||||
|
|
||||||
rfb.scaleViewport = true;
|
rfb.scaleViewport = true;
|
||||||
rfb.resizeSession = true;
|
rfb.resizeSession = true;
|
||||||
@@ -151,6 +171,8 @@ export default function VncClient({
|
|||||||
values,
|
values,
|
||||||
target.authToken
|
target.authToken
|
||||||
);
|
);
|
||||||
|
authConfirmed = true;
|
||||||
|
setConnecting(false);
|
||||||
setConnected(true);
|
setConnected(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -158,7 +180,11 @@ export default function VncClient({
|
|||||||
"disconnect",
|
"disconnect",
|
||||||
(e: { detail: { clean: boolean } }) => {
|
(e: { detail: { clean: boolean } }) => {
|
||||||
rfbRef.current = null;
|
rfbRef.current = null;
|
||||||
|
setConnecting(false);
|
||||||
setConnected(false);
|
setConnected(false);
|
||||||
|
if (!authConfirmed && !e.detail.clean) {
|
||||||
|
setConnectError(t("sshErrorConnectionClosed"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -243,7 +269,12 @@ export default function VncClient({
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
<Button type="submit" className="w-full">
|
<Button
|
||||||
|
type="submit"
|
||||||
|
className="w-full"
|
||||||
|
loading={connecting}
|
||||||
|
disabled={connecting}
|
||||||
|
>
|
||||||
{t("browserGatewayConnect")}
|
{t("browserGatewayConnect")}
|
||||||
</Button>
|
</Button>
|
||||||
{connectError && (
|
{connectError && (
|
||||||
|
|||||||
Reference in New Issue
Block a user