Stream Deck API
Stream Deck API is a library that allows you to interact with an Elgato Stream Deck controller.
package.json
):
NOTE: API is not stable and will not follow semver until version >=1.0.0. If you need a specific version, hard-lock it to an exact version for now (in "dependencies":
Examples
Detect Button Press
const streamDeckDeckApi = ;var streamDeck = streamDeckApi; // -----------------------------------// Individual button presses by number// -----------------------------------streamDeck;streamDeck; // -------------------------------------------------------------// Individual button presses, button number as callback argument// -------------------------------------------------------------streamDeck; streamDeck; // -----------------------------------------------------// Button state changed, callback with all button states// -----------------------------------------------------streamDeck; // ----------------------------------------// Synchronous function to get button state// ----------------------------------------var buttonState = streamDeck;if buttonState8 == 1 console ;if buttonState8 == 0 console ;
Draw Image or Color to Button
const streamDeckDeckApi = ;var streamDeck = streamDeckApi;var buttonNumber = 2; // -------------------------// Draw image from file path// -------------------------streamDeck; // --------------------------// Draw image from raw buffer// --------------------------var buffer = ;var isRGBA = true; // buffer is in RGBA format where each pixel uses 4 bytes in the bufferstreamDeck; // ----------------------------------------------// Draw pure color, colors provided as hex values// ----------------------------------------------streamDeck; // blackstreamDeck; // redstreamDeck; // greenstreamDeck; // bluestreamDeck; // white
API
TODO: Write API docs
Caching
TODO: Clean this up
Quick and dirty explanation: Because it takes a non-trivial amount of time to process an image (reading it from disk and resizing it) and to create the data that gets sent to the Stream Deck, caching has been implemented in order to speed up this process.
You won't see the caching/non-caching effects if you draw to only one button; it's too quick to notice. However, if you draw to all 15 buttons at once, you'll notice that without caching (for example, the first time you draw to all the buttons), there will be a ripple effect as the buttons draw one after another. With caching enabled (currently forced and no way to disable), they will be drawn instantly.
Caching is currently enabled in two places:
-
By image path. If you call
streamDeck.drawImageFile()
, the image will be opened, resized, and the raw buffer data cached. Subsequent calls tostreamDeck.drawImageFile()
with the same path will load the cached data instead. This means that if you alter the image without restarting the app, it won't have any effect because the cached data is used, not the disk copy. The ability to disable this cache selectively or globally will be added in the future. -
By image buffer contents. Before the image is sent to the Stream Deck, it must be split into two byte arrays. The byte arrays are cached once constructed, with the cache key being the image buffer hash. This means that the same image buffer will create the same byte arrays, and so the byte arrays are cached. The ability to disable this cache selectively or globally will be added in the future, which can be useful if you're dynamically generating a lot of image buffers (for example, displaying dynamic text in a button).