feat: expand frame type to support stdout/stderr chan
This commit is contained in:
parent
7dfcbef774
commit
55eacb59e9
12 changed files with 580 additions and 285 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import type { Writable } from 'node:stream';
|
||||
import { decode, encode } from 'cbor2';
|
||||
import { encode } from 'cborg';
|
||||
import { WSContext } from 'hono/ws';
|
||||
import { ChannelType } from './encoder';
|
||||
|
||||
interface Command {
|
||||
op: string;
|
||||
|
|
@ -25,7 +27,6 @@ export async function dispatchCommand(
|
|||
return new Promise<void>((resolve, reject) => {
|
||||
const encodedCommand = Buffer.concat([encode(command), Buffer.from('\n')]);
|
||||
dispatcher.write(encodedCommand, (err) => {
|
||||
console.log('Command dispatched:', command, err);
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
|
|
@ -34,3 +35,31 @@ export async function dispatchCommand(
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
interface SSHConnectData extends Command {
|
||||
op: 'ssh_conn_successful';
|
||||
payload: {
|
||||
sessionId: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface SSHConnectFailedData extends Command {
|
||||
op: 'ssh_conn_failed';
|
||||
payload: {
|
||||
reason: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface SSHFrameData extends Command {
|
||||
op: 'ssh_frame';
|
||||
payload: {
|
||||
channel: ChannelType;
|
||||
frame: Buffer;
|
||||
};
|
||||
}
|
||||
|
||||
type WebData = SSHConnectData | SSHConnectFailedData | SSHFrameData;
|
||||
|
||||
export function dispatchWeb<T>(dispatcher: WSContext<T>, data: WebData) {
|
||||
return dispatcher.send(encode(data));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue