Skip to content

Commit

Permalink
refactor: fixes onTerminalData getting hijacked
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobrosenberg committed Mar 10, 2022
1 parent 85b1479 commit fae22e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,20 @@ class Device {
}

/**
* Handles data from this.adapter.onTerminalData
* Proxies data from this.adapter.onTerminalData
* Can be wrapped and extended
* @param {string} data
*/
onTerminalData(data) {}
onTerminalData(data){}

/**
* Server.js will reactively assign this callback to the currently active terminal
* Therefore any wrapping or extending of this method will be lost whenever a terminal is used
* @param {string} data
*/
__onTerminalDataExclusive(data) {}



async updateConnection() {
if (this.online && !this.connected) {
Expand Down Expand Up @@ -112,6 +122,7 @@ class Device {
const adapter = createBlockingProxy(rawAdapter, { exceptions: ["sendData"] });

adapter.onTerminalData = (data) => {
this.__onTerminalDataExclusive(data);
this.onTerminalData(data);
this.terminalLogFile.write(data);
};
Expand Down
2 changes: 1 addition & 1 deletion src/terminal/Server.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Server {
this.log.debug('received', data.toString())
device.adapter.sendData(data);
// make sure device data is sent to the last active terminal
device.onTerminalData = (data) => socket.write(data);
device.__onTerminalDataExclusive = (data) => socket.write(data);
});

socket.on("error", (err) => {
Expand Down

0 comments on commit fae22e9

Please sign in to comment.