UNPKG

@plugnet/rpc-rx

Version:
43 lines (42 loc) 1.47 kB
import { ProviderInterface } from '@plugnet/rpc-provider/types'; import { RpcRxInterface, RpcRxInterface$Events, RpcRxInterface$Section } from './types'; import { BehaviorSubject } from 'rxjs'; import Rpc from '@plugnet/rpc-core'; /** * @name RpcRx * @summary The RxJS API is a wrapper around the API. * @description It allows wrapping API components with observables using RxJS. * * @example * <BR> * * ```javascript * import RpcRx from '@plugnet/rpc-rx'; * import WsProvider from '@plugnet/rpc-provider/ws'; * * const provider = new WsProvider('http://127.0.0.1:9944'); * const api = new RpcRx(provider); * ``` */ export default class RpcRx implements RpcRxInterface { private _api; private _eventemitter; private _isConnected; readonly author: RpcRxInterface$Section; readonly chain: RpcRxInterface$Section; readonly state: RpcRxInterface$Section; readonly system: RpcRxInterface$Section; /** * @param {ProviderInterface} provider An API provider using HTTP or WebSocket */ constructor(providerOrRpc?: Rpc | ProviderInterface); isConnected(): BehaviorSubject<boolean>; on(type: RpcRxInterface$Events, handler: (...args: Array<any>) => any): void; protected emit(type: RpcRxInterface$Events, ...args: Array<any>): void; private initEmitters; private createInterface; private createObservable; private createReplay; private createReplayCallback; private createReplayUnsub; }