How to use the buttplug.ButtplugServer function in buttplug

To help you get started, we’ve selected a few buttplug examples, based on popular ways it is used in public projects.

github buttplugio / buttplug-js / packages / buttplug-server-cli / src / local.ts View on Github external
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();