Skip to content

Commit 663b68a

Browse files
committed
exc to disconnect in example client
1 parent 6374f43 commit 663b68a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/examples/client/simpleStreamableHttp.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,11 +405,33 @@ async function cleanup(): Promise<void> {
405405
}
406406
}
407407

408+
409+
process.stdin.setRawMode(false);
408410
readline.close();
409411
console.log('\nGoodbye!');
410412
process.exit(0);
411413
}
412414

415+
// Set up raw mode for keyboard input to capture Escape key
416+
process.stdin.setRawMode(true);
417+
process.stdin.on('data', async (data) => {
418+
// Check for Escape key (27)
419+
if (data.length === 1 && data[0] === 27) {
420+
console.log('\nESC key pressed. Disconnecting from server...');
421+
422+
// Abort current operation and disconnect from server
423+
if (client && transport) {
424+
await disconnect();
425+
console.log('Disconnected. Press Enter to continue.');
426+
} else {
427+
console.log('Not connected to server.');
428+
}
429+
430+
// Re-display the prompt
431+
process.stdout.write('> ');
432+
}
433+
});
434+
413435
// Handle Ctrl+C
414436
process.on('SIGINT', async () => {
415437
console.log('\nReceived SIGINT. Cleaning up...');

0 commit comments

Comments
 (0)