diff --git a/src/term.ts b/src/term.ts index beee437d..2eb592be 100644 --- a/src/term.ts +++ b/src/term.ts @@ -48,9 +48,10 @@ class TermWrap { sessionid: sessionId, cmdid: cmdId, ptypos: this.ptyPos, + tail: true, }; GlobalWS.registerAndSendGetCmd(getCmdPacket, (dataPacket) => { - console.log("data-packet", dataPacket); + this.updatePtyData(this.ptyPos, dataPacket.ptydata, dataPacket.ptydatalen); }); } @@ -60,7 +61,7 @@ class TermWrap { throw new Error(sprintf("invalid pty-update, data-pos[%d] does not match term-pos[%d]", pos, this.ptyPos)); } this.ptyPos += datalen; - term.write(data, () => { + this.terminal.write(data, () => { mobx.action(() => { this.resizeToContent(); this.incRenderVersion(); diff --git a/src/ws.ts b/src/ws.ts index 70d1f0be..c900d622 100644 --- a/src/ws.ts +++ b/src/ws.ts @@ -5,15 +5,13 @@ import {boundMethod} from "autobind-decorator"; class WSControl { wsConn : any; open : mobx.IObservableValue; - opening : boolean; - reconnectTimes : int; - msgQueue : any[]; + opening : boolean = false; + reconnectTimes : int = 0; + msgQueue : any[] = []; + reqMap : Record void> = {}; constructor() { - this.reconnectTimes = 0; this.open = mobx.observable.box(false, {name: "WSOpen"}); - this.opening = false; - this.msgQueue = []; setInterval(this.sendPing, 5000); } @@ -22,7 +20,10 @@ class WSControl { this.open.set(val); } - registerAndSendGetCmd(pk : any) { + registerAndSendGetCmd(pk : any, callback : (dataPacket : any) => void) { + if (pk.reqid) { + this.reqMap[pk.reqid] = callback; + } this.pushMessage(pk) } @@ -43,7 +44,7 @@ class WSControl { setTimeout(() => { console.log(sprintf("websocket reconnect(%d)", this.reconnectTimes)); this.opening = true; - this.wsConn = new WebSocket("ws://localhost:8081/ws"); + this.wsConn = new WebSocket("ws://localhost:8081/ws?clientid=" + window.ScriptHausClientId); this.wsConn.onopen = this.onopen; this.wsConn.onmessage = this.onmessage; this.wsConn.onerror = this.onerror; @@ -115,7 +116,16 @@ class WSControl { this.reconnectTimes = 0; return; } - console.log("websocket message", event); + if (eventData.type == "cmddata") { + let cb = this.reqMap[eventData.reqid]; + if (!cb) { + console.log(sprintf("websocket cmddata req=%s -- no callback", eventData.reqid)); + return; + } + cb(eventData); + return; + } + console.log("websocket message", eventData); } @boundMethod