ableton-js
Advanced tools
Comparing version 3.2.2 to 3.2.3
@@ -7,4 +7,10 @@ ### Changelog | ||
#### [v3.2.3](https://github.com/leolabs/ableton.js/compare/v3.2.2...v3.2.3) | ||
- :bug: Fix stray heartbeats emitting a disconnect event [`6157a95`](https://github.com/leolabs/ableton.js/commit/6157a952b766f4c9548e8752c12bde599ccc1a07) | ||
#### [v3.2.2](https://github.com/leolabs/ableton.js/compare/v3.2.1...v3.2.2) | ||
> 23 June 2023 | ||
- :sparkles: Add a fallback `schedule_message` in case the Timer doesn't work as expected [`b5fdbe1`](https://github.com/leolabs/ableton.js/commit/b5fdbe12726d3c76a2fe74ec0fe0a731367fcb4f) | ||
@@ -11,0 +17,0 @@ |
@@ -105,3 +105,3 @@ /// <reference types="node" /> | ||
private clientState; | ||
private cancelDisconnectEvent; | ||
private cancelDisconnectEvents; | ||
constructor(options?: AbletonOptions | undefined); | ||
@@ -108,0 +108,0 @@ private handleConnect; |
17
index.js
@@ -54,3 +54,3 @@ "use strict"; | ||
clientState = "closed"; | ||
cancelDisconnectEvent = false; | ||
cancelDisconnectEvents = []; | ||
constructor(options) { | ||
@@ -170,2 +170,9 @@ super(); | ||
const heartbeat = async () => { | ||
// Add a cancel function to the array of heartbeats | ||
let canceled = false; | ||
const cancel = () => { | ||
canceled = true; | ||
this.logger?.debug("Cancelled heartbeat"); | ||
}; | ||
this.cancelDisconnectEvents.push(cancel); | ||
try { | ||
@@ -176,3 +183,5 @@ await this.internal.get("ping"); | ||
catch (e) { | ||
if (!this.cancelDisconnectEvent) { | ||
this.logger?.warn("Heartbeat failed:", { error: e, canceled }); | ||
// If the heartbeat has been canceled, don't emit a disconnect event | ||
if (!canceled) { | ||
this.handleDisconnect("heartbeat"); | ||
@@ -182,3 +191,3 @@ } | ||
finally { | ||
this.cancelDisconnectEvent = false; | ||
this.cancelDisconnectEvents = this.cancelDisconnectEvents.filter((e) => e !== cancel); | ||
} | ||
@@ -261,3 +270,3 @@ }; | ||
// cancel it to prevent a double disconnect/connect event. | ||
this.cancelDisconnectEvent = true; | ||
this.cancelDisconnectEvents.forEach((cancel) => cancel()); | ||
if (data.data?.port && data.data?.port !== this.serverPort) { | ||
@@ -264,0 +273,0 @@ this.logger?.info("Got new server port via connect:", { |
{ | ||
"name": "ableton-js", | ||
"version": "3.2.2", | ||
"version": "3.2.3", | ||
"description": "Control Ableton Live from Node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
178413
3687