From d6d7e8bb25bb8c88bb4c9664e890f102171325b7 Mon Sep 17 00:00:00 2001 From: sawka Date: Mon, 5 Sep 2022 12:42:48 -0700 Subject: [PATCH] send connect from ws and get session/remotes updates --- src/model.ts | 37 ++++++++----------------------------- src/types.ts | 6 +++++- src/ws.ts | 22 ++++++++++++++++++++++ 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/src/model.ts b/src/model.ts index 3d7ad20f..140bba44 100644 --- a/src/model.ts +++ b/src/model.ts @@ -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; 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}; diff --git a/src/ws.ts b/src/ws.ts index c70cca7b..f352ce80 100644 --- a/src/ws.ts +++ b/src/ws.ts @@ -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};