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;
}
/**
* @name WsProvider
* @summary The WebSocket Provider allows sending requests using WebSocket.
* @description 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} autoConnect Whether to connect automatically or not.
*/
constructor(endpoint: string, autoConnect?: boolean);
/**
* @summary Manually connect
* @description The [[WsProvider]] connects automatically by default, however if you decided otherwise, you may
* connect manually using this method.
*/
connect(): void;
/**
* @summary Whether the node is connected or not.
* @return {boolean} true if connected
*/
isConnected(): boolean;
/**
* @summary 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;
/**
* @summary Send JSON data using WebSockets to configured HTTP Endpoint or queue.
*/
send(method: string, params: Array
* 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