@ -27,26 +27,39 @@ export function runSSHSession(
term . focus ( )
term . focus ( )
const sshSession = ipn . ssh ( def . hostname , def . username , {
let resizeObserver : ResizeObserver | undefined
writeFn : ( input ) = > term . write ( input ) ,
let handleBeforeUnload : ( ( e : BeforeUnloadEvent ) = > void ) | undefined
setReadFn : ( hook ) = > ( onDataHook = hook ) ,
const sshSession = ipn . ssh ( def . hostname + "2" , def . username , {
writeFn ( input ) {
term . write ( input )
} ,
writeErrorFn ( err ) {
console . error ( err )
term . write ( err )
} ,
setReadFn ( hook ) {
onDataHook = hook
} ,
rows : term.rows ,
rows : term.rows ,
cols : term.cols ,
cols : term.cols ,
onDone : ( ) = > {
onDone () {
resizeObserver . disconnect ( )
resizeObserver ? . disconnect ( )
term . dispose ( )
term . dispose ( )
window . removeEventListener ( "beforeunload" , handleBeforeUnload )
if ( handleBeforeUnload ) {
window . removeEventListener ( "beforeunload" , handleBeforeUnload )
}
onDone ( )
onDone ( )
} ,
} ,
} )
} )
// Make terminal and SSH session track the size of the containing DOM node.
// Make terminal and SSH session track the size of the containing DOM node.
const resizeObserver = new ResizeObserver ( ( ) = > fitAddon . fit ( ) )
resizeObserver = new ResizeObserver ( ( ) = > fitAddon . fit ( ) )
resizeObserver . observe ( termContainerNode )
resizeObserver . observe ( termContainerNode )
term . onResize ( ( { rows , cols } ) = > sshSession . resize ( rows , cols ) )
term . onResize ( ( { rows , cols } ) = > sshSession . resize ( rows , cols ) )
// Close the session if the user closes the window without an explicit
// Close the session if the user closes the window without an explicit
// exit.
// exit.
const handleBeforeUnload = ( ) = > sshSession . close ( )
handleBeforeUnload = ( ) = > sshSession . close ( )
window . addEventListener ( "beforeunload" , handleBeforeUnload )
window . addEventListener ( "beforeunload" , handleBeforeUnload )
}
}