Skip to content

Commit

Permalink
feat: All heos connection commands can be chained
Browse files Browse the repository at this point in the history
  • Loading branch information
juliuscc committed Jan 26, 2019
1 parent a5f4ff6 commit 4e5a26c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/connection/heosConnection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HeosEventEmitter } from '../listen/responseEventHandler'
import { HeosEventEmitter, HeosConnectionEventEmitter } from '../listen/responseEventHandler'
import { HeosCommandAttribute } from '../types'
import { generateHeosCommand } from '../write/heosCommand'

Expand All @@ -8,13 +8,19 @@ export class HeosConnection {
once: HeosEventEmitter,
socketWrite: (message: string) => any
) {
this.on = on
this.once = once
this.on = (event, listener) => {
on(event, listener)
return this
}
this.once = (event, listener) => {
once(event, listener)
return this
}
this.socketWrite = socketWrite
}

on: HeosEventEmitter
once: HeosEventEmitter
on: HeosConnectionEventEmitter
once: HeosConnectionEventEmitter
private socketWrite: (message: string) => any

write(
Expand Down
6 changes: 6 additions & 0 deletions src/listen/responseEventHandler.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { HeosResponse, HeosEvent, HeosCommand } from '../types'
import { EventEmitter } from 'events'
import { generateHeosCommandString } from './heosCommand'
import { HeosConnection } from '../connection/heosConnection'

export type HeosConnectionEventEmitter = (
event: HeosCommand,
listener: (message: HeosResponse | HeosEvent) => void
) => HeosConnection

export type HeosEventEmitter = (
event: HeosCommand,
Expand Down

0 comments on commit 4e5a26c

Please sign in to comment.