File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed
Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 11import { spawn } from '@homebridge/node-pty-prebuilt-multiarch' ;
2+ import chalk from 'chalk' ;
23import { Router } from 'express' ;
34
45import { SocketServer } from '../../socket-server.js' ;
@@ -92,10 +93,17 @@ export function createCommandHandler(command: ConnectCommand): Router {
9293
9394 pty . onExit ( ( { exitCode, signal } ) => {
9495 console . log ( 'pty exit' , exitCode , signal ) ;
96+ ws . send ( Buffer . from ( chalk . blue ( `Session ended exit code ${ exitCode } ` ) , 'utf8' ) )
97+
9598 ws . terminate ( ) ;
9699 server . close ( ) ;
97100 } )
98101
102+ ws . on ( 'close' , ( ) => {
103+ console . log ( 'Session ws closed. Shutting down pty' ) ;
104+ pty . kill ( ) ;
105+ manager . removeSession ( sessionId )
106+ } )
99107
100108 return res . status ( 204 ) . json ( { } ) ;
101109 } ) ;
Original file line number Diff line number Diff line change @@ -56,6 +56,10 @@ export class SocketServer {
5656 )
5757 }
5858
59+ removeSession ( id : string ) {
60+ this . sessions . delete ( id ) ;
61+ }
62+
5963 // Under normal use, there should only be 1 socket (1 connection) per namespace.
6064 getSession ( id : string ) : Session | undefined {
6165 return this . sessions . get ( id ) ;
@@ -124,4 +128,4 @@ export class SocketServer {
124128 } )
125129 }
126130
127- }
131+ }
You can’t perform that action at this time.
0 commit comments