cmd input working

This commit is contained in:
sawka 2022-06-17 15:32:19 -07:00
parent bb159bac5b
commit 0cce8ad503
4 changed files with 32 additions and 10 deletions

View File

@ -77,7 +77,7 @@ class LineCmd extends React.Component<{line : LineType, session : Session}, {}>
doRefresh() { doRefresh() {
let {session, line} = this.props; let {session, line} = this.props;
let termWrap = session.getTermWrapByLine(line); let termWrap = session.getTermWrapByLine(line);
termWrap.reloadTerminal(line.sessionid, line.cmdid, 500); termWrap.reloadTerminal(true, 500);
} }
@boundMethod @boundMethod

View File

@ -69,12 +69,11 @@ class Session {
if (termWrap != null) { if (termWrap != null) {
return termWrap; return termWrap;
} }
termWrap = new TermWrap(); termWrap = new TermWrap(line.sessionid, line.cmdid);
this.termMap[termKey] = termWrap; this.termMap[termKey] = termWrap;
this.termMapById[termWrap.termId] = termWrap; this.termMapById[termWrap.termId] = termWrap;
termWrap.initialized = true; termWrap.initialized = true;
termWrap.reloadTerminal(0); termWrap.reloadTerminal(true, 0);
termWrap.startPtyTail(line.sessionid, line.cmdid);
return termWrap; return termWrap;
} }

View File

@ -21,6 +21,8 @@ function loadPtyOut(term : Terminal, sessionId : string, cmdId : string, delayMs
class TermWrap { class TermWrap {
terminal : Terminal; terminal : Terminal;
termId : string; termId : string;
sessionId : string;
cmdId : string;
ptyPos : number = 0; ptyPos : number = 0;
runPos : number = 0; runPos : number = 0;
runData : string = ""; runData : string = "";
@ -32,8 +34,10 @@ class TermWrap {
atRowMax : boolean = false; atRowMax : boolean = false;
initialized : boolean = false; initialized : boolean = false;
constructor() { constructor(sessionId : string, cmdId : string) {
this.termId = uuidv4(); this.termId = uuidv4();
this.sessionId = sessionId;
this.cmdId = cmdId;
this.terminal = new Terminal({rows: 2, cols: 80}); this.terminal = new Terminal({rows: 2, cols: 80});
} }
@ -41,12 +45,23 @@ class TermWrap {
} }
startPtyTail(sessionId : string, cmdId : string) { @boundMethod
onKeyHandler(event : any) {
let inputPacket = {
type: "input",
sessionid: this.sessionId,
cmdid: this.cmdId,
inputdata: event.key,
};
GlobalWS.pushMessage(inputPacket);
}
startPtyTail() {
let getCmdPacket = { let getCmdPacket = {
type: "getcmd", type: "getcmd",
reqid: this.termId, reqid: this.termId,
sessionid: sessionId, sessionid: this.sessionId,
cmdid: cmdId, cmdid: this.cmdId,
ptypos: this.ptyPos, ptypos: this.ptyPos,
tail: true, tail: true,
}; };
@ -121,12 +136,15 @@ class TermWrap {
mobx.action(() => this.renderVersion.set(this.renderVersion.get() + 1))(); mobx.action(() => this.renderVersion.set(this.renderVersion.get() + 1))();
} }
reloadTerminal(sessionId : string, cmdId : string, delayMs : number) { reloadTerminal(startTail : boolean, delayMs : number) {
loadPtyOut(this.terminal, sessionId, cmdId, delayMs, (ptyoutLen) => { loadPtyOut(this.terminal, this.sessionId, this.cmdId, delayMs, (ptyoutLen) => {
mobx.action(() => { mobx.action(() => {
this.incRenderVersion(); this.incRenderVersion();
this.ptyPos = ptyoutLen; this.ptyPos = ptyoutLen;
})(); })();
if (startTail) {
this.startPtyTail();
}
}); });
} }
@ -138,6 +156,7 @@ class TermWrap {
this.terminal.textarea.addEventListener("blur", () => { this.terminal.textarea.addEventListener("blur", () => {
this.setFocus(false); this.setFocus(false);
}); });
this.terminal.onKey(this.onKeyHandler);
} }
} }

View File

@ -33,6 +33,10 @@ class WSControl {
return; return;
} }
this.reconnectTimes++; this.reconnectTimes++;
if (this.reconnectTimes > 20) {
console.log("websocket cannot connect, giving up");
return;
}
let timeoutArr = [0, 0, 2, 5, 10, 10, 30, 60]; let timeoutArr = [0, 0, 2, 5, 10, 10, 30, 60];
let timeout = 60; let timeout = 60;
if (this.reconnectTimes < timeoutArr.length) { if (this.reconnectTimes < timeoutArr.length) {