import { useEffect , useState , useMemo } from 'react' ; import { useParams } from 'react-router' ; import useAttempt from 'shared/hooks/useAttemptNext' ; import { UrlDesktopParams } from 'teleport/config' ; import Ctx from 'teleport/teleportContext' ; import useTdpClientCanvas from './useTdpClientCanvas' ; export default function useDesktopSession ( ctx ) { const { attempt : fetchAttempt , run } = useAttempt ( 'processing' ) ; const { attempt : tdpConnection , setAttempt : setTdpConnection } = useAttempt ( 'processing' ) ; const [ wsConnection , setWsConnection ] = useState < 'open' | 'closed' > ( 'closed' ) ; const [ disconnected , setDisconnected ] = useState ( false ) ; const { username , desktopName , clusterId } = useParams < UrlDesktopParams > ( ) ; const [ hostname , setHostname ] = useState < string > ( '' ) ; const clientCanvasProps = useTdpClientCanvas ( { username , desktopName , clusterId , setTdpConnection , setWsConnection , } ) ; document . title = useMemo ( ( ) => `${ clusterId } • ${ username }@${ hostname }` , [ hostname ] ) ; useEffect ( ( ) => { run ( ( ) => ctx . desktopService . fetchDesktop ( clusterId , desktopName ) . then ( desktop => setHostname ( desktop . addr ) ) ) ; } , [ clusterId , desktopName ] ) ; return { hostname , username , clipboard : false , recording : false , fetchAttempt , tdpConnection , wsConnection , disconnected , setDisconnected , ... clientCanvasProps , } ; } export type State = ReturnType < typeof useDesktopSession > ;