[*] 日常优化

This commit is contained in:
acgist
2023-07-27 08:27:48 +08:00
parent 6e25afaddf
commit c9af50a324
6 changed files with 130 additions and 156 deletions

View File

@@ -94,13 +94,11 @@ const signalChannel = {
}
me.heartbeatTimer = setTimeout(async () => {
if (me.connected()) {
me.push(
protocol.buildMessage("client::heartbeat", {
// TODO电池信息
battery : 100,
charging: true,
})
);
me.taoyao.push(protocol.buildMessage("client::heartbeat", {
// TODO电池信息
battery : 100,
charging: true,
}));
me.heartbeat();
} else {
console.warn("心跳失败", me.address);
@@ -136,18 +134,18 @@ const signalChannel = {
me.channel = new WebSocket(me.address, { rejectUnauthorized: false, handshakeTimeout: 5000 });
me.channel.on("open", async () => {
console.info("打开信令通道", me.address);
me.push(
protocol.buildMessage("client::register", {
name : config.signal.name,
clientId : config.signal.clientId,
clientType: config.signal.clientType,
username : config.signal.username,
password : config.signal.password,
// TODO电池信息
battery : 100,
charging : true,
})
);
const { body } = await me.taoyao.request(protocol.buildMessage("client::register", {
name : config.signal.name,
clientId : config.signal.clientId,
clientType: config.signal.clientType,
username : config.signal.username,
password : config.signal.password,
// TODO电池信息
battery : 100,
charging : true,
}));
protocol.clientIndex = body.index;
console.info("终端注册成功", protocol.clientIndex);
me.reconnectionTimeout = me.minReconnectionDelay;
me.taoyao.connect = true;
me.heartbeat();
@@ -206,19 +204,6 @@ const signalChannel = {
me.maxReconnectionDelay
);
},
/**
* 异步请求
*
* @param {*} message 消息
*/
push(message) {
const me = this;
try {
me.channel.send(JSON.stringify(message));
} catch (error) {
console.error("异步请求异常", message, error);
}
},
/**
* 关闭通道
*/
@@ -409,9 +394,6 @@ class Taoyao {
case "client::reboot":
me.clientReboot(message, body);
break;
case "client::register":
me.clientRegister(message, body);
break;
case "client::shutdown":
me.clientShutdown(message, body);
break;
@@ -587,17 +569,6 @@ class Taoyao {
);
}
/**
* 终端注册信令
*
* @param {*} message 消息
* @param {*} body 消息主体
*/
clientRegister(message, body) {
protocol.clientIndex = body.index;
console.info("终端注册成功", protocol.clientIndex);
}
/**
* 关闭终端信令
*