From f7ce68ea5b88b8abe6e737bf5c5a3c4ffb6ceb5a Mon Sep 17 00:00:00 2001 From: Julian Waller Date: Mon, 30 Oct 2023 22:26:48 +0000 Subject: [PATCH] chore: use interface for client in device implementations --- src/client.ts | 4 ++-- src/device-types/api.ts | 14 +++++++++----- src/device-types/infinitton.ts | 5 ++--- src/device-types/loupedeck-live-s.ts | 5 ++--- src/device-types/loupedeck-live.ts | 5 ++--- src/device-types/razer-stream-controller-x.ts | 5 ++--- src/device-types/streamdeck.ts | 5 ++--- src/device-types/xencelabs-quick-keys.ts | 5 ++--- 8 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/client.ts b/src/client.ts index 7ef6055..21364d8 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1,6 +1,6 @@ import { EventEmitter } from 'eventemitter3' import { Socket } from 'net' -import { ClientCapabilities, DeviceDrawProps, DeviceRegisterProps } from './device-types/api' +import { ClientCapabilities, CompanionClient, DeviceDrawProps, DeviceRegisterProps } from './device-types/api' import { DEFAULT_PORT } from './lib' import * as semver from 'semver' @@ -87,7 +87,7 @@ export type CompanionSatelliteClientEvents = { deviceErrored: [{ deviceId: string; message: string }] } -export class CompanionSatelliteClient extends EventEmitter { +export class CompanionSatelliteClient extends EventEmitter implements CompanionClient { private readonly debug: boolean private socket: Socket | undefined diff --git a/src/device-types/api.ts b/src/device-types/api.ts index 941bf86..6aa5f84 100644 --- a/src/device-types/api.ts +++ b/src/device-types/api.ts @@ -1,5 +1,3 @@ -import { CompanionSatelliteClient } from '../client' - export type DeviceId = string export interface DeviceDrawProps { @@ -25,7 +23,7 @@ export interface WrappedDevice { close(): Promise - initDevice(client: CompanionSatelliteClient, status: string): Promise + initDevice(client: CompanionClient, status: string): Promise updateCapabilities(capabilities: ClientCapabilities): void @@ -53,6 +51,12 @@ export interface ClientCapabilities { readonly useCustomBitmapResolution: boolean } -// export interface CompanionClient { +export interface CompanionClient { + get host(): string + + keyDown(deviceId: string, keyIndex: number): void + keyUp(deviceId: string, keyIndex: number): void -// } + rotateLeft(deviceId: string, keyIndex: number): void + rotateRight(deviceId: string, keyIndex: number): void +} diff --git a/src/device-types/infinitton.ts b/src/device-types/infinitton.ts index fc01e9f..3bf37b6 100644 --- a/src/device-types/infinitton.ts +++ b/src/device-types/infinitton.ts @@ -1,6 +1,5 @@ -import { CompanionSatelliteClient } from '../client' import { CardGenerator } from '../cards' -import { ClientCapabilities, DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api' +import { ClientCapabilities, CompanionClient, DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api' import Infinitton = require('infinitton-idisplay') import * as imageRs from '@julusian/image-rs' @@ -37,7 +36,7 @@ export class InfinittonWrapper implements WrappedDevice { async close(): Promise { this.#panel.close() } - async initDevice(client: CompanionSatelliteClient, status: string): Promise { + async initDevice(client: CompanionClient, status: string): Promise { console.log('Registering key events for ' + this.deviceId) this.#panel.on('down', (key) => client.keyDown(this.deviceId, key)) this.#panel.on('up', (key) => client.keyUp(this.deviceId, key)) diff --git a/src/device-types/loupedeck-live-s.ts b/src/device-types/loupedeck-live-s.ts index e5a3715..e7cadb1 100644 --- a/src/device-types/loupedeck-live-s.ts +++ b/src/device-types/loupedeck-live-s.ts @@ -1,9 +1,8 @@ import { LoupedeckDevice, LoupedeckDisplayId, LoupedeckBufferFormat, LoupedeckModelId } from '@loupedeck/node' import * as imageRs from '@julusian/image-rs' -import { CompanionSatelliteClient } from '../client' import { CardGenerator } from '../cards' import { ImageWriteQueue } from '../writeQueue' -import { ClientCapabilities, DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api' +import { ClientCapabilities, CompanionClient, DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api' export class LoupedeckLiveSWrapper implements WrappedDevice { readonly #cardGenerator: CardGenerator @@ -87,7 +86,7 @@ export class LoupedeckLiveSWrapper implements WrappedDevice { this.#queue?.abort() await this.#deck.close() } - async initDevice(client: CompanionSatelliteClient, status: string): Promise { + async initDevice(client: CompanionClient, status: string): Promise { const convertButtonId = (type: 'button' | 'rotary', id: number): number => { if (type === 'button') { // return 24 + id diff --git a/src/device-types/loupedeck-live.ts b/src/device-types/loupedeck-live.ts index fc55941..d13cb22 100644 --- a/src/device-types/loupedeck-live.ts +++ b/src/device-types/loupedeck-live.ts @@ -1,9 +1,8 @@ import { LoupedeckDevice, LoupedeckDisplayId, LoupedeckBufferFormat, LoupedeckModelId } from '@loupedeck/node' import * as imageRs from '@julusian/image-rs' -import { CompanionSatelliteClient } from '../client' import { CardGenerator } from '../cards' import { ImageWriteQueue } from '../writeQueue' -import { ClientCapabilities, DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api' +import { ClientCapabilities, CompanionClient, DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api' export class LoupedeckLiveWrapper implements WrappedDevice { readonly #cardGenerator: CardGenerator @@ -91,7 +90,7 @@ export class LoupedeckLiveWrapper implements WrappedDevice { this.#queue?.abort() await this.#deck.close() } - async initDevice(client: CompanionSatelliteClient, status: string): Promise { + async initDevice(client: CompanionClient, status: string): Promise { const convertButtonId = (type: 'button' | 'rotary', id: number, rotarySecondary: boolean): number => { if (type === 'button' && id >= 0 && id < 8) { return 24 + id diff --git a/src/device-types/razer-stream-controller-x.ts b/src/device-types/razer-stream-controller-x.ts index ee1ba07..062b993 100644 --- a/src/device-types/razer-stream-controller-x.ts +++ b/src/device-types/razer-stream-controller-x.ts @@ -1,9 +1,8 @@ import { LoupedeckDevice, LoupedeckDisplayId, LoupedeckBufferFormat, LoupedeckModelId } from '@loupedeck/node' import * as imageRs from '@julusian/image-rs' -import { CompanionSatelliteClient } from '../client' import { CardGenerator } from '../cards' import { ImageWriteQueue } from '../writeQueue' -import { ClientCapabilities, DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api' +import { ClientCapabilities, CompanionClient, DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api' export class RazerStreamControllerXWrapper implements WrappedDevice { readonly #cardGenerator: CardGenerator @@ -87,7 +86,7 @@ export class RazerStreamControllerXWrapper implements WrappedDevice { this.#queue?.abort() await this.#deck.close() } - async initDevice(client: CompanionSatelliteClient, status: string): Promise { + async initDevice(client: CompanionClient, status: string): Promise { const convertButtonId = (type: 'button' | 'rotary', id: number): number => { if (type === 'button') { return id diff --git a/src/device-types/streamdeck.ts b/src/device-types/streamdeck.ts index bed6fd1..5d50e05 100644 --- a/src/device-types/streamdeck.ts +++ b/src/device-types/streamdeck.ts @@ -1,9 +1,8 @@ import { DeviceModelId, StreamDeck } from '@elgato-stream-deck/node' import * as imageRs from '@julusian/image-rs' -import { CompanionSatelliteClient } from '../client' import { CardGenerator } from '../cards' import { ImageWriteQueue } from '../writeQueue' -import { ClientCapabilities, DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api' +import { ClientCapabilities, CompanionClient, DeviceDrawProps, DeviceRegisterProps, WrappedDevice } from './api' export class StreamDeckWrapper implements WrappedDevice { readonly #cardGenerator: CardGenerator @@ -120,7 +119,7 @@ export class StreamDeckWrapper implements WrappedDevice { this.#queue?.abort() await this.#deck.close() } - async initDevice(client: CompanionSatelliteClient, status: string): Promise { + async initDevice(client: CompanionClient, status: string): Promise { console.log('Registering key events for ' + this.deviceId) this.#deck.on('down', (key) => client.keyDown(this.deviceId, key)) this.#deck.on('up', (key) => client.keyUp(this.deviceId, key)) diff --git a/src/device-types/xencelabs-quick-keys.ts b/src/device-types/xencelabs-quick-keys.ts index ef206a1..ad78d74 100644 --- a/src/device-types/xencelabs-quick-keys.ts +++ b/src/device-types/xencelabs-quick-keys.ts @@ -5,8 +5,7 @@ import { XencelabsQuickKeysDisplayOrientation, WheelEvent, } from '@xencelabs-quick-keys/node' -import { CompanionSatelliteClient } from '../client' -import { WrappedDevice, DeviceRegisterProps, DeviceDrawProps, ClientCapabilities } from './api' +import { WrappedDevice, DeviceRegisterProps, DeviceDrawProps, ClientCapabilities, CompanionClient } from './api' function keyToCompanion(k: number): number | null { if (k >= 0 && k < 4) return k + 1 @@ -52,7 +51,7 @@ export class QuickKeysWrapper implements WrappedDevice { await this.#surface.stopData() } - async initDevice(client: CompanionSatelliteClient, status: string): Promise { + async initDevice(client: CompanionClient, status: string): Promise { console.log('Registering key events for ' + this.deviceId) const handleDown = (key: number) => {