@neurosity/sdk
Version:
Neurosity SDK
12 lines (11 loc) • 492 B
JavaScript
import { pipe, of, EMPTY } from "rxjs";
import { mergeMap, withLatestFrom } from "rxjs/operators";
export function whileOnline({ status$, allowWhileOnSleepMode }) {
return pipe(withLatestFrom(status$), mergeMap(([value, status]) => shouldAllowMetrics(status, allowWhileOnSleepMode)
? of(value)
: EMPTY));
}
function shouldAllowMetrics(status, allowWhileOnSleepMode) {
return (status.state === "online" &&
(allowWhileOnSleepMode ? true : !status.sleepMode));
}