WS2801-client is a client for the WS2801-webserver package.
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();
-
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.
Sets the apiKey that will be used for the requests.
- apiKey
- Type: string
- The apiKey to be used.
Disconnects the socket.io client.
Returns whether authorization is required or not.
Whetger authorization is required or not.
- Type: Promise
Registers at the webserver.
-
username
- Type: string
- The username to use for registeration.
-
password
- Type: string
- The password to use for registeration.
The apiKey for the registered user.
- Type: Promise
Logs in to the webserver.
-
username
- Type: string
- The username to use when logging in.
-
password
- Type: string
- The password to use when logging in.
The apiKey for the logged in user.
- Type: Promise
Returns the current state of the led strip.
The current state of the led strip.
- Type: Promise<LedStrip>
Fills the entire led strip in one color.
-
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.
The current state of the led strip.
- Type: Promise<LedStrip>
Clears the entire led strip.
The current state of the led strip.
- Type: Promise<LedStrip>
Sets the color of a single led.
-
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.
The current state of the led strip.
- Type: Promise<LedStrip>
Sets a color for each led.
-
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.
The current state of the led strip.
- Type: Promise<LedStrip>
Sets the brightness of the led strip.
- brightness
- Type: number | 'auto'
- The brightness in percent to which the led strip should be set.
Returns the current brightness of the led strip.
The current brightness of the led strip.
- Type: Promise<number | 'auto'>
Starts an animation.
- 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 vialedAmount
.
A promise that resolves once the animation has started, which contains a finishPromise that resolves once the animation has finished.
Promise<{finishPromise: Promise}>
Stops the current animation, if an animation is running.
Resolves when the current animation is finished. If no animation is running, it resolves immediately.
Creates a listener with a callback that is executed each time the led strip is changed.
- callback
- Type: (ledStrip: LedStrip => void | Promise
- The callback to be called each time the led strip is changed.
The id of the created listener.
- Type: string
Creates a listener with a callback that is executed each time the brightness is changed.
- callback
- Type: (brightness: number) => void | Promise
- The callback to be called each time the brightness is changed.
The id of the created listener.
- Type: string
Removes a listener.
- id
- Type: string
- The id of the listener to be removed.