Skip to content

Commit

Permalink
infinite retees
Browse files Browse the repository at this point in the history
  • Loading branch information
hoeken committed Dec 22, 2023
1 parent d3f7603 commit f23c082
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class YarrboardClient {
this.config = false;
this.closed = false;
this.connectionRetryCount = 0;
this.maxConnectionRetries = 100;
this.maxConnectionRetries = 0; // 0 = try forever
this.state = "IDLE";
this.connectionStates = ["IDLE", "CONNECTING", "CONNECTED", "RETRYING", "FAILED"];

Expand Down Expand Up @@ -245,6 +245,19 @@ class YarrboardClient {
}, requireConfirmation);
}

setSwitchState(id, state, source, requireConfirmation = true) {
if (state === true)
state = "ON";
else if (state === false)
state = "OFF";

return this.send({
"cmd": "set_switch",
"id": id,
"state": state,
"source": source
}, requireConfirmation);
}

fadePWMChannel(id, duty, millis, requireConfirmation = true) {
return this.send({
Expand All @@ -256,6 +269,11 @@ class YarrboardClient {
}

setPWMChannelState(id, state, source, requireConfirmation = true) {
if (state === true)
state = "ON";
else if (state === false)
state = "OFF";

return this.send({
"cmd": "set_pwm_channel",
"id": id,
Expand Down Expand Up @@ -358,11 +376,12 @@ class YarrboardClient {
this.closed = true;
this.onclose(event);

//update our retries
this.connectionRetryCount++;

if (this.connectionRetryCount <= this.maxConnectionRetries)
//did we hit our max?
if (this.maxConnectionRetries > 0 && this.connectionRetryCount <= this.maxConnectionRetries)
{
//update our retries
this.connectionRetryCount++;

delete this.ws;
this._createWebsocket();
}
Expand Down

0 comments on commit f23c082

Please sign in to comment.