ableton-js
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -5,2 +5,3 @@ /// <reference types="node" /> | ||
import { Song } from "./ns/song"; | ||
import { Internal } from "./ns/internal"; | ||
declare type ConnectionEventType = "realtime" | "heartbeat"; | ||
@@ -11,2 +12,7 @@ interface ConnectionEventEmitter { | ||
} | ||
export interface EventListener { | ||
prop: string; | ||
eventId: string; | ||
listener: (data: any) => any; | ||
} | ||
export declare class Ableton extends EventEmitter implements ConnectionEventEmitter { | ||
@@ -23,2 +29,3 @@ private host; | ||
song: Song; | ||
internal: Internal; | ||
constructor(host?: string, sendPort?: number, listenPort?: number, heartbeatInterval?: number); | ||
@@ -32,4 +39,4 @@ close(): void; | ||
setProp(ns: string, nsid: number | undefined, prop: string, value: any): Promise<any>; | ||
addPropListener(ns: string, nsid: number | undefined, prop: string, listener: (data: any) => any): Promise<any>; | ||
removePropListener(ns: string, nsid: number | undefined, prop: string, eventId: string): Promise<void>; | ||
addPropListener(ns: string, nsid: number | undefined, prop: string, listener: (data: any) => any): Promise<() => Promise<boolean | undefined>>; | ||
removePropListener(ns: string, nsid: number | undefined, prop: string, eventId: string, listener: (data: any) => any): Promise<boolean | undefined>; | ||
sendRaw(msg: string): void; | ||
@@ -36,0 +43,0 @@ isConnected(): boolean; |
70
index.js
@@ -58,2 +58,4 @@ "use strict"; | ||
var song_1 = require("./ns/song"); | ||
var internal_1 = require("./ns/internal"); | ||
var semver_1 = __importDefault(require("semver")); | ||
var Ableton = /** @class */ (function (_super) { | ||
@@ -63,4 +65,4 @@ __extends(Ableton, _super); | ||
if (host === void 0) { host = "127.0.0.1"; } | ||
if (sendPort === void 0) { sendPort = 9001; } | ||
if (listenPort === void 0) { listenPort = 9000; } | ||
if (sendPort === void 0) { sendPort = 9005; } | ||
if (listenPort === void 0) { listenPort = 9004; } | ||
if (heartbeatInterval === void 0) { heartbeatInterval = 2000; } | ||
@@ -76,2 +78,3 @@ var _this = _super.call(this) || this; | ||
_this.song = new song_1.Song(_this); | ||
_this.internal = new internal_1.Internal(_this); | ||
_this.client = dgram_1["default"].createSocket({ type: "udp4", reuseAddr: true }); | ||
@@ -108,2 +111,8 @@ _this.client.bind(_this.listenPort, host); | ||
}); }, heartbeatInterval); | ||
_this.internal.get("version").then(function (v) { | ||
var jsVersion = _this.internal.getPackageVersion(); | ||
if (semver_1["default"].lt(v, jsVersion)) { | ||
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"); | ||
} | ||
}); | ||
return _this; | ||
@@ -118,13 +127,13 @@ } | ||
try { | ||
var data = JSON.parse(msg.toString()); | ||
var functionCallback = this.msgMap.get(data.uuid); | ||
if (data.event === "result" && functionCallback) { | ||
this.msgMap["delete"](data.uuid); | ||
return functionCallback.res(data.data); | ||
var data_1 = JSON.parse(msg.toString()); | ||
var functionCallback = this.msgMap.get(data_1.uuid); | ||
if (data_1.event === "result" && functionCallback) { | ||
this.msgMap["delete"](data_1.uuid); | ||
return functionCallback.res(data_1.data); | ||
} | ||
if (data.event === "error" && functionCallback) { | ||
this.msgMap["delete"](data.uuid); | ||
return functionCallback.rej(new Error(data.data)); | ||
if (data_1.event === "error" && functionCallback) { | ||
this.msgMap["delete"](data_1.uuid); | ||
return functionCallback.rej(new Error(data_1.data)); | ||
} | ||
if (data.event === "disconnect") { | ||
if (data_1.event === "disconnect") { | ||
this.msgMap.clear(); | ||
@@ -139,3 +148,3 @@ this.eventListeners.clear(); | ||
} | ||
if (data.event === "connect") { | ||
if (data_1.event === "connect") { | ||
if (this._isConnected === false) { | ||
@@ -148,5 +157,5 @@ this._isConnected = true; | ||
} | ||
var eventCallback = this.eventListeners.get(data.event); | ||
var eventCallback = this.eventListeners.get(data_1.event); | ||
if (eventCallback) { | ||
return eventCallback(data.data); | ||
return eventCallback.forEach(function (cb) { return cb(data_1.data); }); | ||
} | ||
@@ -200,2 +209,3 @@ } | ||
var eventId, result; | ||
var _this = this; | ||
return __generator(this, function (_a) { | ||
@@ -207,2 +217,3 @@ switch (_a.label) { | ||
prop: prop, | ||
nsid: nsid, | ||
eventId: eventId | ||
@@ -212,6 +223,11 @@ })]; | ||
result = _a.sent(); | ||
if (result === eventId) { | ||
this.eventListeners.set(eventId, listener); | ||
if (!this.eventListeners.has(result)) { | ||
this.eventListeners.set(result, [listener]); | ||
} | ||
return [2 /*return*/, result]; | ||
else { | ||
this.eventListeners.set(result, this.eventListeners.get(result).concat([ | ||
listener, | ||
])); | ||
} | ||
return [2 /*return*/, function () { return _this.removePropListener(ns, nsid, prop, result, listener); }]; | ||
} | ||
@@ -221,11 +237,23 @@ }); | ||
}; | ||
Ableton.prototype.removePropListener = function (ns, nsid, prop, eventId) { | ||
Ableton.prototype.removePropListener = function (ns, nsid, prop, eventId, listener) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var listeners; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.sendCommand(ns, nsid, "remove_listener", { prop: prop })]; | ||
case 0: | ||
listeners = this.eventListeners.get(eventId); | ||
if (!listeners) { | ||
return [2 /*return*/, false]; | ||
} | ||
if (listeners.length > 1) { | ||
this.eventListeners.set(eventId, listeners.filter(function (l) { return l !== listener; })); | ||
return [2 /*return*/, true]; | ||
} | ||
if (!(listeners.length === 1)) return [3 /*break*/, 2]; | ||
this.eventListeners["delete"](eventId); | ||
return [4 /*yield*/, this.sendCommand(ns, nsid, "remove_listener", { prop: prop, nsid: nsid })]; | ||
case 1: | ||
_a.sent(); | ||
this.eventListeners["delete"](eventId); | ||
return [2 /*return*/]; | ||
return [2 /*return*/, true]; | ||
case 2: return [2 /*return*/]; | ||
} | ||
@@ -232,0 +260,0 @@ }); |
@@ -12,4 +12,3 @@ import { Ableton } from ".."; | ||
set<T extends keyof SP>(prop: T, value: SP[T]): Promise<null>; | ||
addListener<T extends keyof OP>(prop: T, listener: (data: T extends keyof TP ? TP[T] : OP[T]) => any): Promise<any>; | ||
removeListener<T extends keyof OP>(prop: T, eventId: string): Promise<void>; | ||
addListener<T extends keyof OP>(prop: T, listener: (data: T extends keyof TP ? TP[T] : OP[T]) => any): Promise<() => Promise<boolean | undefined>>; | ||
protected sendCommand(name: string, args?: { | ||
@@ -16,0 +15,0 @@ [k: string]: any; |
@@ -88,10 +88,2 @@ "use strict"; | ||
}; | ||
Namespace.prototype.removeListener = function (prop, eventId) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
this.ableton.removePropListener(this.ns, this.nsid, String(prop), eventId); | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
}; | ||
Namespace.prototype.sendCommand = function (name, args, timeout) { | ||
@@ -98,0 +90,0 @@ return __awaiter(this, void 0, void 0, function () { |
{ | ||
"name": "ableton-js", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "Control Ableton Live from Node", | ||
@@ -10,3 +10,4 @@ "main": "index.js", | ||
"**/*.js", | ||
"**/*.d.ts" | ||
"**/*.d.ts", | ||
"hooks/**/*" | ||
], | ||
@@ -21,2 +22,4 @@ "scripts": { | ||
"prepublishOnly": "yarn build", | ||
"postinstall": "node hooks/postinstall.js", | ||
"prepublish": "node hooks/prepublish.js", | ||
"build": "tsc", | ||
@@ -23,0 +26,0 @@ "test": "jest --runInBand" |
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
1
81828
31
1825
1
5