Skip to content

Commit

Permalink
wip: remove lerna and fix typings
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Dec 24, 2020
1 parent 2e13ca6 commit 76da01d
Show file tree
Hide file tree
Showing 14 changed files with 1,612 additions and 3,313 deletions.
8 changes: 0 additions & 8 deletions lerna.json

This file was deleted.

15 changes: 9 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
"update-contrib": "weallcontribute -o . && git add CONTRIBUTING.md && git commit -m 'docs(contributing): updated CONTRIBUTING.md'",
"start-web": "cd packages/elgato-stream-deck-web-example && yarn start",
"dist-web": "cd packages/elgato-stream-deck-web-example && yarn dist",
"build": "yarn lerna run build",
"test": "yarn lerna run test",
"lint": "yarn lerna run lint"
"build": "yarn workspaces run build",
"test": "yarn workspaces run test",
"lint": "yarn workspaces run lint",
"dev": "yarn workspaces run build && node ./scripts/watch.js"
},
"devDependencies": {
"@sofie-automation/code-standard-preset": "^0.2.1",
"@types/jest": "^26.0.19",
"@types/jpeg-js": "^0.3.0",
"@types/sharp": "^0.26.1",
"coveralls": "^3.0.3",
"jest": "^26.6.3",
"jest-haste-map": "^26.6.2",
"jest-resolve": "^26.6.2",
"lerna": "^3.22.1",
"node-license-validator": "^1.3.0",
"open-cli": "^6.0.1",
"prettier": "^2.2.1",
Expand All @@ -41,7 +41,10 @@
},
"workspaces": {
"packages": [
"packages/*"
"packages/elgato-stream-deck-core",
"packages/elgato-stream-deck",
"packages/elgato-stream-deck-web",
"packages/elgato-stream-deck-web-example"
]
},
"dependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/elgato-stream-deck-core/src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export interface HIDDevice {

close(): Promise<void>

sendFeatureReport(data: number[]): Promise<void>
sendFeatureReport(data: Buffer): Promise<void>
getFeatureReport(reportId: number, reportLength: number): Promise<number[]>

sendReport(data: number[]): Promise<void>
sendReport(data: Buffer): Promise<void>
}
2 changes: 1 addition & 1 deletion packages/elgato-stream-deck-core/src/models/base-gen2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export abstract class StreamDeckGen2Base extends StreamDeckBase {
this.ICON_SIZE
)

return this.encodeJPEG(byteBuffer, this.ICON_SIZE, this.ICON_SIZE, this.options.jpegOptions)
return this.encodeJPEG(byteBuffer, this.ICON_SIZE, this.ICON_SIZE)
}

