|
|
@ -1,25 +1,31 @@ |
|
|
|
import { useState, useRef, useEffect, FC } from 'react'; |
|
|
|
import { |
|
|
|
import dynamic from 'next/dynamic'; |
|
|
|
Close as CloseIcon, |
|
|
|
|
|
|
|
Keyboard as KeyboardIcon, |
|
|
|
|
|
|
|
} from '@mui/icons-material'; |
|
|
|
import { |
|
|
|
import { |
|
|
|
Box, |
|
|
|
Box, |
|
|
|
Button, |
|
|
|
|
|
|
|
IconButton, |
|
|
|
IconButton, |
|
|
|
IconButtonProps, |
|
|
|
IconButtonProps, |
|
|
|
Menu, |
|
|
|
Menu, |
|
|
|
MenuItem, |
|
|
|
MenuItem, |
|
|
|
|
|
|
|
styled, |
|
|
|
Typography, |
|
|
|
Typography, |
|
|
|
} from '@mui/material'; |
|
|
|
} from '@mui/material'; |
|
|
|
import { styled } from '@mui/material/styles'; |
|
|
|
|
|
|
|
import CloseIcon from '@mui/icons-material/Close'; |
|
|
|
|
|
|
|
import KeyboardIcon from '@mui/icons-material/Keyboard'; |
|
|
|
|
|
|
|
import RFB from '@novnc/novnc/core/rfb'; |
|
|
|
import RFB from '@novnc/novnc/core/rfb'; |
|
|
|
import { Panel } from '../Panels'; |
|
|
|
import { useState, useRef, useEffect, FC } from 'react'; |
|
|
|
|
|
|
|
import dynamic from 'next/dynamic'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import API_BASE_URL from '../../lib/consts/API_BASE_URL'; |
|
|
|
import { BLACK, RED, TEXT } from '../../lib/consts/DEFAULT_THEME'; |
|
|
|
import { BLACK, RED, TEXT } from '../../lib/consts/DEFAULT_THEME'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import ContainedButton from '../ContainedButton'; |
|
|
|
|
|
|
|
import { HeaderText } from '../Text'; |
|
|
|
import keyCombinations from './keyCombinations'; |
|
|
|
import keyCombinations from './keyCombinations'; |
|
|
|
|
|
|
|
import { Panel } from '../Panels'; |
|
|
|
import putFetch from '../../lib/fetchers/putFetch'; |
|
|
|
import putFetch from '../../lib/fetchers/putFetch'; |
|
|
|
import putFetchWithTimeout from '../../lib/fetchers/putFetchWithTimeout'; |
|
|
|
import putFetchWithTimeout from '../../lib/fetchers/putFetchWithTimeout'; |
|
|
|
import { HeaderText } from '../Text'; |
|
|
|
|
|
|
|
import Spinner from '../Spinner'; |
|
|
|
import Spinner from '../Spinner'; |
|
|
|
|
|
|
|
import useProtectedState from '../../hooks/useProtectedState'; |
|
|
|
|
|
|
|
|
|
|
|
const PREFIX = 'FullSize'; |
|
|
|
const PREFIX = 'FullSize'; |
|
|
|
|
|
|
|
|
|
|
@ -31,7 +37,6 @@ const classes = { |
|
|
|
closeBox: `${PREFIX}-closeBox`, |
|
|
|
closeBox: `${PREFIX}-closeBox`, |
|
|
|
buttonsBox: `${PREFIX}-buttonsBox`, |
|
|
|
buttonsBox: `${PREFIX}-buttonsBox`, |
|
|
|
keysItem: `${PREFIX}-keysItem`, |
|
|
|
keysItem: `${PREFIX}-keysItem`, |
|
|
|
buttonText: `${PREFIX}-buttonText`, |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const StyledDiv = styled('div')(() => ({ |
|
|
|
const StyledDiv = styled('div')(() => ({ |
|
|
@ -85,12 +90,10 @@ const StyledDiv = styled('div')(() => ({ |
|
|
|
backgroundColor: TEXT, |
|
|
|
backgroundColor: TEXT, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
[`& .${classes.buttonText}`]: { |
|
|
|
|
|
|
|
color: BLACK, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
})); |
|
|
|
})); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const CMD_VNC_PIPE_URL = `${API_BASE_URL}/command/vnc-pipe`; |
|
|
|
|
|
|
|
|
|
|
|
const VncDisplay = dynamic(() => import('./VncDisplay'), { ssr: false }); |
|
|
|
const VncDisplay = dynamic(() => import('./VncDisplay'), { ssr: false }); |
|
|
|
|
|
|
|
|
|
|
|
type FullSizeOptionalProps = { |
|
|
|
type FullSizeOptionalProps = { |
|
|
@ -104,7 +107,7 @@ type FullSizeProps = FullSizeOptionalProps & { |
|
|
|
|
|
|
|
|
|
|
|
type VncConnectionProps = { |
|
|
|
type VncConnectionProps = { |
|
|
|
protocol: string; |
|
|
|
protocol: string; |
|
|
|
forward_port: number; |
|
|
|
forwardPort: number; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const FULL_SIZE_DEFAULT_PROPS: Required< |
|
|
|
const FULL_SIZE_DEFAULT_PROPS: Required< |
|
|
@ -122,43 +125,54 @@ const FullSize: FC<FullSizeProps> = ({ |
|
|
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); |
|
|
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); |
|
|
|
const rfb = useRef<typeof RFB>(); |
|
|
|
const rfb = useRef<typeof RFB>(); |
|
|
|
const hostname = useRef<string | undefined>(undefined); |
|
|
|
const hostname = useRef<string | undefined>(undefined); |
|
|
|
const [vncConnection, setVncConnection] = useState< |
|
|
|
const [vncConnection, setVncConnection] = useProtectedState< |
|
|
|
VncConnectionProps | undefined |
|
|
|
VncConnectionProps | undefined |
|
|
|
>(undefined); |
|
|
|
>(undefined); |
|
|
|
const [isError, setIsError] = useState<boolean>(false); |
|
|
|
const [vncConnecting, setVncConnecting] = useProtectedState<boolean>(false); |
|
|
|
|
|
|
|
const [isError, setIsError] = useProtectedState<boolean>(false); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
if (typeof window !== 'undefined') { |
|
|
|
if (typeof window !== 'undefined') { |
|
|
|
hostname.current = window.location.hostname; |
|
|
|
hostname.current = window.location.hostname; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!vncConnection) |
|
|
|
if (!vncConnection && !vncConnecting) |
|
|
|
(async () => { |
|
|
|
(async () => { |
|
|
|
|
|
|
|
setVncConnecting(true); |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
const res = await putFetchWithTimeout( |
|
|
|
const res = await putFetchWithTimeout( |
|
|
|
`${process.env.NEXT_PUBLIC_API_URL}/manage_vnc_pipes`, |
|
|
|
CMD_VNC_PIPE_URL, |
|
|
|
{ |
|
|
|
{ |
|
|
|
server_uuid: serverUUID, |
|
|
|
serverUuid: serverUUID, |
|
|
|
is_open: true, |
|
|
|
open: true, |
|
|
|
}, |
|
|
|
}, |
|
|
|
120000, |
|
|
|
120000, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
setVncConnection(await res.json()); |
|
|
|
setVncConnection(await res.json()); |
|
|
|
} catch { |
|
|
|
} catch { |
|
|
|
setIsError(true); |
|
|
|
setIsError(true); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
setVncConnecting(false); |
|
|
|
} |
|
|
|
} |
|
|
|
})(); |
|
|
|
})(); |
|
|
|
}, [serverUUID, vncConnection, isError]); |
|
|
|
}, [ |
|
|
|
|
|
|
|
serverUUID, |
|
|
|
|
|
|
|
vncConnection, |
|
|
|
|
|
|
|
isError, |
|
|
|
|
|
|
|
setVncConnection, |
|
|
|
|
|
|
|
setIsError, |
|
|
|
|
|
|
|
vncConnecting, |
|
|
|
|
|
|
|
setVncConnecting, |
|
|
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
const handleClick = (event: React.MouseEvent<HTMLButtonElement>): void => { |
|
|
|
const handleClick = (event: React.MouseEvent<HTMLButtonElement>): void => { |
|
|
|
setAnchorEl(event.currentTarget); |
|
|
|
setAnchorEl(event.currentTarget); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handleClickClose = async () => { |
|
|
|
const handleClickClose = async () => { |
|
|
|
await putFetch(`${process.env.NEXT_PUBLIC_API_URL}/manage_vnc_pipes`, { |
|
|
|
await putFetch(CMD_VNC_PIPE_URL, { serverUuid: serverUUID }); |
|
|
|
server_uuid: serverUUID, |
|
|
|
|
|
|
|
is_open: false, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const handleSendKeys = (scans: string[]) => { |
|
|
|
const handleSendKeys = (scans: string[]) => { |
|
|
@ -189,7 +203,7 @@ const FullSize: FC<FullSizeProps> = ({ |
|
|
|
<Box display="flex" className={classes.displayBox}> |
|
|
|
<Box display="flex" className={classes.displayBox}> |
|
|
|
<VncDisplay |
|
|
|
<VncDisplay |
|
|
|
rfb={rfb} |
|
|
|
rfb={rfb} |
|
|
|
url={`${vncConnection.protocol}://${hostname.current}:${vncConnection.forward_port}`} |
|
|
|
url={`${vncConnection.protocol}://${hostname.current}:${vncConnection.forwardPort}`} |
|
|
|
viewOnly={false} |
|
|
|
viewOnly={false} |
|
|
|
focusOnClick={false} |
|
|
|
focusOnClick={false} |
|
|
|
clipViewport={false} |
|
|
|
clipViewport={false} |
|
|
@ -262,20 +276,13 @@ const FullSize: FC<FullSizeProps> = ({ |
|
|
|
<Box style={{ paddingBottom: '2em' }}> |
|
|
|
<Box style={{ paddingBottom: '2em' }}> |
|
|
|
<HeaderText text="There was a problem connecting to the server, please try again" /> |
|
|
|
<HeaderText text="There was a problem connecting to the server, please try again" /> |
|
|
|
</Box> |
|
|
|
</Box> |
|
|
|
<Button |
|
|
|
<ContainedButton |
|
|
|
variant="contained" |
|
|
|
|
|
|
|
onClick={() => { |
|
|
|
onClick={() => { |
|
|
|
setIsError(false); |
|
|
|
setIsError(false); |
|
|
|
}} |
|
|
|
}} |
|
|
|
style={{ textTransform: 'none' }} |
|
|
|
|
|
|
|
> |
|
|
|
> |
|
|
|
<Typography |
|
|
|
Reconnect |
|
|
|
className={classes.buttonText} |
|
|
|
</ContainedButton> |
|
|
|
variant="subtitle1" |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
Reconnect |
|
|
|
|
|
|
|
</Typography> |
|
|
|
|
|
|
|
</Button> |
|
|
|
|
|
|
|
</> |
|
|
|
</> |
|
|
|
)} |
|
|
|
)} |
|
|
|
</Box> |
|
|
|
</Box> |
|
|
|