js-broadlink
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

Broadlink JS

Installation

npm install js-broadlink

Usage

  • As CLI: npx broadlink
  • As lib:

Example:

import { Setup, SecurityMode, Discover } from "js-broadlink";
const sleep = (s: number) => new Promise((resolve) => setTimeout(resolve, s * 1000));

// discover
async function discover() {
  const devices = [];
  const stream = Discover(1000); // wait for 1 second before closing
  stream.listen((device) => devices.push(device));
  await sleep(1);
  
  if (devices.length) {
    // use device here
    await devices[0].enterLearning();
    // read, send code etc...
  }
}

or callback style

import { Discover } from "js-broadlink";

// discover
function discover(callback) {
  const stream = Discover(); // wait indefinitely...
  const subscrption = stream.listen((device) => {
    subscription.cancel(); // cancels subscription after first device
    callback(device);
  });
}

async function myCallback(device) {
  await device.enterLearning();
  // read, send code etc...
}

discover(myCallback);

Readme

Keywords

Package Sidebar

Install

npm i js-broadlink

Weekly Downloads

0

Version

0.0.6

License

none

Unpacked Size

40.2 kB

Total Files

10

Last publish

Collaborators

  • davinche