Files
api/packages/api-rx/src/api/connected.ts
T
Jaco Greeff e2365bb00a RxJS 6 (#123)
* RxJS 6

* Don't log observable promise.catch to console

* Extra space
2018-08-07 17:30:18 +02:00

17 lines
583 B
TypeScript

// Copyright 2017-2018 @polkadot/api-rx authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { ProviderInterface } from '@polkadot/api-provider/types';
import { BehaviorSubject } from 'rxjs';
export default function connected (provider: ProviderInterface): BehaviorSubject<boolean> {
const subject = new BehaviorSubject(provider.isConnected());
provider.on('connected', () => subject.next(true));
provider.on('disconnected', () => subject.next(false));
return subject;
}