import { DEVICE_MODELS , OpenStreamDeckOptions , StreamDeck , VENDOR_ID } from '@elgato-stream-deck/core' ; import * as HID from 'node-hid' ; import { NodeHIDDevice , StreamDeckDeviceInfo } from './device' ; import { encodeJPEG , JPEGEncodeOptions } from './jpeg' ; import { StreamDeckNode } from './wrapper' ; export { DeviceModelId , KeyIndex , StreamDeck } from '@elgato-stream-deck/core' ; export interface OpenStreamDeckOptionsNode extends OpenStreamDeckOptions { jpegOptions ? : JPEGEncodeOptions ; resetToLogoOnClose ? : boolean ; } HID . setDriverType ( 'libusb' ) ; /**
 * Scan for and list detected devices
 */ export function listStreamDecks ( ) { const devices = [ ] ; for ( const dev of HID . devices ( ) ) { const model = DEVICE_MODELS . find ( ( m ) => m . productId === dev . productId ) ; if ( model && dev . vendorId === VENDOR_ID && dev . path ) { devices . push ( { model : model . id , path : dev . path , serialNumber : dev . serialNumber , } ) ; } } return devices ; } /**
 * Get the info of a device if the given path is a streamdeck
 */ export function getStreamDeckInfo ( path ) { return listStreamDecks ( ) . find ( ( dev ) => dev . path === path ) ; } param devicePath param userOptions export function openStreamDeck ( devicePath ? , userOptions ? ) { let foundDevices = listStreamDecks ( ) ; if ( devicePath ) { foundDevices = foundDevices . filter ( ( d ) => d . path === devicePath ) ; } if ( foundDevices . length === 0 ) { if ( devicePath ) { throw new Error ( `Device "${ devicePath }" was not found` ) ; } else { throw new Error ( 'No Stream Decks are connected.' ) ; } } const model = DEVICE_MODELS . find ( ( m ) => m . id === foundDevices [ 0 ] . model ) ; if ( ! model ) { throw new Error ( 'Stream Deck is of unexpected type.' ) ; } const jpegOptions = userOptions ?. jpegOptions ? { ... userOptions . jpegOptions } : undefined ; const options = { useOriginalKeyOrder : false , encodeJPEG : async ( buffer , width , height ) => encodeJPEG ( buffer , width , height , jpegOptions ) , ... userOptions , } ; const device = new NodeHIDDevice ( foundDevices [ 0 ] ) ; const rawSteamdeck = new model . class ( device , options || { } ) ; return new StreamDeckNode ( rawSteamdeck , userOptions ?. resetToLogoOnClose ?? false ) ; }