UNPKG

rxpoweredup

Version:

A Typescript RxJS-based library for controlling LEGO Powered UP hubs & peripherals.

23 lines (22 loc) 1.02 kB
import { filter, map, shareReplay } from 'rxjs'; import { HubActionType } from '../../constants'; export class HubActionsFeature { hubActionsMessageFactory; messenger; willDisconnect; willSwitchOff; constructor(hubActionsMessageFactory, messenger, inboundMessages) { this.hubActionsMessageFactory = hubActionsMessageFactory; this.messenger = messenger; this.willDisconnect = inboundMessages.pipe(filter((m) => m.actionType === HubActionType.willDisconnect), map(() => void 0), shareReplay(1)); this.willSwitchOff = inboundMessages.pipe(filter((m) => m.actionType === HubActionType.willSwitchOff), map(() => void 0), shareReplay(1)); } disconnect() { const message = this.hubActionsMessageFactory.createDisconnectMessage(); return this.messenger.sendWithoutResponse(message); } switchOff() { const message = this.hubActionsMessageFactory.createSwitchOffMessage(); return this.messenger.sendWithoutResponse(message); } }