aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElijah Moore <elimoor@siue.edu>2022-03-31 14:44:36 -0500
committerElijah Moore <elimoor@siue.edu>2022-03-31 14:44:36 -0500
commitbbc7bf2c092460f9400a25dc6ccce992e7b8e056 (patch)
tree23bd6154257ac74660ea17eb1d7fbd020150472d
parent7350bb7ef45dc4881b61541c9402bc2d9c8a5193 (diff)
Co-authored-by: Anthony Schneider <BoredOY@users.noreply.github.com>
Added robustness to Terminal
-rw-r--r--src/App.js28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/App.js b/src/App.js
index 9ab8706..5d4eadb 100644
--- a/src/App.js
+++ b/src/App.js
@@ -59,6 +59,7 @@ class TerminalComponent extends React.Component {
selection: "#fff",
},
});
+ this.isConnecting = false;
}
componentDidMount() {
@@ -73,11 +74,13 @@ class TerminalComponent extends React.Component {
// Terminal events
this.term.onData((data) => {
- this.socket.send(this.encoder.encode("\x00" + data));
+ //this.socket.send(this.encoder.encode("\x00" + data));
+ this.handleSend(this.encoder.encode("\x00" + data));
});
this.term.onResize((evt) => {
- this.socket.send(this.encoder.encode("\x01" + JSON.stringify({ cols: evt.cols, rows: evt.rows })))
+ //this.socket.send(this.encoder.encode("\x01" + JSON.stringify({ cols: evt.cols, rows: evt.rows })));
+ this.handleSend(this.encoder.encode("\x01" + JSON.stringify({ cols: evt.cols, rows: evt.rows })));
});
this.term.onTitleChange((title) => {
@@ -106,6 +109,21 @@ class TerminalComponent extends React.Component {
this.fitAddon.fit();
}
+ handleSend(message) {
+ if (this.socket.readyState === WebSocket.OPEN) {
+ this.isConnecting = false;
+ this.socket.send(message);
+ }
+ else if (this.socket.readyState === WebSocket.CONNECTING && !this.isConnecting) {
+ this.isConnecting = true;
+ this.socket.addEventListener('open', this.handleSend(message));
+ }
+ else {
+
+ }
+ };
+
+
render() {
return (
<div className="terminalContainer">
@@ -144,9 +162,9 @@ class Sidebar extends React.Component {
return (
<div className="sidenav">
<ul>
- <li><div class="sidenavButton" onClick={() => this.createTemplate()}>Create Template</div></li>
- <li><div class="sidenavButton" onClick={() => this.toStudentView()}>View as Student</div></li>
- <li><div class="sidenavButton" onClick={() => this.logOut()}>Log Out</div></li>
+ <li><div className="sidenavButton" onClick={() => this.createTemplate()}>Create Template</div></li>
+ <li><div className="sidenavButton" onClick={() => this.toStudentView()}>View as Student</div></li>
+ <li><div className="sidenavButton" onClick={() => this.logOut()}>Log Out</div></li>
</ul>
</div>
);