新增 连接错误超时

This commit is contained in:
Suwings 2022-01-25 14:19:13 +08:00
parent d7f05a4913
commit c80bb8a809
2 changed files with 18 additions and 8 deletions

View File

@ -30,7 +30,12 @@ import { ElNotification } from "element-plus";
// import { API_URL } from "./common";
export function connectRemoteService(addr, password) {
export function connectRemoteService(
addr,
password,
connectCallback = () => {},
errorCallbackCallback = () => {}
) {
console.log("浏览器正在连接守护进程:", addr);
console.log("临时密码:", password);
const socket = io(addr, {}).connect();
@ -55,12 +60,14 @@ export function connectRemoteService(addr, password) {
socket.on("connect_error", (error) => {
console.log("[WS->Daemon] 连接错误:", error);
errorCallbackCallback(error);
});
socket.on("stream/auth", (packet) => {
const data = packet.data;
if (data === true) {
console.log("[WS->Daemon/stream/auth] Websocket 身份验证成功");
connectCallback();
} else {
ElNotification({
title: "无法与终端建立连接",

View File

@ -540,7 +540,16 @@ export default {
//
const password = res.password;
const addr = parseforwardAddress(res.addr, "ws");
this.socket = connectRemoteService(addr, password);
this.socket = connectRemoteService(
addr,
password,
() => {
this.unavailableTerminal = false;
},
() => {
this.unavailableTerminal = true;
}
);
//
this.socket.on("instance/stdout", (packet) => {
@ -581,12 +590,6 @@ export default {
},
startInterval() {
if (!this.renderTask) this.renderTask = setInterval(this.renderFromSocket, 1000);
//
setTimeout(() => {
if (!this.available && this.unavailableTerminal === false) {
this.unavailableTerminal = true;
}
}, 8000);
},
stopInterval() {
clearInterval(this.renderTask);