UNPKG

rxpoweredup

Version:

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

12 lines (11 loc) 602 B
import { map, switchMap } from 'rxjs'; import { container } from 'tsyringe'; import { HubFactory } from '../hub'; import { HubScannerFactory } from './hub-scanner-factory'; import { registerServices } from './register-service'; export function connectHub(bluetooth, config) { registerServices(container); const scannerFactory = container.resolve(HubScannerFactory).create(bluetooth); const hubFactory = container.resolve(HubFactory); return scannerFactory.discoverHub().pipe(map((device) => hubFactory.create(device, config)), switchMap((hub) => hub.connect().pipe(map(() => hub)))); }