mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-09 19:48:45 +01:00
handle pty udpates again
This commit is contained in:
parent
05af5a8510
commit
94fd29cbad
@ -519,7 +519,7 @@ class MainSideBar extends React.Component<{}, {}> {
|
|||||||
|
|
||||||
render() {
|
render() {
|
||||||
let model = GlobalModel;
|
let model = GlobalModel;
|
||||||
let curSessionId = model.curSessionId.get();
|
let activeSessionId = model.activeSessionId.get();
|
||||||
let session : Session = null;
|
let session : Session = null;
|
||||||
return (
|
return (
|
||||||
<div className={cn("main-sidebar", {"collapsed": this.collapsed.get()})}>
|
<div className={cn("main-sidebar", {"collapsed": this.collapsed.get()})}>
|
||||||
@ -539,7 +539,7 @@ class MainSideBar extends React.Component<{}, {}> {
|
|||||||
</If>
|
</If>
|
||||||
<If condition={model.sessionListLoaded.get()}>
|
<If condition={model.sessionListLoaded.get()}>
|
||||||
<For each="session" of={model.sessionList}>
|
<For each="session" of={model.sessionList}>
|
||||||
<li key={session.sessionId}><a className={cn({"is-active": curSessionId == session.sessionId})} onClick={() => this.handleSessionClick(session.sessionId)}>#{session.name.get()}</a></li>
|
<li key={session.sessionId}><a className={cn({"is-active": activeSessionId == session.sessionId})} onClick={() => this.handleSessionClick(session.sessionId)}>#{session.name.get()}</a></li>
|
||||||
</For>
|
</For>
|
||||||
<li className="new-session"><a className="new-session"><i className="fa fa-plus"/> New Session</a></li>
|
<li className="new-session"><a className="new-session"><i className="fa fa-plus"/> New Session</a></li>
|
||||||
</If>
|
</If>
|
||||||
|
73
src/model.ts
73
src/model.ts
@ -1,10 +1,10 @@
|
|||||||
import * as mobx from "mobx";
|
import * as mobx from "mobx";
|
||||||
import {sprintf} from "sprintf-js";
|
import {sprintf} from "sprintf-js";
|
||||||
import {boundMethod} from "autobind-decorator";
|
import {boundMethod} from "autobind-decorator";
|
||||||
import {handleJsonFetchResponse} from "./util";
|
import {handleJsonFetchResponse, base64ToArray} from "./util";
|
||||||
import {TermWrap} from "./term";
|
import {TermWrap} from "./term";
|
||||||
import {v4 as uuidv4} from "uuid";
|
import {v4 as uuidv4} from "uuid";
|
||||||
import type {SessionDataType, WindowDataType, LineType, RemoteType, HistoryItem, RemoteInstanceType, CmdDataType, FeCmdPacketType, TermOptsType, RemoteStateType, ScreenDataType, ScreenWindowType, ScreenOptsType, LayoutType} from "./types";
|
import type {SessionDataType, WindowDataType, LineType, RemoteType, HistoryItem, RemoteInstanceType, CmdDataType, FeCmdPacketType, TermOptsType, RemoteStateType, ScreenDataType, ScreenWindowType, ScreenOptsType, LayoutType, PtyDataUpdateType} from "./types";
|
||||||
import {WSControl} from "./ws";
|
import {WSControl} from "./ws";
|
||||||
|
|
||||||
var GlobalUser = "sawka";
|
var GlobalUser = "sawka";
|
||||||
@ -69,6 +69,14 @@ class Cmd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatePtyData(ptyMsg : PtyDataUpdateType) {
|
||||||
|
for (let key in this.instances) {
|
||||||
|
let tw = this.instances[key];
|
||||||
|
let data = base64ToArray(ptyMsg.ptydata64);
|
||||||
|
tw.updatePtyData(ptyMsg.ptypos, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getTermWrap(screenId : string, windowId : string) : TermWrap {
|
getTermWrap(screenId : string, windowId : string) : TermWrap {
|
||||||
return this.instances[screenId + "/" + windowId];
|
return this.instances[screenId + "/" + windowId];
|
||||||
}
|
}
|
||||||
@ -183,6 +191,16 @@ class Screen {
|
|||||||
return session.getWindowById(this.activeWindowId.get());
|
return session.getWindowById(this.activeWindowId.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatePtyData(ptyMsg : PtyDataUpdateType) {
|
||||||
|
for (let i=0; i<this.windows.length; i++) {
|
||||||
|
let sw = this.windows[i];
|
||||||
|
let win = sw.getWindow();
|
||||||
|
if (win != null) {
|
||||||
|
win.updatePtyData(ptyMsg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getActiveSW() : ScreenWindow {
|
getActiveSW() : ScreenWindow {
|
||||||
return this.getSW(this.activeWindowId.get());
|
return this.getSW(this.activeWindowId.get());
|
||||||
}
|
}
|
||||||
@ -198,6 +216,23 @@ class Screen {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadWindows(force : boolean) {
|
||||||
|
let loadedMap : Record<string, boolean> = {};
|
||||||
|
let activeWindowId = this.activeWindowId.get();
|
||||||
|
if (activeWindowId != null) {
|
||||||
|
GlobalModel.loadWindow(this.sessionId, activeWindowId, false);
|
||||||
|
loadedMap[activeWindowId] = true;
|
||||||
|
}
|
||||||
|
for (let i=0; i<this.windows.length; i++) {
|
||||||
|
let win = this.windows[i];
|
||||||
|
if (loadedMap[win.windowId]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
loadedMap[win.windowId] = true;
|
||||||
|
GlobalModel.loadWindow(this.sessionId, win.windowId, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ScreenWindow {
|
class ScreenWindow {
|
||||||
@ -247,6 +282,14 @@ class Window {
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updatePtyData(ptyMsg : PtyDataUpdateType) {
|
||||||
|
let cmd = this.cmds[ptyMsg.cmdid];
|
||||||
|
if (cmd == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
cmd.updatePtyData(ptyMsg);
|
||||||
|
}
|
||||||
|
|
||||||
updateWindow(win : WindowDataType, isActive : boolean) {
|
updateWindow(win : WindowDataType, isActive : boolean) {
|
||||||
mobx.action(() => {
|
mobx.action(() => {
|
||||||
if (!isBlank(win.curremote)) {
|
if (!isBlank(win.curremote)) {
|
||||||
@ -430,7 +473,7 @@ class Session {
|
|||||||
|
|
||||||
class Model {
|
class Model {
|
||||||
clientId : string;
|
clientId : string;
|
||||||
curSessionId : OV<string> = mobx.observable.box(null);
|
activeSessionId : OV<string> = mobx.observable.box(null);
|
||||||
sessionListLoaded : OV<boolean> = mobx.observable.box(false);
|
sessionListLoaded : OV<boolean> = mobx.observable.box(false);
|
||||||
sessionList : OArr<Session> = mobx.observable.array([], {name: "SessionList", deep: false});
|
sessionList : OArr<Session> = mobx.observable.array([], {name: "SessionList", deep: false});
|
||||||
ws : WSControl;
|
ws : WSControl;
|
||||||
@ -460,11 +503,20 @@ class Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onWSMessage(message : any) {
|
onWSMessage(message : any) {
|
||||||
|
if ("ptydata64" in message) {
|
||||||
|
let ptyMsg : PtyDataUpdateType = message;
|
||||||
|
let activeScreen = this.getActiveScreen();
|
||||||
|
if (!activeScreen || activeScreen.sessionId != ptyMsg.sessionid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
activeScreen.updatePtyData(ptyMsg);
|
||||||
|
return;
|
||||||
|
}
|
||||||
console.log("ws-message", message);
|
console.log("ws-message", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
getActiveSession() : Session {
|
getActiveSession() : Session {
|
||||||
return this.getSessionById(this.curSessionId.get());
|
return this.getSessionById(this.activeSessionId.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
getSessionById(sessionId : string) : Session {
|
getSessionById(sessionId : string) : Session {
|
||||||
@ -541,7 +593,7 @@ class Model {
|
|||||||
if (session == null) {
|
if (session == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let isActive = (win.sessionid == this.curSessionId.get());
|
let isActive = (win.sessionid == this.activeSessionId.get());
|
||||||
session.updateWindow(win, isActive);
|
session.updateWindow(win, isActive);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -562,10 +614,11 @@ class Model {
|
|||||||
}
|
}
|
||||||
this.sessionList.replace(slist);
|
this.sessionList.replace(slist);
|
||||||
this.sessionListLoaded.set(true)
|
this.sessionListLoaded.set(true)
|
||||||
this.curSessionId.set(defaultSessionId);
|
this.activeSessionId.set(defaultSessionId);
|
||||||
let win = this.getActiveWindow();
|
let screen = this.getActiveScreen();
|
||||||
if (win != null) {
|
if (screen != null) {
|
||||||
this.loadWindow(win.sessionId, win.windowId);
|
this.ws.pushMessage({type: "watchscreen", sessionid: screen.sessionId, screenid: screen.screenId});
|
||||||
|
screen.loadWindows(false);
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
@ -573,7 +626,7 @@ class Model {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
loadWindow(sessionId : string, windowId : string) {
|
loadWindow(sessionId : string, windowId : string, force : boolean) {
|
||||||
let usp = new URLSearchParams({sessionid: sessionId, windowid: windowId});
|
let usp = new URLSearchParams({sessionid: sessionId, windowid: windowId});
|
||||||
let url = new URL(sprintf("http://localhost:8080/api/get-window?") + usp.toString());
|
let url = new URL(sprintf("http://localhost:8080/api/get-window?") + usp.toString());
|
||||||
fetch(url).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
|
fetch(url).then((resp) => handleJsonFetchResponse(url, resp)).then((data) => {
|
||||||
|
18
src/types.ts
18
src/types.ts
@ -108,7 +108,13 @@ type FeCmdPacketType = {
|
|||||||
userid : string,
|
userid : string,
|
||||||
cmdstr : string,
|
cmdstr : string,
|
||||||
remotestate : CmdRemoteStateType,
|
remotestate : CmdRemoteStateType,
|
||||||
}
|
};
|
||||||
|
|
||||||
|
type WatchScreenPacketType = {
|
||||||
|
type : string,
|
||||||
|
sessionid : string,
|
||||||
|
screenid : string,
|
||||||
|
};
|
||||||
|
|
||||||
type TermOptsType = {
|
type TermOptsType = {
|
||||||
rows : number,
|
rows : number,
|
||||||
@ -147,4 +153,12 @@ type CmdDataType = {
|
|||||||
usedrows : number,
|
usedrows : number,
|
||||||
};
|
};
|
||||||
|
|
||||||
export type {SessionDataType, LineType, RemoteType, RemoteStateType, RemoteInstanceType, WindowDataType, HistoryItem, CmdRemoteStateType, FeCmdPacketType, TermOptsType, CmdStartPacketType, CmdDonePacketType, CmdDataType, ScreenDataType, ScreenOptsType, ScreenWindowType, LayoutType};
|
type PtyDataUpdateType = {
|
||||||
|
sessionid : string,
|
||||||
|
cmdid : string,
|
||||||
|
ptypos : number,
|
||||||
|
ptydata64 : string,
|
||||||
|
ptydatalen : number,
|
||||||
|
};
|
||||||
|
|
||||||
|
export type {SessionDataType, LineType, RemoteType, RemoteStateType, RemoteInstanceType, WindowDataType, HistoryItem, CmdRemoteStateType, FeCmdPacketType, TermOptsType, CmdStartPacketType, CmdDonePacketType, CmdDataType, ScreenDataType, ScreenOptsType, ScreenWindowType, LayoutType, PtyDataUpdateType};
|
||||||
|
11
src/util.ts
11
src/util.ts
@ -33,4 +33,13 @@ function handleJsonFetchResponse(url : URL, resp : any) : Promise<any> {
|
|||||||
return rtnData;
|
return rtnData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export {handleJsonFetchResponse};
|
function base64ToArray(b64 : string) : Uint8Array {
|
||||||
|
let rawStr = atob(b64);
|
||||||
|
let rtnArr = new Uint8Array(new ArrayBuffer(rawStr.length));
|
||||||
|
for (let i=0; i<rawStr.length; i++) {
|
||||||
|
rtnArr[i] = rawStr.charCodeAt(i);
|
||||||
|
}
|
||||||
|
return rtnArr;
|
||||||
|
}
|
||||||
|
|
||||||
|
export {handleJsonFetchResponse, base64ToArray};
|
||||||
|
Loading…
Reference in New Issue
Block a user