mirror of
https://github.com/wavetermdev/backup.git
synced 2026-08-05 13:57:07 -07:00
termcontext for remoteid terminals
This commit is contained in:
+21
-5
@@ -322,7 +322,7 @@ class ScreenWindow {
|
|||||||
}
|
}
|
||||||
let cols = widthToCols(width);
|
let cols = widthToCols(width);
|
||||||
let usedRows = GlobalModel.getTUR(this.sessionId, cmdId, cols);
|
let usedRows = GlobalModel.getTUR(this.sessionId, cmdId, cols);
|
||||||
termWrap = new TermWrap(elem, this.sessionId, cmdId, usedRows, cmd.getTermOpts(), {height: 0, width: width}, cmd.handleKey.bind(cmd));
|
termWrap = new TermWrap(elem, {sessionId: this.sessionId, cmdId: cmdId}, usedRows, cmd.getTermOpts(), {height: 0, width: width}, cmd.handleKey.bind(cmd));
|
||||||
this.terms[cmdId] = termWrap;
|
this.terms[cmdId] = termWrap;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -636,6 +636,9 @@ class InputModel {
|
|||||||
infoMsg : OV<InfoType> = mobx.observable.box(null);
|
infoMsg : OV<InfoType> = mobx.observable.box(null);
|
||||||
infoTimeoutId : any = null;
|
infoTimeoutId : any = null;
|
||||||
|
|
||||||
|
ptyRemoteId : OV<string> = mobx.observable.box(null);
|
||||||
|
remoteTermWrap : TermWrap;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.filteredHistoryItems = mobx.computed(() => {
|
this.filteredHistoryItems = mobx.computed(() => {
|
||||||
return this._getFilteredHistoryItems();
|
return this._getFilteredHistoryItems();
|
||||||
@@ -1404,12 +1407,25 @@ class Model {
|
|||||||
runUpdate_internal(genUpdate : UpdateMessage, uiContext : UIContextType, interactive : boolean) {
|
runUpdate_internal(genUpdate : UpdateMessage, uiContext : UIContextType, interactive : boolean) {
|
||||||
if ("ptydata64" in genUpdate) {
|
if ("ptydata64" in genUpdate) {
|
||||||
let ptyMsg : PtyDataUpdateType = genUpdate;
|
let ptyMsg : PtyDataUpdateType = genUpdate;
|
||||||
let activeScreen = this.getActiveScreen();
|
if (isBlank(ptyMsg.remoteid)) {
|
||||||
if (!activeScreen || activeScreen.sessionId != ptyMsg.sessionid) {
|
// regular update
|
||||||
|
let activeScreen = this.getActiveScreen();
|
||||||
|
if (!activeScreen || activeScreen.sessionId != ptyMsg.sessionid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
activeScreen.updatePtyData(ptyMsg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// remote update
|
||||||
|
let activeRemoteId = this.inputModel.ptyRemoteId.get();
|
||||||
|
if (activeRemoteId != ptyMsg.remoteid || this.inputModel.remoteTermWrap == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let ptyData = base64ToArray(ptyMsg.ptydata64);
|
||||||
|
this.inputModel.remoteTermWrap.updatePtyData(ptyMsg.ptypos, ptyData);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
activeScreen.updatePtyData(ptyMsg);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
let update : ModelUpdateType = genUpdate;
|
let update : ModelUpdateType = genUpdate;
|
||||||
if ("sessions" in update) {
|
if ("sessions" in update) {
|
||||||
|
|||||||
+24
-9
@@ -31,11 +31,12 @@ function boundInt(ival : number, minVal : number, maxVal : number) : number {
|
|||||||
return ival;
|
return ival;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TermContext = {sessionId? : string, cmdId? : string, remoteId? : string};
|
||||||
|
|
||||||
// cmd-instance
|
// cmd-instance
|
||||||
class TermWrap {
|
class TermWrap {
|
||||||
terminal : any;
|
terminal : any;
|
||||||
sessionId : string;
|
termContext : TermContext;
|
||||||
cmdId : string;
|
|
||||||
atRowMax : boolean;
|
atRowMax : boolean;
|
||||||
usedRows : mobx.IObservableValue<number>;
|
usedRows : mobx.IObservableValue<number>;
|
||||||
isFocused : mobx.IObservableValue<boolean> = mobx.observable.box(false, {name: "focus"});
|
isFocused : mobx.IObservableValue<boolean> = mobx.observable.box(false, {name: "focus"});
|
||||||
@@ -49,9 +50,8 @@ class TermWrap {
|
|||||||
numParseErrors : number = 0;
|
numParseErrors : number = 0;
|
||||||
termSize : TermWinSize;
|
termSize : TermWinSize;
|
||||||
|
|
||||||
constructor(elem : Element, sessionId : string, cmdId : string, usedRows : number, termOpts : TermOptsType, winSize : WindowSize, keyHandler : (event : any) => void) {
|
constructor(elem : Element, termContext : TermContext, usedRows : number, termOpts : TermOptsType, winSize : WindowSize, keyHandler : (event : any) => void) {
|
||||||
this.sessionId = sessionId;
|
this.termContext = termContext;
|
||||||
this.cmdId = cmdId;
|
|
||||||
this.connectedElem = elem;
|
this.connectedElem = elem;
|
||||||
this.flexRows = termOpts.flexrows ?? false;
|
this.flexRows = termOpts.flexrows ?? false;
|
||||||
this.winSize = winSize;
|
this.winSize = winSize;
|
||||||
@@ -140,6 +140,12 @@ class TermWrap {
|
|||||||
if (this.terminal == null) {
|
if (this.terminal == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!this.flexRows) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.termContext.remoteId != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (forceFull) {
|
if (forceFull) {
|
||||||
this.atRowMax = false;
|
this.atRowMax = false;
|
||||||
}
|
}
|
||||||
@@ -156,12 +162,12 @@ class TermWrap {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.usedRows.set(tur);
|
this.usedRows.set(tur);
|
||||||
GlobalModel.setTUR(this.sessionId, this.cmdId, this.termSize, tur);
|
GlobalModel.setTUR(this.termContext.sessionId, this.termContext.cmdId, this.termSize, tur);
|
||||||
if (this.connectedElem) {
|
if (this.connectedElem) {
|
||||||
let resizeEvent = new CustomEvent("termresize", {
|
let resizeEvent = new CustomEvent("termresize", {
|
||||||
bubbles: true,
|
bubbles: true,
|
||||||
detail: {
|
detail: {
|
||||||
cmdId: this.cmdId,
|
cmdId: this.termContext.cmdId,
|
||||||
oldUsedRows: oldUsedRows,
|
oldUsedRows: oldUsedRows,
|
||||||
newUsedRows: tur,
|
newUsedRows: tur,
|
||||||
},
|
},
|
||||||
@@ -190,13 +196,22 @@ class TermWrap {
|
|||||||
this.updateUsedRows(true);
|
this.updateUsedRows(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getReloadUrl() : string {
|
||||||
|
if (this.termContext.remoteId != null) {
|
||||||
|
return sprintf("http://localhost:8080/api/remote-pty?remoteid=%s", this.termContext.remoteId);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return sprintf("http://localhost:8080/api/ptyout?sessionid=%s&cmdid=%s", this.termContext.sessionId, this.termContext.cmdId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
reloadTerminal(delayMs : number) {
|
reloadTerminal(delayMs : number) {
|
||||||
if (this.terminal == null) {
|
if (this.terminal == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.reloading = true;
|
this.reloading = true;
|
||||||
this.terminal.reset();
|
this.terminal.reset();
|
||||||
let url = sprintf("http://localhost:8080/api/ptyout?sessionid=%s&cmdid=%s", this.sessionId, this.cmdId);
|
let url = this._getReloadUrl();
|
||||||
let ptyOffset = 0;
|
let ptyOffset = 0;
|
||||||
fetch(url).then((resp) => {
|
fetch(url).then((resp) => {
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
@@ -236,7 +251,7 @@ class TermWrap {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (pos > this.ptyPos) {
|
if (pos > this.ptyPos) {
|
||||||
throw new Error(sprintf("invalid pty-update, data-pos[%d] does not match term-pos[%d] cmdid[%s]", pos, this.ptyPos, this.cmdId));
|
throw new Error(sprintf("invalid pty-update, data-pos[%d] does not match term-pos[%d] cmdid[%s]", pos, this.ptyPos, JSON.stringify(this.termContext)));
|
||||||
}
|
}
|
||||||
if (pos < this.ptyPos) {
|
if (pos < this.ptyPos) {
|
||||||
let diff = this.ptyPos - pos;
|
let diff = this.ptyPos - pos;
|
||||||
|
|||||||
@@ -229,6 +229,7 @@ type CmdDataType = {
|
|||||||
type PtyDataUpdateType = {
|
type PtyDataUpdateType = {
|
||||||
sessionid : string,
|
sessionid : string,
|
||||||
cmdid : string,
|
cmdid : string,
|
||||||
|
remoteid : string,
|
||||||
ptypos : number,
|
ptypos : number,
|
||||||
ptydata64 : string,
|
ptydata64 : string,
|
||||||
ptydatalen : number,
|
ptydatalen : number,
|
||||||
|
|||||||
Reference in New Issue
Block a user