Skip to content

Commit

Permalink
fix(miio): Set ServerSocket to disconnected on timeouts to prevent va…
Browse files Browse the repository at this point in the history
…letudo breaking on wifi issues
  • Loading branch information
Hypfer committed Feb 10, 2021
1 parent 1509be3 commit e14935d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/miio/MiioSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,22 @@ class MiioSocket {
timeout: () => {
Logger.debug(this.name, "request", msg["id"], msg["method"], "timed out");
delete this.pendingRequests[msg["id"]];

if (this.isServerSocket && this.connected === true) {
Logger.info("Cloud message timed out. Assuming that we're not connected anymore");

this.connected = false;
}


reject(new MiioTimeoutError(msg));
}
};

this.pendingRequests[msg["id"]].timeout_id = setTimeout(
this.pendingRequests[msg["id"]].timeout, options.timeout || this.timeout);
this.pendingRequests[msg["id"]].timeout,
options.timeout || this.timeout
);
}
const payload = msg === null ? null : Buffer.from(JSON.stringify(msg), "utf8");
const packet = this.codec.encode(payload, this.stamp.orNew(), this.deviceId);
Expand Down

0 comments on commit e14935d

Please sign in to comment.