fix(striker-ui): display error specifics in VNC connection

main^2
Tsu-ba-me 7 months ago
parent 76219f135d
commit a477cc54f7
  1. 63
      striker-ui/components/Display/FullSize.tsx
  2. 5
      striker-ui/types/APIError.d.ts

@ -15,7 +15,8 @@ import MenuItem from '../MenuItem';
import { Panel, PanelHeader } from '../Panels'; import { Panel, PanelHeader } from '../Panels';
import ServerMenu from '../ServerMenu'; import ServerMenu from '../ServerMenu';
import Spinner from '../Spinner'; import Spinner from '../Spinner';
import { HeaderText } from '../Text'; import { BodyText, HeaderText } from '../Text';
import useCookieJar from '../../hooks/useCookieJar';
import useIsFirstRender from '../../hooks/useIsFirstRender'; import useIsFirstRender from '../../hooks/useIsFirstRender';
const PREFIX = 'FullSize'; const PREFIX = 'FullSize';
@ -43,7 +44,7 @@ const StyledDiv = styled('div')(() => ({
const VncDisplay = dynamic(() => import('./VncDisplay'), { ssr: false }); const VncDisplay = dynamic(() => import('./VncDisplay'), { ssr: false });
// Unit: seconds // Unit: seconds
const DEFAULT_VNC_RECONNECT_TIMER_START = 5; const DEFAULT_VNC_RECONNECT_TIMER_START = 10;
const buildServerVncUrl = (host: string, serverUuid: string) => const buildServerVncUrl = (host: string, serverUuid: string) =>
`ws://${host}/ws/server/vnc/${serverUuid}`; `ws://${host}/ws/server/vnc/${serverUuid}`;
@ -54,6 +55,7 @@ const FullSize: FC<FullSizeProps> = ({
serverName, serverName,
vncReconnectTimerStart = DEFAULT_VNC_RECONNECT_TIMER_START, vncReconnectTimerStart = DEFAULT_VNC_RECONNECT_TIMER_START,
}): JSX.Element => { }): JSX.Element => {
const { buildCookieJar } = useCookieJar();
const isFirstRender = useIsFirstRender(); const isFirstRender = useIsFirstRender();
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null); const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null);
@ -62,6 +64,12 @@ const FullSize: FC<FullSizeProps> = ({
>(undefined); >(undefined);
const [vncConnecting, setVncConnecting] = useState<boolean>(false); const [vncConnecting, setVncConnecting] = useState<boolean>(false);
const [vncError, setVncError] = useState<boolean>(false); const [vncError, setVncError] = useState<boolean>(false);
const [vncClientErrorMessage, setVncClientErrorMessage] = useState<
string | undefined
>();
const [vncApiErrorMessage, setVncApiErrorMessage] = useState<
string | undefined
>();
const [vncReconnectTimer, setVncReconnectTimer] = useState<number>( const [vncReconnectTimer, setVncReconnectTimer] = useState<number>(
vncReconnectTimerStart, vncReconnectTimerStart,
); );
@ -138,17 +146,47 @@ const FullSize: FC<FullSizeProps> = ({
// 'disconnect' event emits when a connection fails, // 'disconnect' event emits when a connection fails,
// OR when a user closes the existing connection. // OR when a user closes the existing connection.
const rfbDisconnectEventHandler = useCallback( const rfbDisconnectEventHandler = useCallback(
({ detail: { clean } }) => { (event) => {
if (!clean) { const { detail } = event;
const { clean } = detail;
if (clean) return;
setVncConnecting(false); setVncConnecting(false);
setVncError(true); setVncError(true);
updateVncReconnectTimer(); updateVncReconnectTimer();
}
}, },
[updateVncReconnectTimer], [updateVncReconnectTimer],
); );
const wsCloseEventHandler = useCallback(
(event?: WebsockCloseEvent): void => {
if (!event) return;
const { code: wscode, reason } = event;
let clientmsg = `ws: ${wscode}`;
if (reason) {
clientmsg += `, ${reason}`;
}
setVncClientErrorMessage(clientmsg);
const vncerror = buildCookieJar()[
`suiapi.vncerror.${serverUUID}`
] as APIError;
if (!vncerror) return;
const { code: apicode, message } = vncerror;
setVncApiErrorMessage(`api: ${apicode}, ${message}`);
},
[buildCookieJar, serverUUID],
);
const showScreen = useMemo( const showScreen = useMemo(
() => !vncConnecting && !vncError, () => !vncConnecting && !vncError,
[vncConnecting, vncError], [vncConnecting, vncError],
@ -281,27 +319,26 @@ const FullSize: FC<FullSizeProps> = ({
<VncDisplay <VncDisplay
onConnect={rfbConnectEventHandler} onConnect={rfbConnectEventHandler}
onDisconnect={rfbDisconnectEventHandler} onDisconnect={rfbDisconnectEventHandler}
onWsClose={wsCloseEventHandler}
rfb={rfb} rfb={rfb}
rfbConnectArgs={rfbConnectArgs} rfbConnectArgs={rfbConnectArgs}
rfbScreen={rfbScreen} rfbScreen={rfbScreen}
/> />
</Box> </Box>
{!showScreen && ( {!showScreen && (
<Box display="flex" className={classes.spinnerBox}> <Box display="flex" className={classes.spinnerBox} textAlign="center">
{vncConnecting && ( {vncConnecting && (
<> <>
<HeaderText textAlign="center"> <HeaderText>Connecting to {serverName}.</HeaderText>
Connecting to {serverName}.
</HeaderText>
<Spinner /> <Spinner />
</> </>
)} )}
{vncError && ( {vncError && (
<> <>
<HeaderText textAlign="center"> <HeaderText>Can&apos;t connect to the server.</HeaderText>
There was a problem connecting to the server. <BodyText>{vncApiErrorMessage}</BodyText>
</HeaderText> <BodyText>{vncClientErrorMessage}</BodyText>
<HeaderText textAlign="center" mt="1em"> <HeaderText mt=".5em">
Retrying in {vncReconnectTimer}. Retrying in {vncReconnectTimer}.
</HeaderText> </HeaderText>
</> </>

@ -0,0 +1,5 @@
type APIError = {
code: string;
message: string;
name: string;
};
Loading…
Cancel
Save