private transformCoordinates(x: number, y: number): { x: number; y: number } {
Expand Down
14 changes: 10 additions & 4 deletions packages/elgato-stream-deck-core/src/models/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export interface OpenStreamDeckOptions {
useOriginalKeyOrder?: boolean
resetToLogoOnExit?: boolean
encodeJPEG?: EncodeJPEGHelper
jpegOptions?: JPEGEncodeOptions
}

export interface StreamDeckProperties {
Expand Down Expand Up @@ -147,7 +146,6 @@ export abstract class StreamDeckBase extends EventEmitter implements StreamDeck
protected readonly device: HIDDevice
private readonly deviceProperties: Readonly<StreamDeckProperties>
// private readonly options: Readonly<OpenStreamDeckOptions>
private readonly releaseExitHook: () => void
private readonly keyState: boolean[]

constructor(device: HIDDevice, options: OpenStreamDeckOptions, properties: StreamDeckProperties) {
Expand Down Expand Up @@ -265,13 +263,21 @@ export abstract class StreamDeckBase extends EventEmitter implements StreamDeck

const pixels = Buffer.alloc(this.ICON_BYTES, 0)
const keyIndex2 = this.transformKeyIndex(keyIndex)
return this.fillImageRange(keyIndex2, pixels, 0, this.ICON_SIZE * 3)
return this.fillImageRange(keyIndex2, pixels, {
format: 'rgb',
offset: 0,
stride: this.ICON_SIZE * 3,
})
}

public async clearPanel(): Promise<void> {
const pixels = Buffer.alloc(this.ICON_BYTES, 0)
for (let keyIndex = 0; keyIndex < this.NUM_KEYS; keyIndex++) {
await this.fillImageRange(keyIndex, pixels, 0, this.ICON_SIZE * 3)
await this.fillImageRange(keyIndex, pixels, {
format: 'rgb',
offset: 0,
stride: this.ICON_SIZE * 3,
})
}
}

Expand Down
13 changes: 2 additions & 11 deletions packages/elgato-stream-deck-core/src/models/mini.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { HIDDevice } from '../device'
import { BMP_HEADER_LENGTH, imageToByteArray, writeBMPHeader } from '../util'
<<<<<<< HEAD:packages/elgato-stream-deck-core/src/models/mini.ts
import { OpenStreamDeckOptions, StreamDeckBase, StreamDeckProperties } from './base'
import { InternalFillImageOptions, OpenStreamDeckOptions, StreamDeckBase, StreamDeckProperties } from './base'
import { DeviceModelId, KeyIndex } from './id'
=======
import { OpenStreamDeckOptions, StreamDeckBase, StreamDeckProperties, InternalFillImageOptions } from './base'
import { DeviceModelId, KeyIndex, StreamDeckDeviceInfo } from './id'
>>>>>>> master:src/models/mini.ts

const miniProperties: StreamDeckProperties = {
MODEL: DeviceModelId.MINI,
Expand All @@ -26,11 +21,7 @@ export class StreamDeckMini extends StreamDeckBase {
return keyIndex
}

<<<<<<< HEAD:packages/elgato-stream-deck-core/src/models/mini.ts
protected convertFillImage(sourceBuffer: Buffer, sourceOffset: number, sourceStride: number): Promise<Buffer> {
=======
protected convertFillImage(sourceBuffer: Buffer, sourceOptions: InternalFillImageOptions): Buffer {
>>>>>>> master:src/models/mini.ts
protected convertFillImage(sourceBuffer: Buffer, sourceOptions: InternalFillImageOptions): Promise<Buffer> {
const byteBuffer = imageToByteArray(
sourceBuffer,
sourceOptions,
Expand Down
3 changes: 3 additions & 0 deletions packages/elgato-stream-deck-core/src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ export class StreamDeckProxy implements StreamDeck {
public get ICON_BYTES() {
return this.device.ICON_BYTES
}
public get ICON_PIXELS() {
return this.device.ICON_PIXELS
}
public get MODEL() {
return this.device.MODEL
}
Expand Down
4 changes: 2 additions & 2 deletions packages/elgato-stream-deck-core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"extends": "../../tsconfig.json",
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist"
},
"include": [
"src/**/*.ts"
]
}
}
4 changes: 2 additions & 2 deletions packages/elgato-stream-deck-web/src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ export class WebHIDDevice extends EventEmitter implements HIDDevice {
return this.device.close()
}

public sendFeatureReport(data: number[]): Promise<void> {
public sendFeatureReport(data: Buffer): Promise<void> {
return this.device.sendFeatureReport(data[0], new Uint8Array(data.slice(1)))
}
public getFeatureReport(reportId: number, reportLength: number): Promise<number[]> {
return this.device
.receiveFeatureReport(reportId, reportLength)
.then((view: DataView) => Array.from(new Uint8Array(view.buffer)))
}
public sendReport(data: number[]): Promise<void> {
public sendReport(data: Buffer): Promise<void> {
return this.device.sendReport(data[0], new Uint8Array(data.slice(1)))
}
}
4 changes: 2 additions & 2 deletions packages/elgato-stream-deck/src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export class NodeHIDDevice extends EventEmitter implements HIDDevice {
this.device.close()
}

public async sendFeatureReport(data: number[]): Promise<void> {
public async sendFeatureReport(data: Buffer): Promise<void> {
this.device.sendFeatureReport(data)
}
public async getFeatureReport(reportId: number, reportLength: number): Promise<number[]> {
return this.device.getFeatureReport(reportId, reportLength)
}
public async sendReport(data: number[]): Promise<void> {
public async sendReport(data: Buffer): Promise<void> {
this.device.write(data)
}
}
18 changes: 12 additions & 6 deletions packages/elgato-stream-deck/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
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 } from './jpeg'
import { encodeJPEG, JPEGEncodeOptions } from './jpeg'

export { DeviceModelId, KeyIndex, StreamDeck } from 'elgato-stream-deck-core'

export interface OpenStreamDeckOptionsNode extends OpenStreamDeckOptions {
jpegOptions?: JPEGEncodeOptions
}

/*
* The original StreamDeck uses packet sizes too large for the hidraw driver which is
* the default on linux. https://github.com/node-hid/node-hid/issues/249
Expand All @@ -17,7 +21,7 @@ HID.setDriverType('libusb')
export function listStreamDecks(): StreamDeckDeviceInfo[] {
const devices: StreamDeckDeviceInfo[] = []
for (const dev of HID.devices()) {
const model = DEVICE_MODELS.find(m => m.productId === dev.productId)
const model = DEVICE_MODELS.find((m) => m.productId === dev.productId)

if (model && dev.vendorId === VENDOR_ID && dev.path) {
devices.push({
Expand All @@ -37,7 +41,7 @@ export function getStreamDeckInfo(path: string): StreamDeckDeviceInfo | undefine
return listStreamDecks().find((dev) => dev.path === path)
}

export function openStreamDeck(devicePath?: string, userOptions?: OpenStreamDeckOptions): StreamDeck {
export function openStreamDeck(devicePath?: string, userOptions?: OpenStreamDeckOptionsNode): StreamDeck {
let foundDevices = listStreamDecks()
if (devicePath) {
foundDevices = foundDevices.filter((d) => d.path === devicePath)
Expand All @@ -51,16 +55,18 @@ export function openStreamDeck(devicePath?: string, userOptions?: OpenStreamDeck
}
}

const model = DEVICE_MODELS.find(m => m.id === foundDevices[0].model)
const model = DEVICE_MODELS.find((m) => m.id === foundDevices[0].model)
if (!model) {
throw new Error('Stream Deck is of unexpected type.')
}

// Clone the options, to ensure they dont get changed
const options: OpenStreamDeckOptions = { ...userOptions }
const options: OpenStreamDeckOptionsNode = { ...userOptions }

if (!options.encodeJPEG) {
options.encodeJPEG = encodeJPEG
const jpegOptions: JPEGEncodeOptions | undefined = options.jpegOptions ? { ...options.jpegOptions } : undefined
options.encodeJPEG = (buffer: Buffer, width: number, height: number) =>
encodeJPEG(buffer, width, height, jpegOptions)
}

const device = new NodeHIDDevice(foundDevices[0])
Expand Down
18 changes: 7 additions & 11 deletions packages/elgato-stream-deck/src/jpeg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ export interface JPEGEncodeOptions {

const DEFAULT_QUALITY = 95

export function encodeJPEG(buffer: Buffer, width: number, height: number,
options: JPEGEncodeOptions | undefined): Promise<Buffer> {
export function encodeJPEG(
buffer: Buffer,
width: number,
height: number,
options: JPEGEncodeOptions | undefined
): Promise<Buffer> {
try {
// Try using jpeg-turbo if it is available
if (jpegTurbo && jpegTurbo.bufferSize && jpegTurbo.compressSync) {
Expand All @@ -29,15 +33,7 @@ export function encodeJPEG(buffer: Buffer, width: number, height: number,
}
if (buffer.length === width * height * 4) {
const tmpBuffer = Buffer.alloc(jpegTurbo.bufferSize(encodeOptions))
return new Promise((resolve, reject) => {
jpegTurbo!.compress(buffer, tmpBuffer, encodeOptions, (err, resBuffer) => {
if (err) {
reject(err)
} else {
resolve(resBuffer)
}
})
})
return jpegTurbo.compress(buffer, tmpBuffer, encodeOptions)
}
}
} catch (e) {
Expand Down
40 changes: 40 additions & 0 deletions scripts/exec-tree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const concurrently = require('concurrently');

(async () => {
try {
console.log('Starting watchers');
// Now run everything
await concurrently(
[
{
command: 'yarn workspace @companion/module-framework watch',
name: 'FRAMEWORK',
},
{
command: `yarn workspace companion3 ${process.env.ELECTRON ? 'dev-electron' : 'dev-server'}`,
name: 'SERVER',
prefixColor: 'bgBlue.bold',
env: {
MONGO_URL: mongoUrl,
DEVELOPER: 1,
},
},
{
command: 'yarn workspace companion3 dev-client',
name: 'CLIENT',
prefixColor: 'bgGreen.bold',
},
],
{
prefix: 'name',
killOthers: ['failure', 'success'],
restartTries: 3,
},
);
console.log('Done!');
process.exit();
} catch (err) {
console.error(`Failure: ${err}`);
process.exit(1);
}
})();
Loading

0 comments on commit 76da01d

Please sign in to comment.