Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it("Should zip multiple command arrays correctly", async () => {
const fleshlightMap = new Map();
const fleshlightCommands = [new FleshlightLaunchFW12Cmd(10, 20),
new FleshlightLaunchFW12Cmd(20, 30),
new FleshlightLaunchFW12Cmd(30, 40)];
fleshlightMap.set(1, [fleshlightCommands[0]]);
fleshlightMap.set(3, [fleshlightCommands[1]]);
fleshlightMap.set(5, [fleshlightCommands[2]]);
fleshlightMap.set(10, [fleshlightCommands[0]]);
const vibrateMap = new Map();
const vibrateCommands = [new SingleMotorVibrateCmd(10),
new SingleMotorVibrateCmd(20),
new SingleMotorVibrateCmd(30)];
vibrateMap.set(1, [vibrateCommands[0]]);
vibrateMap.set(2, [vibrateCommands[1]]);
vibrateMap.set(4, [vibrateCommands[2]]);
// Map with no messages
const emptyMap = new Map();
const commandArray = HapticCommandToButtplugMessage.ZipCommandMaps([fleshlightMap, vibrateMap, emptyMap]);
const expectedCommandArray = new Map();
expectedCommandArray.set(1, [fleshlightCommands[0], vibrateCommands[0]]);
expectedCommandArray.set(2, [vibrateCommands[1]]);
expectedCommandArray.set(3, [fleshlightCommands[1]]);
expectedCommandArray.set(4, [vibrateCommands[2]]);
expectedCommandArray.set(5, [fleshlightCommands[2]]);
expectedCommandArray.set(10, [fleshlightCommands[0]]);
expect(commandArray).to.deep.equal(expectedCommandArray);
expect(Array.from(commandArray.keys())).to.deep.equal([1, 2, 3, 4, 5, 10]);
it("Should zip multiple command arrays correctly", async () => {
const fleshlightMap = new Map();
const fleshlightCommands = [new FleshlightLaunchFW12Cmd(10, 20),
new FleshlightLaunchFW12Cmd(20, 30),
new FleshlightLaunchFW12Cmd(30, 40)];
fleshlightMap.set(1, [fleshlightCommands[0]]);
fleshlightMap.set(3, [fleshlightCommands[1]]);
fleshlightMap.set(5, [fleshlightCommands[2]]);
fleshlightMap.set(10, [fleshlightCommands[0]]);
const vibrateMap = new Map();
const vibrateCommands = [new SingleMotorVibrateCmd(10),
new SingleMotorVibrateCmd(20),
new SingleMotorVibrateCmd(30)];
vibrateMap.set(1, [vibrateCommands[0]]);
vibrateMap.set(2, [vibrateCommands[1]]);
vibrateMap.set(4, [vibrateCommands[2]]);
// Map with no messages
const emptyMap = new Map();
const commandArray = HapticCommandToButtplugMessage.ZipCommandMaps([fleshlightMap, vibrateMap, emptyMap]);
const expectedCommandArray = new Map();
expectedCommandArray.set(1, [fleshlightCommands[0], vibrateCommands[0]]);
expectedCommandArray.set(2, [vibrateCommands[1]]);
expectedCommandArray.set(3, [fleshlightCommands[1]]);
expectedCommandArray.set(4, [vibrateCommands[2]]);
expectedCommandArray.set(5, [fleshlightCommands[2]]);
expectedCommandArray.set(10, [fleshlightCommands[0]]);
expect(commandArray).to.deep.equal(expectedCommandArray);
it("Should zip multiple command arrays correctly", async () => {
const fleshlightMap = new Map();
const fleshlightCommands = [new FleshlightLaunchFW12Cmd(10, 20),
new FleshlightLaunchFW12Cmd(20, 30),
new FleshlightLaunchFW12Cmd(30, 40)];
fleshlightMap.set(1, [fleshlightCommands[0]]);
fleshlightMap.set(3, [fleshlightCommands[1]]);
fleshlightMap.set(5, [fleshlightCommands[2]]);
fleshlightMap.set(10, [fleshlightCommands[0]]);
const vibrateMap = new Map();
const vibrateCommands = [new SingleMotorVibrateCmd(10),
new SingleMotorVibrateCmd(20),
new SingleMotorVibrateCmd(30)];
vibrateMap.set(1, [vibrateCommands[0]]);
vibrateMap.set(2, [vibrateCommands[1]]);
vibrateMap.set(4, [vibrateCommands[2]]);
// Map with no messages
const emptyMap = new Map();
const commandArray = HapticCommandToButtplugMessage.ZipCommandMaps([fleshlightMap, vibrateMap, emptyMap]);
const expectedCommandArray = new Map();
expectedCommandArray.set(1, [fleshlightCommands[0], vibrateCommands[0]]);
expectedCommandArray.set(2, [vibrateCommands[1]]);
expectedCommandArray.set(3, [fleshlightCommands[1]]);
expectedCommandArray.set(4, [vibrateCommands[2]]);
expectedCommandArray.set(5, [fleshlightCommands[2]]);
expectedCommandArray.set(10, [fleshlightCommands[0]]);
expect(commandArray).to.deep.equal(expectedCommandArray);
expect(Array.from(commandArray.keys())).to.deep.equal([1, 2, 3, 4, 5, 10]);
});
it("Should zip multiple command arrays correctly", async () => {
const fleshlightMap = new Map();
const fleshlightCommands = [new FleshlightLaunchFW12Cmd(10, 20),
new FleshlightLaunchFW12Cmd(20, 30),
new FleshlightLaunchFW12Cmd(30, 40)];
fleshlightMap.set(1, [fleshlightCommands[0]]);
fleshlightMap.set(3, [fleshlightCommands[1]]);
fleshlightMap.set(5, [fleshlightCommands[2]]);
fleshlightMap.set(10, [fleshlightCommands[0]]);
const vibrateMap = new Map();
const vibrateCommands = [new SingleMotorVibrateCmd(10),
new SingleMotorVibrateCmd(20),
new SingleMotorVibrateCmd(30)];
vibrateMap.set(1, [vibrateCommands[0]]);
vibrateMap.set(2, [vibrateCommands[1]]);
vibrateMap.set(4, [vibrateCommands[2]]);
// Map with no messages
const emptyMap = new Map();
const commandArray = HapticCommandToButtplugMessage.ZipCommandMaps([fleshlightMap, vibrateMap, emptyMap]);
const expectedCommandArray = new Map();
it("Should zip multiple command arrays correctly", async () => {
const fleshlightMap = new Map();
const fleshlightCommands = [new FleshlightLaunchFW12Cmd(10, 20),
new FleshlightLaunchFW12Cmd(20, 30),
new FleshlightLaunchFW12Cmd(30, 40)];
fleshlightMap.set(1, [fleshlightCommands[0]]);
fleshlightMap.set(3, [fleshlightCommands[1]]);
fleshlightMap.set(5, [fleshlightCommands[2]]);
fleshlightMap.set(10, [fleshlightCommands[0]]);
const vibrateMap = new Map();
const vibrateCommands = [new SingleMotorVibrateCmd(10),
new SingleMotorVibrateCmd(20),
new SingleMotorVibrateCmd(30)];
vibrateMap.set(1, [vibrateCommands[0]]);
vibrateMap.set(2, [vibrateCommands[1]]);
vibrateMap.set(4, [vibrateCommands[2]]);
// Map with no messages
const emptyMap = new Map();
const commandArray = HapticCommandToButtplugMessage.ZipCommandMaps([fleshlightMap, vibrateMap, emptyMap]);
const expectedCommandArray = new Map();
expectedCommandArray.set(1, [fleshlightCommands[0], vibrateCommands[0]]);
it("Should zip multiple command arrays correctly", async () => {
const fleshlightMap = new Map();
const fleshlightCommands = [new FleshlightLaunchFW12Cmd(10, 20),
new FleshlightLaunchFW12Cmd(20, 30),
new FleshlightLaunchFW12Cmd(30, 40)];
fleshlightMap.set(1, [fleshlightCommands[0]]);
fleshlightMap.set(3, [fleshlightCommands[1]]);
fleshlightMap.set(5, [fleshlightCommands[2]]);
fleshlightMap.set(10, [fleshlightCommands[0]]);
const vibrateMap = new Map();
const vibrateCommands = [new SingleMotorVibrateCmd(10),
new SingleMotorVibrateCmd(20),
new SingleMotorVibrateCmd(30)];
vibrateMap.set(1, [vibrateCommands[0]]);
vibrateMap.set(2, [vibrateCommands[1]]);
vibrateMap.set(4, [vibrateCommands[2]]);
// Map with no messages
const emptyMap = new Map();
const commandArray = HapticCommandToButtplugMessage.ZipCommandMaps([fleshlightMap, vibrateMap, emptyMap]);
async function main() {
process.on("unhandledRejection", (reason, p) => {
console.log("Unhandled Rejection at: Promise", p, "reason:", reason);
// application specific logging, throwing an error, or other logic here
});
commander
.version("0.0.1-alpha")
.parse(process.argv);
let res;
const p = new Promise((resolve, reject) => { res = resolve });
const bs = new ButtplugServer();
bs.AddDeviceManager(new ButtplugNodeBluetoothLEDeviceManager());
const localConnector = new ButtplugEmbeddedServerConnector();
localConnector.Server = bs;
const bc = new ButtplugClient("Buttplug Local Client");
await bc.Connect(localConnector);
bc.on("deviceadded", (d) => {
console.log(`Device Found: ${d.Name}`);
res();
});
console.log("starting scan");
await bc.StartScanning();
console.log("scanning");
await p;
console.log("Found a device, exiting.")
await bc.Disconnect();
process.exit();
}
async function main() {
process.on("unhandledRejection", (reason, p) => {
console.log("Unhandled Rejection at: Promise", p, "reason:", reason);
// application specific logging, throwing an error, or other logic here
});
commander
.version("0.0.1-alpha")
.parse(process.argv);
let res;
const p = new Promise((resolve, reject) => { res = resolve });
const bs = new ButtplugServer();
bs.AddDeviceManager(new ButtplugNodeBluetoothLEDeviceManager());
const localConnector = new ButtplugEmbeddedServerConnector();
localConnector.Server = bs;
const bc = new ButtplugClient("Buttplug Local Client");
await bc.Connect(localConnector);
bc.on("deviceadded", (d) => {
console.log(`Device Found: ${d.Name}`);
res();
});
console.log("starting scan");
await bc.StartScanning();
console.log("scanning");
await p;
console.log("Found a device, exiting.")
await bc.Disconnect();
process.exit();
}
async function main() {
process.on("unhandledRejection", (reason, p) => {
console.log("Unhandled Rejection at: Promise", p, "reason:", reason);
// application specific logging, throwing an error, or other logic here
});
commander
.version("0.0.1-alpha")
.parse(process.argv);
let res;
const p = new Promise((resolve, reject) => { res = resolve });
const bs = new ButtplugServer();
bs.AddDeviceManager(new ButtplugNodeBluetoothLEDeviceManager());
const localConnector = new ButtplugEmbeddedServerConnector();
localConnector.Server = bs;
const bc = new ButtplugClient("Buttplug Local Client");
await bc.Connect(localConnector);
bc.on("deviceadded", (d) => {
console.log(`Device Found: ${d.Name}`);
res();
});
console.log("starting scan");
await bc.StartScanning();
console.log("scanning");
await p;
console.log("Found a device, exiting.")
await bc.Disconnect();
process.exit();
continue;
}
// If no characteristics are present in the DeviceInfo block, we assume that
// we're connecting to a simple rx/tx service, and can query to figure out
// characteristics. Assume that the characteristics have tx/rx references.
const characteristics = await discoverCharsAsync([]);
for (const char of characteristics) {
if (char.properties.indexOf("write") !== -1 ||
char.properties.indexOf("writeWithoutResponse") !== -1 ||
char.properties.indexOf("reliableWrite") !== -1) {
this._characteristics.set(Endpoints.Tx, char);
} else if (char.properties.indexOf("read") !== -1 ||
char.properties.indexOf("broadcast") !== -1 ||
char.properties.indexOf("notify") !== -1 ||
char.properties.indexOf("indicate") !== -1) {
this._characteristics.set(Endpoints.Rx, char);
}
}
}
if (this._characteristics.size === 0) {
const err = `No characteristics found for device ${this.Name}, cannot communicate with device.`;
throw new ButtplugDeviceException(err);
}
this._device.once("disconnect", () => {
this.emit("deviceremoved");
});
}