import { ProviderInterface, ProviderInterface$Callback, ProviderInterface$Emitted, ProviderInterface$EmitCb } from '../types'; import './polyfill'; import E3 from 'eventemitter3'; declare type SubscriptionHandler = { callback: ProviderInterface$Callback; type: string; }; interface WSProviderInterface extends ProviderInterface { connect(): void; } /** * The WebSocket Provider allows sending requests using WebSocket. Unlike the [[HttpProvider]], * it does support subscriptions and allows listening to events such as new blocks or balance changes. * * @example * import createApi from '@polkadot/api'; * import WsProvider from '@polkadot/api-provider/ws'; * const provider = new WsProvider('ws://127.0.0.1:9944'); * const api = createApi(provider); * * @see [[HttpProvider]] */ export default class WsProvider extends E3.EventEmitter implements WSProviderInterface { private autoConnect; private coder; private endpoint; private handlers; private _isConnected; private l; private queued; private subscriptions; private websocket; /** * @param {string} endpoint The endpoint url. Usually `ws://ip:9944` or `wss://ip:9944` * @param {boolean = true} autoConnect Whether to connect automatically or not. */ constructor(endpoint: string, autoConnect?: boolean); /** * The [[WsProvider]] connects automatically by default. if you decided otherwise, you may * connect manually using this method. */ connect(): void; /** * Whether the node is connected or not. * @return {boolean} true if connected */ isConnected(): boolean; /** * Listens on events after having subscribed using the [[subscribe]] function. * @param {ProviderInterface$Emitted} type Event * @param {ProviderInterface$EmitCb} sub Callback * @return {this} [description] */ on(type: ProviderInterface$Emitted, sub: ProviderInterface$EmitCb): this; send(method: string, params: Array, subscription?: SubscriptionHandler): Promise; /** * Allows subscribing to a specific event. * @param {string} type Subscription type * @param {string} method Subscription method * @param {Array} params Parameters * @param {ProviderInterface$Callback} callback Callback * @return {Promise} Promise resolving to the dd of the subscription you can use with [[unsubscribe]]. * * @example * const provider = new WsProvider('ws://127.0.0.1:9944'); * const api = createApi(provider); * * api.state.storage([[storage.balances.freeBalance,
]], (_, values) => { * console.log(values) * }).then((subscriptionId) => { * console.log('balance changes subscription id: ', subscriptionId) * }) */ subscribe(type: string, method: string, params: Array, callback: ProviderInterface$Callback): Promise; /** * Allows unsubscribing to subscriptions made with [[subscribe]]. */ unsubscribe(type: string, method: string, id: number): Promise; private onSocketClose; private onSocketError; private onSocketMessage; private onSocketMessageResult; private onSocketMessageSubscribe; private onSocketOpen; } export {};