Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

iconnectivity-js

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iconnectivity-js - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

lib/commands/audio/get-audio-global-parm.d.ts

3

lib/commands/device/get-command-list.js

@@ -17,5 +17,2 @@ "use strict";

});
if (!response) {
return null;
}
const length = (0, number_1.mergeNumber)(response.slice(16, 18));

@@ -22,0 +19,0 @@ if (length % 2 !== 0) {

@@ -28,2 +28,2 @@ import { CommandOptions } from "..";

*/
export declare const getDevice: (params: CommandOptions) => Promise<DeviceInfo | null>;
export declare const getDevice: (params: CommandOptions) => Promise<DeviceInfo>;

@@ -25,5 +25,2 @@ "use strict";

});
if (!response) {
return null;
}
return {

@@ -30,0 +27,0 @@ productId: response[6],

@@ -6,2 +6,2 @@ import { DeviceInfoType } from ".";

*/
export declare const getInfoList: (params: CommandOptions) => Promise<DeviceInfoType[] | null>;
export declare const getInfoList: (params: CommandOptions) => Promise<DeviceInfoType[]>;

@@ -15,5 +15,2 @@ "use strict";

});
if (!response) {
return null;
}
const length = (0, number_1.mergeNumber)(response.slice(16, 18));

@@ -20,0 +17,0 @@ if (length % 2 !== 0) {

import { DeviceInfoType } from ".";
import { CommandOptions } from "..";
interface GetInfoParams extends CommandOptions {
export interface GetInfoParams extends CommandOptions {
infoType: DeviceInfoType;

@@ -9,3 +9,2 @@ }

*/
export declare const getInfo: ({ infoType, ...params }: GetInfoParams) => Promise<string | null>;
export {};
export declare const getInfo: ({ infoType, ...params }: GetInfoParams) => Promise<string>;

@@ -16,5 +16,2 @@ "use strict";

});
if (!response) {
return null;
}
const length = (0, number_1.mergeNumber)(response.slice(16, 18));

@@ -21,0 +18,0 @@ const result = response.slice(19, 19 + length - 1);

@@ -7,22 +7,2 @@ import { CommandOptions } from "..";

/** This command is used to get the current value from a hardware interface element. */
export declare const getHardwareValue: ({ type, ...params }: HardwareValueParams) => Promise<import("../../util/data").Data | null>;
export declare enum AudioMidiState {
/** Host is not connected or is not sending any USB data. */
NotConnected = 0,
/** Host has enumerated the device and is sending USB start of frame (SOF). */
Connected = 1,
/** Host is sending data to the USB audio or MIDI OUT endpoint. */
SendingData = 2,
/** Host is sending non-zero data to the specified audio channel (main audio only) or sending data to the specified MIDI port (main MIDI only). */
SendingNonZeroData = 3
}
export interface AutomaticFailoverState {
alarm: boolean;
armed: boolean;
mainAudioState: AudioMidiState;
mainMidiState: AudioMidiState;
backupAudioState: AudioMidiState;
backupMidiState: AudioMidiState;
}
/** Gets the state of the device's failover system. */
export declare const getAutomaticFailoverState: (data: CommandOptions) => Promise<AutomaticFailoverState | null>;
export declare const getHardwareValue: ({ type, ...params }: HardwareValueParams) => Promise<Uint8Array | number[]>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAutomaticFailoverState = exports.AudioMidiState = exports.getHardwareValue = void 0;
exports.getHardwareValue = void 0;
const __1 = require("..");

@@ -11,39 +11,6 @@ const _1 = require(".");

