mirror of
https://github.com/MCSManager/UI.git
synced 2025-02-23 18:49:12 +08:00
新增 连接错误超时
This commit is contained in:
parent
d7f05a4913
commit
c80bb8a809
@ -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: "无法与终端建立连接",
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user