mirror of
https://github.com/tale/headplane.git
synced 2026-08-29 00:17:13 +00:00
feat: add xterm frontend ui
This commit is contained in:
@@ -3,7 +3,7 @@ import { encode } from 'cborg';
|
||||
import { WSContext } from 'hono/ws';
|
||||
import { ChannelType } from './encoder';
|
||||
|
||||
interface Command {
|
||||
export interface Command {
|
||||
op: string;
|
||||
payload: unknown;
|
||||
}
|
||||
@@ -18,7 +18,14 @@ interface SSHConnectCommand extends Command {
|
||||
};
|
||||
}
|
||||
|
||||
type AgentCommand = SSHConnectCommand;
|
||||
interface SSHCloseCommand extends Command {
|
||||
op: 'ssh_term';
|
||||
payload: {
|
||||
sessionId: string;
|
||||
};
|
||||
}
|
||||
|
||||
type AgentCommand = SSHConnectCommand | SSHCloseCommand;
|
||||
|
||||
export async function dispatchCommand(
|
||||
dispatcher: Writable,
|
||||
@@ -36,21 +43,21 @@ export async function dispatchCommand(
|
||||
});
|
||||
}
|
||||
|
||||
interface SSHConnectData extends Command {
|
||||
export interface SSHConnectData extends Command {
|
||||
op: 'ssh_conn_successful';
|
||||
payload: {
|
||||
sessionId: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface SSHConnectFailedData extends Command {
|
||||
export interface SSHConnectFailedData extends Command {
|
||||
op: 'ssh_conn_failed';
|
||||
payload: {
|
||||
reason: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface SSHFrameData extends Command {
|
||||
export interface SSHFrameData extends Command {
|
||||
op: 'ssh_frame';
|
||||
payload: {
|
||||
channel: ChannelType;
|
||||
|
||||
+17
-3
@@ -143,22 +143,36 @@ export class SSHMultiplexer {
|
||||
this.sshInput.write(encodedFrame);
|
||||
},
|
||||
|
||||
onClose: (_, ws) => {
|
||||
onClose: async (_, ws) => {
|
||||
const sessionId = ws.raw;
|
||||
if (sessionId && this.connections.has(sessionId)) {
|
||||
const session = this.connections.get(sessionId);
|
||||
if (session) {
|
||||
await dispatchCommand(this.control, {
|
||||
op: 'ssh_term',
|
||||
payload: {
|
||||
sessionId,
|
||||
},
|
||||
});
|
||||
|
||||
session.connected = false;
|
||||
this.connections.delete(sessionId);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onError: (event, ws) => {
|
||||
onError: async (event, ws) => {
|
||||
const sessionId = ws.raw;
|
||||
if (sessionId && this.connections.has(sessionId)) {
|
||||
const session = this.connections.get(sessionId);
|
||||
if (session) {
|
||||
await dispatchCommand(this.control, {
|
||||
op: 'ssh_term',
|
||||
payload: {
|
||||
sessionId,
|
||||
},
|
||||
});
|
||||
|
||||
session.connected = false;
|
||||
this.connections.delete(sessionId);
|
||||
}
|
||||
@@ -191,7 +205,7 @@ export class SSHMultiplexer {
|
||||
op: 'ssh_frame',
|
||||
payload: {
|
||||
channel: frame.channel,
|
||||
data: frame.payload,
|
||||
frame: frame.payload,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user