command: _1.HardwareInterfaceCommand.GetHardwareValue,
data: [0x00, type],
data: [type, 0x00],
});
if (!response) {
return null;
}
return response;
return (0, __1.getResponseBody)(response);
};
exports.getHardwareValue = getHardwareValue;
var AudioMidiState;
(function (AudioMidiState) {
/** Host is not connected or is not sending any USB data. */
AudioMidiState[AudioMidiState["NotConnected"] = 0] = "NotConnected";
/** Host has enumerated the device and is sending USB start of frame (SOF). */
AudioMidiState[AudioMidiState["Connected"] = 1] = "Connected";
/** Host is sending data to the USB audio or MIDI OUT endpoint. */
AudioMidiState[AudioMidiState["SendingData"] = 2] = "SendingData";
/** Host is sending non-zero data to the specified audio channel (main audio only) or sending data to the specified MIDI port (main MIDI only). */
AudioMidiState[AudioMidiState["SendingNonZeroData"] = 3] = "SendingNonZeroData";
})(AudioMidiState = exports.AudioMidiState || (exports.AudioMidiState = {}));
/** Gets the state of the device's failover system. */
const getAutomaticFailoverState = async (data) => {
const response = await (0, exports.getHardwareValue)({
...data,
type: _1.HardwareInterfaceType.AutomaticFailover,
});
if (!response) {
return null;
}
return {
alarm: !!(response[22] & 2),
armed: !!(response[22] & 1),
mainAudioState: response[23],
mainMidiState: response[24],
backupAudioState: response[25],
backupMidiState: response[26],
};
};
exports.getAutomaticFailoverState = getAutomaticFailoverState;

@@ -9,8 +9,2 @@ import { CommandOptions } from "..";

/** This command is used to get the current value from a hardware interface element. */
export declare const setHardwareValue: ({ type, data, ...params }: SetHardwareValueParams) => Promise<Data | null>;
export interface SetAutomaticFailoverStateParams extends CommandOptions {
alarm?: boolean;
arm?: boolean;
}
/** Sets the state of the device's failover system. */
export declare const setAutomaticFailoverState: ({ alarm, arm, ...params }: SetAutomaticFailoverStateParams) => Promise<Data | null>;
export declare const setHardwareValue: ({ type, data, ...params }: SetHardwareValueParams) => Promise<Data>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setAutomaticFailoverState = exports.setHardwareValue = void 0;
exports.setHardwareValue = void 0;
const __1 = require("..");

@@ -8,3 +8,3 @@ const _1 = require(".");

