import { detect } from 'detect-browser' ; import { DEVICE_MODELS , DeviceModelId , OpenStreamDeckOptions , StreamDeck , VENDOR_ID } from '@elgato-stream-deck/core' ; import { WebHIDDevice } from './device' ; import { encodeJPEG } from './jpeg' ; import { StreamDeckWeb } from './wrapper' ; export { DeviceModelId , KeyIndex , StreamDeck } from '@elgato-stream-deck/core' ; export { StreamDeckWeb } from './wrapper' ; param userOptions export async function requestStreamDecks ( options ? ) { return navigator . hid . requestDevice ( { filters : [ { vendorId : VENDOR_ID , } , ] , } ) . then ( async ( browserDevices ) => { return Promise . all ( browserDevices . map ( async ( dev ) => openDevice ( dev , options ) ) ) ; } ) ; } param options export async function getStreamDecks ( options ? ) { return navigator . hid . getDevices ( ) . then ( async ( browserDevices ) => { return Promise . all ( browserDevices . map ( async ( dev ) => openDevice ( dev , options ) ) ) ; } ) ; } param browserDevice param userOptions export async function openDevice ( browserDevice , userOptions ? ) { const model = DEVICE_MODELS . find ( ( m ) => m . productId === browserDevice . productId ) ; if ( ! model ) { throw new Error ( 'Stream Deck is of unexpected type.' ) ; } if ( model . id === DeviceModelId . ORIGINAL ) { const browser = detect ( ) ; if ( browser && browser . os === 'Linux' ) { throw new Error ( 'This is not supported on linux' ) ; } } await browserDevice . open ( ) ; const options = { useOriginalKeyOrder : false , encodeJPEG : encodeJPEG , ... userOptions , } ; const device = new model . class ( new WebHIDDevice ( browserDevice ) , options || { } ) ; return new StreamDeckWeb ( device ) ; }