send connect from ws and get session/remotes updates

This commit is contained in:
sawka
2022-09-05 12:42:48 -07:00
parent fb899cd458
commit d6d7e8bb25
3 changed files with 35 additions and 30 deletions
+8 -29
View File
@@ -1132,8 +1132,6 @@ class Model {
constructor() {
this.clientId = getApi().getId();
this.loadRemotes();
this.loadSessionList();
this.ws = new WSControl(this.clientId, (message : any) => this.runUpdate(message, false));
this.ws.reconnect();
this.inputModel = new InputModel();
@@ -1408,6 +1406,10 @@ class Model {
this.inputModel.setHistoryInfo(update.history);
}
}
if ("connect" in update) {
this.sessionListLoaded.set(true);
this.remotesLoaded.set(true);
}
// console.log("run-update>", Date.now(), interactive, update);
}
@@ -1553,6 +1555,7 @@ class Model {
args: args,
kwargs: Object.assign({}, kwargs),
uicontext : this.getUIContext(),
interactive : interactive,
};
this.submitCommandPacket(pk, interactive);
}
@@ -1564,6 +1567,7 @@ class Model {
args: [cmdStr],
kwargs: null,
uicontext : this.getUIContext(),
interactive : interactive,
};
if (!addToHistory) {
pk.kwargs["nohist"] = "1";
@@ -1571,19 +1575,6 @@ class Model {
this.submitCommandPacket(pk, interactive)
}
loadSessionList() : void {
let url = new URL("http://localhost:8080/api/get-all-sessions");
fetch(url).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
mobx.action(() => {
this.runUpdate(data.data, false);
this.sessionListLoaded.set(true);
})();
return;
}).catch((err) => {
this.errorHandler("getting session list", err, false);
});
}
_activateSession(sessionId : string) {
let oldActiveSession = this.getActiveSession();
if (oldActiveSession != null && oldActiveSession.sessionId == sessionId) {
@@ -1613,10 +1604,10 @@ class Model {
})();
let curScreen = this.getActiveScreen();
if (curScreen == null) {
this.ws.pushMessage({type: "watchscreen", sessionid: sessionId});
this.ws.watchScreen(sessionId, null);
return;
}
this.ws.pushMessage({type: "watchscreen", sessionid: curScreen.sessionId, screenid: curScreen.screenId});
this.ws.watchScreen(curScreen.sessionId, curScreen.screenId);
}
loadWindow(sessionId : string, windowId : string) : Window {
@@ -1637,18 +1628,6 @@ class Model {
return newWin;
}
loadRemotes() {
let url = new URL("http://localhost:8080/api/get-remotes");
fetch(url).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
mobx.action(() => {
this.runUpdate(data.data, false);
this.remotesLoaded.set(true);
})();
}).catch((err) => {
this.errorHandler("calling get-remotes", err, false)
});
}
getRemote(remoteId : string) : RemoteType {
for (let i=0; i<this.remotes.length; i++) {
if (this.remotes[i].remoteid == remoteId) {
+5 -1
View File
@@ -161,12 +161,14 @@ type FeCmdPacketType = {
args : string[],
kwargs : Record<string, string>;
uicontext : UIContextType,
interactive : boolean,
};
type WatchScreenPacketType = {
type : string,
sessionid : string,
screenid : string,
connect : boolean,
};
type TermOptsType = {
@@ -226,6 +228,8 @@ type ModelUpdateType = {
cmdline? : CmdLineUpdateType,
remotes? : RemoteType[],
history? : HistoryInfoType,
interactive : boolean,
connect? : boolean,
};
type HistoryInfoType = {
@@ -264,4 +268,4 @@ type HistoryQueryOpts = {
type UpdateMessage = PtyDataUpdateType | ModelUpdateType;
export type {SessionDataType, LineType, RemoteType, RemoteStateType, RemoteInstanceType, WindowDataType, HistoryItem, CmdRemoteStateType, FeCmdPacketType, TermOptsType, CmdStartPacketType, CmdDonePacketType, CmdDataType, ScreenDataType, ScreenOptsType, ScreenWindowType, LayoutType, PtyDataUpdateType, ModelUpdateType, UpdateMessage, InfoType, CmdLineUpdateType, RemotePtrType, UIContextType, HistoryInfoType, HistoryQueryOpts};
export type {SessionDataType, LineType, RemoteType, RemoteStateType, RemoteInstanceType, WindowDataType, HistoryItem, CmdRemoteStateType, FeCmdPacketType, TermOptsType, CmdStartPacketType, CmdDonePacketType, CmdDataType, ScreenDataType, ScreenOptsType, ScreenWindowType, LayoutType, PtyDataUpdateType, ModelUpdateType, UpdateMessage, InfoType, CmdLineUpdateType, RemotePtrType, UIContextType, HistoryInfoType, HistoryQueryOpts, WatchScreenPacketType};
+22
View File
@@ -1,6 +1,7 @@
import * as mobx from "mobx";
import {sprintf} from "sprintf-js";
import {boundMethod} from "autobind-decorator";
import {WatchScreenPacketType} from "./types";
class WSControl {
wsConn : any;
@@ -10,6 +11,8 @@ class WSControl {
msgQueue : any[] = [];
clientId : string;
messageCallback : (any) => void = null;
watchSessionId : string = null;
watchScreenId : string = null;
constructor(clientId : string, messageCallback : (any) => void) {
this.messageCallback = messageCallback;
@@ -78,6 +81,7 @@ class WSControl {
this.setOpen(true);
this.opening = false;
this.runMsgQueue();
this.sendWatchScreenPacket(true);
// reconnectTimes is reset in onmessage:hello
}
@@ -148,6 +152,24 @@ class WSControl {
}
this.sendMessage(data);
}
sendWatchScreenPacket(connect : boolean) {
let pk : WatchScreenPacketType = {"type": "watchscreen", connect: connect, sessionid: null, screenid: null};
if (this.watchSessionId != null) {
pk.sessionid = this.watchSessionId;
}
if (this.watchScreenId != null) {
pk.screenid = this.watchScreenId;
}
this.pushMessage(pk);
}
// these params can be null. (null, null) means stop watching
watchScreen(sessionId : string, screenId : string) {
this.watchSessionId = sessionId;
this.watchScreenId = screenId;
this.sendWatchScreenPacket(false);
}
}
export {WSControl};