const setHardwareValue = async ({ type, data, ...params }) => {
const response = await (0, __1.sendCommand)({
return await (0, __1.sendCommand)({
...params,

@@ -14,20 +14,3 @@ command: _1.HardwareInterfaceCommand.RetSetHardwareValue,

});
if (!response) {
return null;
}
return response;
};
exports.setHardwareValue = setHardwareValue;
/** Sets the state of the device's failover system. */
const setAutomaticFailoverState = async ({ alarm, arm, ...params }) => {
const valueFlags = (alarm !== undefined ? 2 : 0) + (arm !== undefined ? 1 : 0);
const values = (alarm ? 2 : 0) + (arm ? 1 : 0);
const data = [0x00, valueFlags, values];
const response = await (0, exports.setHardwareValue)({
...params,
type: _1.HardwareInterfaceType.AutomaticFailover,
data,
});
return response;
};
exports.setAutomaticFailoverState = setAutomaticFailoverState;
import { Connectable } from "../connection";
import { Data } from "../util/data";
import { BodyParameters } from "../util/message";

@@ -15,2 +16,3 @@ import { AdvancedMidiProcessorCommand } from "./advanced-midi-processor";

device: Connectable;
debug?: boolean;
}

@@ -20,3 +22,33 @@ export declare type CommandOptions = Omit<SendCommandOptions, "command" | "data">;

export declare const getCommandName: (command: Command) => string;
/**
* Support for some commands isn't returned by the GetCommandList command,
* but is instead inferred by the support for another command. This map
* keeps track of this.
*/
export declare const COMMAND_MAP: Map<Command, Command>;
/** Sends a message to the given output and waits for a response. */
export declare const sendCommand: ({ device, command, productId, serialNumber, transactionId, data, }: SendCommandOptions) => Promise<import("../util/data").Data>;
export declare const sendCommand: ({ device, command, productId, serialNumber, transactionId, data, debug, }: SendCommandOptions) => Promise<Data>;
/** Returns the part of the response that contains the data */
export declare const getResponseBody: (response: Data) => Uint8Array | number[];
export * from "./advanced-midi-processor";
export * from "./audio";
export * from "./audio/get-audio-global-parm";
export * from "./audio/get-audio-port-meter-value";
export * from "./audio-mixer";
export * from "./automation-control";
export * from "./device";
export * from "./device/ack";
export * from "./device/extras";
export * from "./device/get-command-list";
export * from "./device/get-device";
export * from "./device/get-info-list";
export * from "./device/get-info";
export * from "./hardware-interface";
export * from "./hardware-interface/extras";
export * from "./hardware-interface/get-hardware-value";
export * from "./hardware-interface/set-hardware-value";
export * from "./midi";
export * from "./snapshot";
export * from "./snapshot/extras";
export * from "./snapshot/apply-snapshot";
export * from "./snapshot/get-snapshot-list";
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendCommand = exports.getCommandName = void 0;
exports.getResponseBody = exports.sendCommand = exports.COMMAND_MAP = exports.getCommandName = void 0;
const data_1 = require("../util/data");
const message_1 = require("../util/message");

@@ -11,2 +26,3 @@ const number_1 = require("../util/number");

const device_1 = require("./device");
const ack_1 = require("./device/ack");
const hardware_interface_1 = require("./hardware-interface");

@@ -26,2 +42,12 @@ const midi_1 = require("./midi");

exports.getCommandName = getCommandName;
/**
* Support for some commands isn't returned by the GetCommandList command,
* but is instead inferred by the support for another command. This map
* keeps track of this.
*/
exports.COMMAND_MAP = new Map([
[snapshot_1.SnapshotCommand.ApplySnapshot, snapshot_1.SnapshotCommand.GetSnapshotParm],
[snapshot_1.SnapshotCommand.CreateSnapshot, snapshot_1.SnapshotCommand.GetSnapshotParm],
[snapshot_1.SnapshotCommand.ApplySnapshotList, snapshot_1.SnapshotCommand.GetSnapshotList],
]);
/** The current transaction ID, increases with every sent command. */

@@ -38,6 +64,3 @@ let transactionId = 0;

/** Sends a message to the given output and waits for a response. */
const sendCommand = async ({ device, command, productId, serialNumber, transactionId = getNextTransactionId(), data, }) => {
if (device.supportsCommand && !device.supportsCommand(command)) {
throw new Error(`Device does not support command ${(0, exports.getCommandName)(command)}`);
}
const sendCommand = async ({ device, command, productId, serialNumber, transactionId = getNextTransactionId(), data, debug, }) => {
const body = (0, message_1.buildBody)({

@@ -47,8 +70,55 @@ command,

productId,
serialNumber,
serialNumber: serialNumber ?? device.serialNumber,
transactionId,
});
const message = (0, message_1.buildMessage)(body);
return await device.sendMessage(message);
try {
const result = await device.sendMessage(message, { command, debug });
if (result[15] === device_1.DeviceCommand.ACK) {
const code = result[20];
if (code !== ack_1.ErrorCode.NoError) {
throw new Error(`Command failed with error code ${(0, data_1.formatData)([code])} (${ack_1.ErrorCode[code]})`);
}
}
return result;
}
catch (e) {
console.error("Sending command failed:", {
error: e,
command: (0, exports.getCommandName)(command),
data: (0, data_1.formatData)(data ?? []),
transactionId,
message: (0, data_1.formatData)(message),
});
throw e;
}
};
exports.sendCommand = sendCommand;
/** Returns the part of the response that contains the data */
const getResponseBody = (response) => {
return response.slice(18, response.length - 2);
};
exports.getResponseBody = getResponseBody;
// ===== EXPORTS OF COMMANDS =====
__exportStar(require("./advanced-midi-processor"), exports);
__exportStar(require("./audio"), exports);
__exportStar(require("./audio/get-audio-global-parm"), exports);
__exportStar(require("./audio/get-audio-port-meter-value"), exports);
__exportStar(require("./audio-mixer"), exports);
__exportStar(require("./automation-control"), exports);
__exportStar(require("./device"), exports);
__exportStar(require("./device/ack"), exports);
__exportStar(require("./device/extras"), exports);
__exportStar(require("./device/get-command-list"), exports);
__exportStar(require("./device/get-device"), exports);
__exportStar(require("./device/get-info-list"), exports);
__exportStar(require("./device/get-info"), exports);
__exportStar(require("./hardware-interface"), exports);
__exportStar(require("./hardware-interface/extras"), exports);
__exportStar(require("./hardware-interface/get-hardware-value"), exports);
__exportStar(require("./hardware-interface/set-hardware-value"), exports);
__exportStar(require("./midi"), exports);
__exportStar(require("./snapshot"), exports);
__exportStar(require("./snapshot/extras"), exports);
__exportStar(require("./snapshot/apply-snapshot"), exports);
__exportStar(require("./snapshot/get-snapshot-list"), exports);

@@ -12,1 +12,8 @@ export declare enum SnapshotCommand {

}
export declare enum SnapshotType {
MidiPatchbay = 1,
AudioPatchbay = 2,
AudioControl = 3,
MixerControl = 4,
Scene = 127
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SnapshotCommand = void 0;
exports.SnapshotType = exports.SnapshotCommand = void 0;
var SnapshotCommand;

@@ -16,1 +16,9 @@ (function (SnapshotCommand) {

})(SnapshotCommand = exports.SnapshotCommand || (exports.SnapshotCommand = {}));
var SnapshotType;
(function (SnapshotType) {
SnapshotType[SnapshotType["MidiPatchbay"] = 1] = "MidiPatchbay";
SnapshotType[SnapshotType["AudioPatchbay"] = 2] = "AudioPatchbay";
SnapshotType[SnapshotType["AudioControl"] = 3] = "AudioControl";
SnapshotType[SnapshotType["MixerControl"] = 4] = "MixerControl";
SnapshotType[SnapshotType["Scene"] = 127] = "Scene";
})(SnapshotType = exports.SnapshotType || (exports.SnapshotType = {}));
import { Command } from "./commands";
import { Data } from "./util/data";
export interface SendMessageOptions {
debug?: boolean;
command: Command;
}
export interface Connectable {
sendMessage: (message: Data) => Promise<Data>;
supportsCommand?: (command: Command) => boolean;
/** The device's serial number, used to send commands to a specific device. */
serialNumber?: Data;
/** Sends a raw MIDI message to the device and returns the raw response data. */
sendMessage: (message: Data, options: SendMessageOptions) => Promise<Data>;
}

@@ -12,3 +18,3 @@ export declare class Connection implements Connectable {

/** Sends a message to the device and waits for a response. */
sendMessage: (message: Data) => Promise<Uint8Array>;
sendMessage: (message: Data, options: SendMessageOptions) => Promise<Uint8Array>;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Connection = void 0;
const commands_1 = require("./commands");
const data_1 = require("./util/data");

@@ -12,3 +13,3 @@ const message_1 = require("./util/message");

/** Sends a message to the device and waits for a response. */
this.sendMessage = async (message) => {
this.sendMessage = async (message, options) => {
return await new Promise((res, rej) => {

@@ -31,16 +32,13 @@ const timeout = setTimeout(() => rej(new Error("Timeout")), 500);

this.input.removeEventListener("midimessage", handler);
console.log({
request: (0, data_1.formatData)(message),
response: (0, data_1.formatData)(m.data),
transactionId: (0, number_1.mergeNumber)(message.slice(12, 14)),
});
if (options.debug) {
console.log({
command: (0, commands_1.getCommandName)(options.command),
request: (0, data_1.formatData)(message),
response: (0, data_1.formatData)(m.data),
transactionId: (0, number_1.mergeNumber)(message.slice(12, 14)),
});
}
};
this.input.addEventListener("midimessage", handler);
try {
this.output.send(message);
}
catch (e) {
console.error("Sending message failed:", (0, data_1.formatData)(message));
throw e;
}
this.output.send(message);
});

@@ -47,0 +45,0 @@ };

@@ -1,5 +0,4 @@

import { Command } from "./commands";
import { DeviceInfoType } from "./commands/device";
import { DeviceInfo } from "./commands/device/get-device";
import { Connection } from "./connection";
import { Data } from "./util/data";
/** Represents an iConnectivity device with a MIDI input and output */

@@ -10,8 +9,6 @@ export declare class Device extends Connection {

readonly info: DeviceInfo;
readonly supportedCommands: Command[];
constructor(input: MIDIInput, output: MIDIOutput, info: DeviceInfo, supportedCommands: Command[]);
get serialNumber(): string;
supportsCommand(command: Command): boolean;
getSupportedCommandNames(): string[];
getAllInfo(): Promise<Record<DeviceInfoType, string> | null>;
readonly serialNumber: Data;
constructor(input: MIDIInput, output: MIDIOutput, info: DeviceInfo);
/** The device's serial number as a human-readable string */
get serialNumberString(): string;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Device = void 0;
const commands_1 = require("./commands");
const device_1 = require("./commands/device");
const get_info_1 = require("./commands/device/get-info");
const get_info_list_1 = require("./commands/device/get-info-list");
const connection_1 = require("./connection");

@@ -12,3 +8,3 @@ const data_1 = require("./util/data");

class Device extends connection_1.Connection {
constructor(input, output, info, supportedCommands) {
constructor(input, output, info) {
super(input, output);

@@ -18,34 +14,9 @@ this.input = input;

this.info = info;
this.supportedCommands = supportedCommands;
this.serialNumber = info.serialNumber;
}
get serialNumber() {
/** The device's serial number as a human-readable string */
get serialNumberString() {
return (0, data_1.formatData)(this.info.serialNumber);
}
supportsCommand(command) {
if (command === device_1.DeviceCommand.GetDevice ||
command === device_1.DeviceCommand.GetCommandList) {
return true;
}
return this.supportedCommands.includes(command);
}
getSupportedCommandNames() {
return this.supportedCommands.map((c) => (0, commands_1.getCommandName)(c));
}
async getAllInfo() {
const supportedInfo = await (0, get_info_list_1.getInfoList)({ device: this });
if (!supportedInfo) {
return null;
}
const info = await Promise.all(supportedInfo.map(async (infoType) => ({
infoType,
info: await (0, get_info_1.getInfo)({ device: this, infoType }),
})));
return info.reduce((acc, cur) => {
if (cur.info) {
acc[cur.infoType] = cur.info;
}
return acc;
}, {});
}
}
exports.Device = Device;

@@ -30,1 +30,6 @@ import { Device } from "./device";

}
export * from "./commands";
export * from "./types";
export * from "./util";
export * from "./connection";
export * from "./device";
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
var __importDefault = (this && this.__importDefault) || function (mod) {

@@ -9,3 +23,2 @@ return (mod && mod.__esModule) ? mod : { "default": mod };

const uniqBy_1 = __importDefault(require("lodash/uniqBy"));
const get_command_list_1 = require("./commands/device/get-command-list");
const get_device_1 = require("./commands/device/get-device");

@@ -60,9 +73,3 @@ const connection_1 = require("./connection");

if (deviceInfo) {
const supportedCommands = await (0, get_command_list_1.getCommandList)({
device,
serialNumber: deviceInfo.serialNumber,
});
if (supportedCommands) {
return new device_1.Device(input, output, deviceInfo, supportedCommands);
}
return new device_1.Device(input, output, deviceInfo);
}

@@ -73,3 +80,3 @@ }

}));
const devices = (0, uniqBy_1.default)(answers.filter(array_1.isTruthy), (d) => d.serialNumber);
const devices = (0, uniqBy_1.default)(answers.filter(array_1.isTruthy), (d) => d.serialNumberString);
return devices;

@@ -98,1 +105,6 @@ }

exports.DeviceManager = DeviceManager;
__exportStar(require("./commands"), exports);
__exportStar(require("./types"), exports);
__exportStar(require("./util"), exports);
__exportStar(require("./connection"), exports);
__exportStar(require("./device"), exports);
{
"name": "iconnectivity-js",
"version": "1.0.3",
"version": "1.1.0",
"main": "lib/index.js",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/leolabs/iconnectivity-js.git"
},
"scripts": {

@@ -7,0 +11,0 @@ "test": "jest",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc