Skip to content

Commit

Permalink
fix: ensure only one reconnection timer is running
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmattmatt committed Apr 7, 2018
1 parent 766f42a commit 421f9fb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/YeeLightConfig.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Yeelight from 'yeelight2';

const RECONNETION_INTERVAL_SECS = 5000;

export default function YeeLightConfig(RED) {
return function(config) {
const node = this;
Expand All @@ -19,7 +21,8 @@ export default function YeeLightConfig(RED) {

const onYeelightError = error => {
console.error(`Error at ${host}`, error);
reconnectionTimeout = setTimeout(startConnection, 5000);
clearTimeout(reconnectionTimeout);
reconnectionTimeout = setTimeout(startConnection, RECONNETION_INTERVAL_SECS);
node.yeelight.socketState = 'error';
};

Expand Down

0 comments on commit 421f9fb

Please sign in to comment.