fix web console js do not close connect problem; fix js ws send state problem. #1345

This commit is contained in:
hengyunabc
2020-07-17 20:30:53 +08:00
parent eacc5081fd
commit 14b1b32542
2 changed files with 6 additions and 2 deletions
@@ -105,6 +105,7 @@ function startConnect (silent) {
// init webSocket
initWs(ip, port);
ws.onerror = function () {
ws.close();
ws = null;
!silent && alert('Connect error');
};
@@ -128,7 +129,7 @@ function startConnect (silent) {
});
ws.send(JSON.stringify({action: 'resize', cols: terminalSize.cols, rows: terminalSize.rows}));
window.setInterval(function () {
if (ws != null) {
if (ws != null && ws.readyState === 1) {
ws.send(JSON.stringify({action: 'read', data: ""}));
}
}, 30000);
@@ -137,6 +138,7 @@ function startConnect (silent) {
function disconnect () {
try {
ws.close();
ws.onmessage = null;
ws.onclose = null;
ws = null;
@@ -116,6 +116,7 @@ function startConnect (silent) {
// init webSocket
initWs(ip, port, agentId);
ws.onerror = function () {
ws.close();
ws = null;
!silent && alert('Connect error');
};
@@ -144,7 +145,7 @@ function startConnect (silent) {
});
ws.send(JSON.stringify({action: 'resize', cols: terminalSize.cols, rows: terminalSize.rows}));
window.setInterval(function () {
if (ws != null) {
if (ws != null && ws.readyState === 1) {
ws.send(JSON.stringify({action: 'read', data: ""}));
}
}, 30000);
@@ -153,6 +154,7 @@ function startConnect (silent) {
function disconnect () {
try {
ws.close();
ws.onmessage = null;
ws.onclose = null;
ws = null;