ableton-js 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,7 +4,14 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
- #### [v3.0.0](https://github.com/leolabs/ableton.js/compare/v2.9.1...v3.0.0)
7
+ #### [v3.0.1](https://github.com/leolabs/ableton.js/compare/v3.0.0...v3.0.1)
8
+
9
+ - :memo: Add breaking change reminder to the changelog [`3158328`](https://github.com/leolabs/ableton.js/commit/31583280950ac4c9a4d8d425592c05481ee7b3e7)
10
+ - :sparkles: Don't allow starting the server multiple times [`83a42b1`](https://github.com/leolabs/ableton.js/commit/83a42b1186ede6820efa13c6cec7b599693a1bb5)
11
+
12
+ ### [v3.0.0](https://github.com/leolabs/ableton.js/compare/v2.9.1...v3.0.0)
13
+
14
+ > 25 February 2023
8
15
 
9
16
  - :sparkles: Don't rely on fixed ports, make server and client bind to a random free one [`54f7737`](https://github.com/leolabs/ableton.js/commit/54f773758ec359ab9b5bc3f5fd3e7c96cae4e8b8)
10
17
  - :sparkles: Add a timeout param to the start method [`600e752`](https://github.com/leolabs/ableton.js/commit/600e752c5f7c0e349b0cb69aaf4b8f6238f6a1d4)
package/index.d.ts CHANGED
@@ -62,6 +62,7 @@ export declare class Ableton extends EventEmitter implements ConnectionEventEmit
62
62
  private clientPortFile;
63
63
  private serverPortFile;
64
64
  private logger;
65
+ private clientState;
65
66
  constructor(options?: AbletonOptions | undefined);
66
67
  /**
67
68
  * Starts the server and waits for a connection with Live to be established.
@@ -72,7 +73,7 @@ export declare class Ableton extends EventEmitter implements ConnectionEventEmit
72
73
  */
73
74
  start(timeoutMs?: number): Promise<void>;
74
75
  /** Closes the client */
75
- close(): Promise<unknown>;
76
+ close(): Promise<void>;
76
77
  /**
77
78
  * Returns the latency between the last command and its response.
78
79
  * This is a rough measurement, so don't rely too much on it.
package/index.js CHANGED
@@ -132,6 +132,7 @@ var Ableton = /** @class */ (function (_super) {
132
132
  _this.application = new application_1.Application(_this);
133
133
  _this.internal = new internal_1.Internal(_this);
134
134
  _this.midi = new midi_1.Midi(_this);
135
+ _this.clientState = "closed";
135
136
  _this.logger = options === null || options === void 0 ? void 0 : options.logger;
136
137
  _this.cache = new lru_cache_1.default(__assign({ max: 500, ttl: 1000 * 60 * 10 }, options === null || options === void 0 ? void 0 : options.cacheOptions));
137
138
  _this.clientPortFile = path_1.default.join(os_1.default.tmpdir(), (_b = (_a = _this.options) === null || _a === void 0 ? void 0 : _a.clientPortFile) !== null && _b !== void 0 ? _b : CLIENT_PORT_FILE);
@@ -146,13 +147,18 @@ var Ableton = /** @class */ (function (_super) {
146
147
  * in the given time. Should be higher than 2000ms to avoid false positives.
147
148
  */
148
149
  Ableton.prototype.start = function (timeoutMs) {
149
- var _a, _b, _c, _d;
150
+ var _a, _b, _c, _d, _e;
150
151
  return __awaiter(this, void 0, void 0, function () {
151
152
  var connection, timeout, heartbeat;
152
153
  var _this = this;
153
- return __generator(this, function (_e) {
154
- switch (_e.label) {
154
+ return __generator(this, function (_f) {
155
+ switch (_f.label) {
155
156
  case 0:
157
+ if (this.clientState !== "closed") {
158
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn("Tried call start, but client is already " + this.clientState);
159
+ return [2 /*return*/];
160
+ }
161
+ this.clientState = "starting";
156
162
  this.client = dgram_1.default.createSocket({ type: "udp4" });
157
163
  this.client.addListener("message", this.handleIncoming.bind(this));
158
164
  this.client.addListener("listening", function () { return __awaiter(_this, void 0, void 0, function () {
@@ -221,8 +227,8 @@ var Ableton = /** @class */ (function (_super) {
221
227
  }); })];
222
228
  case 1:
223
229
  // Wait for the server port file to exist
224
- _e.sent();
225
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info("Checking connection...");
230
+ _f.sent();
231
+ (_b = this.logger) === null || _b === void 0 ? void 0 : _b.info("Checking connection...");
226
232
  connection = new Promise(function (res) { return _this.once("connect", res); });
227
233
  if (!timeoutMs) return [3 /*break*/, 3];
228
234
  timeout = new Promise(function (_, rej) {
@@ -230,14 +236,15 @@ var Ableton = /** @class */ (function (_super) {
230
236
  });
231
237
  return [4 /*yield*/, Promise.race([connection, timeout])];
232
238
  case 2:
233
- _e.sent();
239
+ _f.sent();
234
240
  return [3 /*break*/, 5];
235
241
  case 3: return [4 /*yield*/, connection];
236
242
  case 4:
237
- _e.sent();
238
- _e.label = 5;
243
+ _f.sent();
244
+ _f.label = 5;
239
245
  case 5:
240
- (_b = this.logger) === null || _b === void 0 ? void 0 : _b.info("Got connection!");
246
+ (_c = this.logger) === null || _c === void 0 ? void 0 : _c.info("Got connection!");
247
+ this.clientState = "started";
241
248
  heartbeat = function () { return __awaiter(_this, void 0, void 0, function () {
242
249
  var e_2;
243
250
  return __generator(this, function (_a) {
@@ -269,14 +276,15 @@ var Ableton = /** @class */ (function (_super) {
269
276
  }
270
277
  });
271
278
  }); };
272
- this.heartbeatInterval = setInterval(heartbeat, (_d = (_c = this.options) === null || _c === void 0 ? void 0 : _c.heartbeatInterval) !== null && _d !== void 0 ? _d : 2000);
279
+ this.heartbeatInterval = setInterval(heartbeat, (_e = (_d = this.options) === null || _d === void 0 ? void 0 : _d.heartbeatInterval) !== null && _e !== void 0 ? _e : 2000);
273
280
  heartbeat();
274
281
  this.internal
275
282
  .get("version")
276
283
  .then(function (v) {
284
+ var _a;
277
285
  var jsVersion = package_version_1.getPackageVersion();
278
286
  if (semver_1.default.lt(v, jsVersion)) {
279
- console.warn("The installed version of your AbletonJS plugin (" + v + ") is lower than the JS library (" + jsVersion + ").", "Please update your AbletonJS plugin to the latest version: https://git.io/JvaOu");
287
+ (_a = _this.logger) === null || _a === void 0 ? void 0 : _a.warn("The installed version of your AbletonJS plugin (" + v + ") is lower than the JS library (" + jsVersion + ").", "Please update your AbletonJS plugin to the latest version: https://git.io/JvaOu");
280
288
  }
281
289
  })
282
290
  .catch(function () { });
@@ -291,17 +299,24 @@ var Ableton = /** @class */ (function (_super) {
291
299
  var closePromise;
292
300
  var _this = this;
293
301
  return __generator(this, function (_a) {
294
- this.cancelConnectionEvent = true;
295
- fs_1.unwatchFile(this.serverPortFile);
296
- if (this.heartbeatInterval) {
297
- clearInterval(this.heartbeatInterval);
298
- }
299
- if (this.client) {
300
- closePromise = new Promise(function (res) { var _a; return (_a = _this.client) === null || _a === void 0 ? void 0 : _a.once("close", res); });
301
- this.client.close();
302
- return [2 /*return*/, closePromise];
302
+ switch (_a.label) {
303
+ case 0:
304
+ this.cancelConnectionEvent = true;
305
+ fs_1.unwatchFile(this.serverPortFile);
306
+ if (this.heartbeatInterval) {
307
+ clearInterval(this.heartbeatInterval);
308
+ }
309
+ if (!this.client) return [3 /*break*/, 2];
310
+ closePromise = new Promise(function (res) { var _a; return (_a = _this.client) === null || _a === void 0 ? void 0 : _a.once("close", res); });
311
+ this.client.close();
312
+ return [4 /*yield*/, closePromise];
313
+ case 1:
314
+ _a.sent();
315
+ _a.label = 2;
316
+ case 2:
317
+ this.clientState = "closed";
318
+ return [2 /*return*/];
303
319
  }
304
- return [2 /*return*/];
305
320
  });
306
321
  });
307
322
  };
@@ -13,4 +13,4 @@ class Internal(Interface):
13
13
  return True
14
14
 
15
15
  def get_version(self, ns):
16
- return "3.0.0"
16
+ return "3.0.1"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ableton-js",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Control Ableton Live from Node",
5
5
  "main": "index.js",
6
6
  "author": "Leo Bernard <admin@leolabs.org>",