25 lines
493 B
TypeScript
25 lines
493 B
TypeScript
import type {Relay} from './Relay'
|
|
import {EventBus} from './util/EventBus'
|
|
|
|
export class RelaySet {
|
|
relays: Relay[]
|
|
bus: EventBus
|
|
constructor(relays) {
|
|
this.relays = relays
|
|
this.bus = new EventBus()
|
|
|
|
relays.forEach(relay => {
|
|
relay.bus.pipe(EventBus.ANY, this.bus)
|
|
})
|
|
}
|
|
send(...payload) {
|
|
this.relays.forEach(async relay => {
|
|
await relay.connect()
|
|
|
|
if (relay.status === Relay.STATUS.READY) {
|
|
relay.send(...payload)
|
|
}
|
|
})
|
|
}
|
|
}
|