elgato-stream-deck
elgato-stream-deck
is a Node.js library for interfacing
with the various models of the Elgato Stream Deck.
❗ Please note that node-elgato-stream-deck
is NOT a standalone application. It is not something you download and run on its own. It is not an alternative to the official Stream Deck program provided by Elgato. Instead, node-elgato-stream-deck
is a code library which provides an API to the Stream Deck. Developers can use this API to make their own applications which interface with the Stream Deck.
To further clarify: this is not an installable program. There is no user interface, and you cannot do anything with this library on its own. Out of the box, this library does nothing. It's purpose is to provide tools for programmers to build programs from the ground up which interact with a Stream Deck.
This is a tool for developers to use. It is not a program for end users. It cannot and will not replace the official Stream Deck program. That is not its goal. However, it does enable someone to more easily write a program which does do that.
Install
$ npm install --save elgato-stream-deck
$ npm install --save @julusian/jpeg-turbo@^1.0.0
(Optional)
It is recommended to install @julusian/jpeg-turbo
to greatly improve performance for writing images to the StreamDeck XL or the Original-v2. Without doing so jpeg-js
will be used instead, but image transfers will be noticably more cpu intensive and slower. jpeg-turbo
has prebuilt binaries, but is not installed by default to ensure installation is easy for users who do not need the performance or the XL or the Original-v2.
Linux
On linux, the udev subsystem blocks access to the StreamDeck without some special configuration.
Save the following to /etc/udev/rules.d/50-elgato.rules
and reload the rules with sudo udevadm control --reload-rules
SUBSYSTEM=="input", GROUP="input", MODE="0666"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fd9", ATTRS{idProduct}=="0060", MODE:="666", GROUP="plugdev"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fd9", ATTRS{idProduct}=="0063", MODE:="666", GROUP="plugdev"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fd9", ATTRS{idProduct}=="006c", MODE:="666", GROUP="plugdev"
SUBSYSTEM=="usb", ATTRS{idVendor}=="0fd9", ATTRS{idProduct}=="006d", MODE:="666", GROUP="plugdev"
Unplug and replug the device and it should be usable
Native dependencies
All of this library's native dependencies ship with prebuilt binaries, so having a full compiler toolchain should not be necessary to install node-elgato-stream-deck
.
However, in the event that installation does fail (or if you are on a platform that our dependencies don't provide prebuilt binaries for, such as a Raspberry Pi), you will need to install a compiler toolchain to enable npm to build some of node-elgato-stream-deck
's dependencies from source. Expand the details block below for full instructions on how to do so.
Compiling dependencies from source
Table of Contents
Features
- Multiplatform support: Windows 7-10, MacOS, Linux, and even Raspberry Pi!
- Support for every StreamDeck model (Original, Mini & XL)
- Key
down
and key up
events - Fill keys with images or solid RGB colors
- Fill the entire panel with a single image, spread across all keys
- Set the Stream Deck brightness
- TypeScript support
Example
JavaScript
const path = require('path')
const { openStreamDeck } = require('elgato-stream-deck')
const myStreamDeck = openStreamDeck()
myStreamDeck.on('down', (keyIndex) => {
console.log('key %d down', keyIndex)
})
myStreamDeck.on('up', (keyIndex) => {
console.log('key %d up', keyIndex)
})
myStreamDeck.on('error', (error) => {
console.error(error)
})
myStreamDeck.fillColor(4, 255, 0, 0)
console.log('Successfully wrote a red square to key 4.')
TypeScript
import { openStreamDeck } = require('elgato-stream-deck')
const myStreamDeck = openStreamDeck()
myStreamDeck.on('down', keyIndex => {
console.log('key %d down', keyIndex)
})
myStreamDeck.on('up', keyIndex => {
console.log('key %d up', keyIndex)
})
myStreamDeck.on('error', error => {
console.error(error)
})
API
> openStreamDeck(path?: string, options?: OpenStreamDeckOptions) -> StreamDeckDeviceInfo | undefined
Opens a StreamDeck.
If a path is provided, then a specific device will be opened, otherwise the first found device will be used. See listDevices for info on how to discover devices.
Some device types have additional options, as part of the options object. This is not required to be provided.
Options:
- useOriginalKeyOrder: This restores the right-to-left key order for the Original StreamDeck. Since v3.0.0 the default key order has been changed to make sense and be consistent with the other models
const streamDeck = openStreamDeck()
const streamDeck = openStreamDeck('0001:0021:00')
const streamDeck = openStreamDeck('0001:0021:00', {
useOriginalKeyOrder: true,
})
> listStreamDecks() -> Array<StreamDeckDeviceInfo>
This will scan for and list all detected StreamDeck devices on the system along with their model. The path property can be passed into the constructor to open a specific device.
console.log('Devices: ', listStreamDecks())
> getStreamDeckInfo(path: string) -> StreamDeckDeviceInfo | undefined
Get the info for a given device. Returns undefined
if the path is not a valid StreamDeck
console.log('Info: ', getStreamDeckInfo('0001:0021:00'))
> streamDeck.fillColor(keyIndex, r, g, b) -> undefined
Synchronously sets the given keyIndex
's screen to a solid RGB color.
An error will be thrown if the keyIndex is not valid, of a colour component is outside of the range 0-255
Example
streamDeck.fillColor(4, 255, 0, 0)
> streamDeck.fillImage(keyIndex, buffer) -> undefined
Synchronously writes a buffer of RGB image data to the given keyIndex
's screen.
The required size of the buffer varies by device, and must be the exact length. Any other length will result in an error being thrown.
The expected sizes are:
- Original: 15552 (72px)
- Mini: 19200 (80px)
- XL: 27648 (96px)
Example
const sharp = require('sharp')
sharp(path.resolve(__dirname, 'github_logo.png'))
.flatten()
.resize(streamDeck.ICON_SIZE, streamDeck.ICON_SIZE)
.raw()
.toBuffer()
.then((buffer) => {
streamDeck.fillImage(2, buffer)
})
.catch((err) => {
console.error(err)
})
> streamDeck.fillPanel(buffer) -> undefined
Applies an image to the entire panel, spreading it over all keys. The image must be exactly the correct resolution for your device. Any other size will result in an error being thrown.
Example
const sharp = require('sharp')
sharp(path.resolve(__dirname, 'github_logo.png'))
.flatten()
.resize(streamDeck.ICON_SIZE * streamDeck.KEY_COLUMNS, streamDeck.ICON_SIZE * streamDeck.KEY_ROWS)
.raw()
.toBuffer()
.then((buffer) => {
streamDeck.fillPanel(buffer)
})
.catch((err) => {
console.error(err)
})
> streamDeck.clearKey(keyIndex) -> undefined
Synchronously clears the given keyIndex
's screen.
An error will be thrown if the keyIndex is not valid
Example
streamDeck.clearKey(2)
> streamDeck.clearAllKeys() -> undefined
Synchronously clears all keys on the device.
Example
streamDeck.clearAllKeys()
> streamDeck.setBrightness(percentage) -> undefined
Synchronously set the brightness of the Stream Deck. This affects all keys at once. The brightness of individual keys cannot be controlled.
An error will be thrown if the brightness is not in the range 0-100
Example
streamDeck.setBrightness(100)
> streamDeck.resetToLogo() -> undefined
Resets the device back to the startup Elgato logo.
Example
streamDeck.resetToLogo()
> streamDeck.getFirmwareVersion() -> string
Gets the firmware version number.
Example
console.log(streamDeck.getFirmwareVersion())
> streamDeck.getSerialNumber() -> string
Gets the serial number of the device.
Example
console.log(streamDeck.getSerialNumber())
Events
> down
Fired whenever a key is pressed. keyIndex
is the index of that key.
Example
streamDeck.on('down', (keyIndex) => {
console.log('key %d down', keyIndex)
})
> up
Fired whenever a key is released. keyIndex
is the index of that key.
Example
streamDeck.on('up', (keyIndex) => {
console.log('key %d up', keyIndex)
})
> error
Fired whenever an error is detected by the node-hid
library.
Always add a listener for this event! If you don't, errors will be silently dropped.
Example
streamDeck.on('error', (error) => {
console.error(error)
})
Contributing
The elgato-stream-deck team enthusiastically welcomes contributions and project participation! There's a bunch of things you can do if you want to contribute! Please don't hesitate to jump in if you'd like to, or even ask us questions if something isn't clear.
Please refer to the Changelog for project history details, too.
Protocol Notes
Raw protocol notes can be found in NOTES.md. These detail the protocol and method for interacting with the Stream Deck which this module implements.