npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ws2801-client

v1.0.0

Published

A client for the webserver for the WS2801-Pi module.

Downloads

14

Readme

WS2801-client

WS2801-client is a client for the WS2801-webserver package.

Usage

import {LedColor, WS2801Client} from './src/index';

const client: WS2801Client = new WS2801Client('http://localhost:45451');

async function register(): Promise<void> {
  if (!(await client.loginRequired())) {
    console.log('No registration needed.');

    return;
  }

  const apiKey: string = await client.register('<username>', '<password>');

  console.log(`Successfully registered (${apiKey}).`);
}

async function turnLightOn(): Promise<void> {
  const red: LedColor = {
    red: 255,
    green: 0,
    blue: 0,
  };

  await client.fillLedStrip(red);

  console.log('Ledstrip is now red.');
}

async function run(): Promise<void> {
  await register();
  await turnLightOn();
}
run();

Functions

Constructor

Parameters:

  • baseUrl

    • Type: string
    • The url of the WS2801-webserver.
  • apiKey

    • optional
    • Type: string
    • The apiKey to be used for authorization on the webserver.
      • If a valid apiKey is set in the constructor, registration and login is not required.

setApiKey

Sets the apiKey that will be used for the requests.

Parameters

  • apiKey
    • Type: string
    • The apiKey to be used.

dispose

Disconnects the socket.io client.

loginRequired

Returns whether authorization is required or not.

Returns

Whetger authorization is required or not.

  • Type: Promise

register

Registers at the webserver.

Parameters

  • username

    • Type: string
    • The username to use for registeration.
  • password

    • Type: string
    • The password to use for registeration.

Returns

The apiKey for the registered user.

  • Type: Promise

login

Logs in to the webserver.

Parameters

  • username

    • Type: string
    • The username to use when logging in.
  • password

    • Type: string
    • The password to use when logging in.

Returns

The apiKey for the logged in user.

  • Type: Promise

getLedStrip

Returns the current state of the led strip.

Returns

The current state of the led strip.

fillLedStrip

Fills the entire led strip in one color.

Parameters

  • color

    • Type: LedColor
    • The color that the led strip should become.
  • brightness

    • optional
    • Type: number | 'auto'
    • The brightness in percent to which the led strip should be set.

Returns

The current state of the led strip.

clearLedStrip

Clears the entire led strip.

Returns

The current state of the led strip.

setLed

Sets the color of a single led.

Parameters

  • ledIndex

    • Type: number
    • The index of the led to be changed.
  • brightness

    • optional
    • Type: number | 'auto'
    • The brightness in percent to set the led strip to.

Returns

The current state of the led strip.

setLedStrip

Sets a color for each led.

Parameters

  • ledStrip

    • Type: LedStrip
    • An array of LedColors. Must contain exactly one entry for each led.
  • brightness

    • optional
    • Type: number | 'auto'
    • The brightness in percent to set the led strip to.

Returns

The current state of the led strip.

setBrightness

Sets the brightness of the led strip.

Parameters

  • brightness
    • Type: number | 'auto'
    • The brightness in percent to which the led strip should be set.

getBrightness

Returns the current brightness of the led strip.

Returns

The current brightness of the led strip.

  • Type: Promise<number | 'auto'>

startAnimation

Starts an animation.

Parameters

  • animationScript
    • Type: string
    • The animation script that should be executed. The animation script can access the LED controller via ledController and the amount of Leds via ledAmount.

Returns

A promise that resolves once the animation has started, which contains a finishPromise that resolves once the animation has finished.

Promise<{finishPromise: Promise}>

stopAnimation

Stops the current animation, if an animation is running.

waitForAnimationToFinish

Resolves when the current animation is finished. If no animation is running, it resolves immediately.

Listeners

onLedStripChanged

Creates a listener with a callback that is executed each time the led strip is changed.

Parameters

  • callback
    • Type: (ledStrip: LedStrip => void | Promise
    • The callback to be called each time the led strip is changed.

Returns

The id of the created listener.

  • Type: string

onBrightnessChanged

Creates a listener with a callback that is executed each time the brightness is changed.

Parameters

  • callback
    • Type: (brightness: number) => void | Promise
    • The callback to be called each time the brightness is changed.

Returns

The id of the created listener.

  • Type: string

removeListener

Removes a listener.

Parameters

  • id
    • Type: string
    • The id of the listener to be removed.