From 22e52b8d1ae8d5c9264586c4a6e3d28bf0fd9f0e Mon Sep 17 00:00:00 2001 From: Sam Lanning Date: Tue, 19 Mar 2019 21:14:02 -0700 Subject: [PATCH] Stricter tsconfig.json --- src/behaviour/display.ts | 2 +- src/behaviour/interval.ts | 8 ++--- src/config/home.ts | 66 +++++++++++++++++++-------------------- src/listener/listener.ts | 18 ++++++----- src/main.ts | 2 +- src/tsconfig.json | 5 +-- 6 files changed, 51 insertions(+), 50 deletions(-) diff --git a/src/behaviour/display.ts b/src/behaviour/display.ts index 4b6ca22..a1e5fdb 100644 --- a/src/behaviour/display.ts +++ b/src/behaviour/display.ts @@ -211,7 +211,7 @@ export class Display { // Mapping form universe to buffers private readonly buffers: {[id: number]: Int8Array} = {}; private readonly layout: Layout; - private playState: SimplePlayState | null; + private playState: SimplePlayState | null = null; private readonly transitionInterval: Interval; private readonly colorInterval: Interval; diff --git a/src/behaviour/interval.ts b/src/behaviour/interval.ts index d740d84..a7b2d15 100644 --- a/src/behaviour/interval.ts +++ b/src/behaviour/interval.ts @@ -5,8 +5,7 @@ export class Interval { private callee: () => void; private intervalMs: number; private enabled = true; - private timeout: NodeJS.Timer; - private next: number; + private timeout: NodeJS.Timer | null = null; private lightDesk: { group: lightDesk.Group; @@ -39,16 +38,15 @@ export class Interval { } private trigger() { - clearTimeout(this.timeout); + if (this.timeout !== null) clearTimeout(this.timeout); this.callee(); this.resetTimeout(); } private resetTimeout() { - clearTimeout(this.timeout); + if (this.timeout !== null) clearTimeout(this.timeout); if (this.enabled && this.intervalMs > 0) { this.timeout = setTimeout(this.trigger, this.intervalMs); - this.next = new Date().getTime() + this.intervalMs; } } } diff --git a/src/config/home.ts b/src/config/home.ts index a3357d5..1cfb07b 100644 --- a/src/config/home.ts +++ b/src/config/home.ts @@ -1,6 +1,6 @@ -import {Channel, Fixture, Config} from './'; +import {Channel, Config} from './'; -const fixtures: Fixture[] = []; +// const fixtures: Fixture[] = []; const simpleRgbFixtureChannels: Channel[] = [ {kind: 'color', color: 'r'}, @@ -8,39 +8,39 @@ const simpleRgbFixtureChannels: Channel[] = [ {kind: 'color', color: 'b'} ]; -const simpleRgbFixtureChannels2: Channel[] = [ - {kind: 'static', value: 255}, // dimmer - {kind: 'color', color: 'r'}, - {kind: 'color', color: 'g'}, - {kind: 'color', color: 'b'} -]; +// const simpleRgbFixtureChannels2: Channel[] = [ +// {kind: 'static', value: 255}, // dimmer +// {kind: 'color', color: 'r'}, +// {kind: 'color', color: 'g'}, +// {kind: 'color', color: 'b'} +// ]; -const movingHeadOneFixtureChannels: Channel[] = [ - {kind: 'movement', dimension: 'level'}, - {kind: 'static', value: 0}, - {kind: 'movement', dimension: 'vertical'}, - {kind: 'static', value: 0}, - {kind: 'speed'}, - {kind: 'static', value: 255}, // dimmer - {kind: 'strobe'}, - {kind: 'color', color: 'r'}, - {kind: 'color', color: 'g'}, - {kind: 'color', color: 'b'}, - {kind: 'color', color: 'w'} -]; +// const movingHeadOneFixtureChannels: Channel[] = [ +// {kind: 'movement', dimension: 'level'}, +// {kind: 'static', value: 0}, +// {kind: 'movement', dimension: 'vertical'}, +// {kind: 'static', value: 0}, +// {kind: 'speed'}, +// {kind: 'static', value: 255}, // dimmer +// {kind: 'strobe'}, +// {kind: 'color', color: 'r'}, +// {kind: 'color', color: 'g'}, +// {kind: 'color', color: 'b'}, +// {kind: 'color', color: 'w'} +// ]; -const movingHeadTwoFixtureChannels: Channel[] = [ - {kind: 'movement', dimension: 'level'}, - {kind: 'static', value: 0}, - {kind: 'movement', dimension: 'vertical'}, - {kind: 'static', value: 0}, - {kind: 'speed'}, - {kind: 'static', value: 255}, // strobe / dimmer - {kind: 'color', color: 'r'}, - {kind: 'color', color: 'g'}, - {kind: 'color', color: 'b'}, - {kind: 'color', color: 'w'} -]; +// const movingHeadTwoFixtureChannels: Channel[] = [ +// {kind: 'movement', dimension: 'level'}, +// {kind: 'static', value: 0}, +// {kind: 'movement', dimension: 'vertical'}, +// {kind: 'static', value: 0}, +// {kind: 'speed'}, +// {kind: 'static', value: 255}, // strobe / dimmer +// {kind: 'color', color: 'r'}, +// {kind: 'color', color: 'g'}, +// {kind: 'color', color: 'b'}, +// {kind: 'color', color: 'w'} +// ]; const config: Config = { fixtures: [ diff --git a/src/listener/listener.ts b/src/listener/listener.ts index 2339240..ae261dc 100644 --- a/src/listener/listener.ts +++ b/src/listener/listener.ts @@ -25,15 +25,22 @@ export type StateListener = (state: messages.PlayStateData | null, getFile: (has // } // } -export class SynesthesiaConsumerClient { +export class SynesthesiaListener { + + private readonly stateUpdated: StateListener; + public constructor(stateUpdated: StateListener) { + this.stateUpdated = stateUpdated; + } + + public connectToServer() { const ws = new WebSocket(`ws://localhost:${constants.DEFAULT_SYNESTHESIA_PORT}/listen`); ws.addEventListener('open', () => { const endpoint = new DownstreamEndpoint( msg => ws.send(JSON.stringify(msg)), state => { console.log('new state', state); - stateUpdated(state, getFile); + this.stateUpdated(state, getFile); } ); const getFile = endpoint.getFile.bind(endpoint); @@ -45,15 +52,10 @@ export class SynesthesiaConsumerClient { // TODO console.error(err); }); - ws.addEventListener('close', err => { + ws.addEventListener('close', _err => { // TODO }); } } -export class SynesthesiaListener { - public constructor(stateUpdated: StateListener) { - const server = new SynesthesiaConsumerClient(stateUpdated); - } -} diff --git a/src/main.ts b/src/main.ts index 4219ab9..1ed8cd9 100644 --- a/src/main.ts +++ b/src/main.ts @@ -12,7 +12,7 @@ const proxy = new DmxProxy(PYTHON_PROXY); const display = new Display(getConfig(), proxy); -const consumer = new SynesthesiaListener(display.newSynesthesiaPlayState); +new SynesthesiaListener(display.newSynesthesiaPlayState).connectToServer(); display.run(); diff --git a/src/tsconfig.json b/src/tsconfig.json index f3c86d1..4eefa1d 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -6,9 +6,10 @@ "isolatedModules": false, "experimentalDecorators": false, "declaration": true, - "noImplicitAny": true, "noImplicitUseStrict": false, - "strictNullChecks": true, + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, "removeComments": true, "noLib": false, "preserveConstEnums": true,