UNPKG

717 BJavaScriptView Raw
1"use strict";
2
3// Copyright 2017-2018 Jaco Greeff
4// This software may be modified and distributed under the terms
5// of the ISC license. See the LICENSE file for details.
6const EventEmitter = require('eventemitter3');
7
8const assert = require('@polkadot/util/assert');
9
10const l = require('@polkadot/util/logger')('api-ws');
11
12const coder = require('../coder/json');
13
14module.exports = function state(endpoint, autoConnect) {
15 assert(/^(wss|ws):\/\//.test(endpoint), `Endpoint should start with 'ws://', received '${endpoint}'`);
16 return {
17 autoConnect,
18 coder: coder(),
19 emitter: new EventEmitter(),
20 endpoint,
21 handlers: {},
22 isConnected: false,
23 l,
24 queued: {},
25 subscriptions: {}
26 };
27};
\No newline at end of file