UNPKG

@ledgerhq/live-common

Version:
50 lines 1.99 kB
import { Observable, ReplaySubject } from "rxjs"; import { Device } from "./types"; export declare enum ImplementationType { event = "enum", polling = "polling" } type ImplementationEvent = { type: "deviceChange"; device?: Device | undefined | null; } | { type: "unresponsiveDevice"; } | { type: "error"; error: Error; }; type PollingImplementationConfig = { pollingFrequency: number; initialWaitTime: number; reconnectWaitTime: number; connectionTimeout: number; }; type PollingImplementationParams<Request, EmittedEvents> = { deviceSubject: ReplaySubject<Device | null | undefined>; task: (params: { deviceId: string; deviceName: string | null; request: Request; }) => Observable<EmittedEvents>; request: Request; config?: PollingImplementationConfig; retryableWithDelayDisconnectedErrors?: ReadonlyArray<ErrorConstructor>; }; export declare const defaultImplementationConfig: PollingImplementationConfig; type Implementation = <EmittedEvent, GenericRequestType>(params: PollingImplementationParams<GenericRequestType, EmittedEvent>) => Observable<EmittedEvent | ImplementationEvent>; export type EmittedEvent<T> = { type: string; } & T; /** * Returns a polling implementation function that repeatedly performs a given task * with a given request, with a specified polling frequency and wait times until a * KO or OK end state is reached. This emulates the event based connection paradigm * from the USB stack in a BLE setting. * @template EmittedEvent - Type of the events emitted by the task's observable. * @template GenericRequestType - Type of the request to be passed to the task. **/ declare const pollingImplementation: Implementation; declare const eventImplementation: Implementation; declare const getImplementation: (currentMode: string) => Implementation; export { pollingImplementation, eventImplementation, getImplementation }; //# sourceMappingURL=implementations.d.ts.map