Description
To solve #1361 ,I've tried MQTT version 5.3.3 recently, it's able to maintain the connection automatically when client browser tab are blured or the whole browser is minimized, which works well.
However, when the computer enters sleep mode, the heartbeat stops sending immediatly.And the weirdest thing is, I purposefully added a close callback in the MQTT method to reconnect after disconnection. However, after the computer goes into sleep and then wakes up, none of the console.log in the close callback are printed. It seems like the JavaScript code in the callback hasn't been executed at all. By the way, In my tests, I tried to manually disconnect the client from the server while in the awake state. This does trigger the code in the close callback, and it can reconnect normally.
this.client.on("close", async err => {
// console.log("MQTT 连接关闭");
console.error("MQTT 连接关闭", err, new Date().valueOf());
// 如果已经尝试重连超过10次,就不再重连
if (this.retryCount >= 10) {
console.error("已经尝试重连10次,不再重连");
return;
}
// 每秒发起一次重连,重连次数超过10次后,不再重连
setTimeout(() => {
this.retryCount++;
this.connect();
}, 1000);
});
I'm not sure if this is a problem with this MQTT.js library, the browser, or the Windows operating system.
System Info
System:
OS: Windows 11 10.0.22621
CPU: (16) x64 AMD Ryzen 7 7840H w/ Radeon 780M Graphics
Memory: 13.54 GB / 29.71 GB
Binaries:
Node: 16.17.0 - C:\Program Files\nodejs\node.EXE
npm: 8.15.0 - C:\Program Files\nodejs\npm.CMD
pnpm: 8.10.3 - C:\Program Files\nodejs\pnpm.CMD
Browsers:
Edge: Spartan (44.22621.1702.0), Chromium (100.0.1185.36)
Internet Explorer: 11.0.22621.1