<commit_before>var _ = require('lodash')
var inherits = require('util').inherits
var io = require('socket.io-client')
var Q = require('q')
// var ws = require('ws')

var Network = require('./network')
var errors = require('../errors')
var util = require('../util')
var yatc = require('../yatc')


/**
 * [Electrum api (WebSocket)]{@link https://github.com/fanatid/electrumjs-server}
 *
 * @class ElectrumWS
 * @extends Network
 *
 * @param {Object} [opts]
 * @param {string} [opts.networkName=bitcoin]
 * @param {string} [opts.url]
 */
function ElectrumWS(opts) {
  var self = this
  Network.call(self, opts)

  opts = _.extend({
    url: ElectrumWS.getURLs(self.getNetworkName())[0],
  }, opts)
  if (!_.isString(opts.url)) {
    throw new TypeError('Can\'t resolve network name `' + self.getNetworkName() + '` to url')
  }

  self._requestId = 0
  self._requests = {}
  self._lastResponse = Date.now()

  self._subscribedAddresses = {}

  self._socket = io(opts.url, {
    autoConnect: false,
    forceNew: true,
    reconnectionDelay: 10000,
    reconnectionDelayMax: 10000,
    randomizationFactor: 0,
    forceJSONP: false,
    jsonp: true,
    transports: ['polling']
    // transports: ws !== null ? ['websocket', 'polling'] : ['polling']
  })

  self._socket.on('connect', function () {
    self._setReadyState(self.OPEN)
  })

  self._socket.on('connect_error', function () {
    self._setReadyState(self.CLOSED)
    self.emit('error', new errors.ConnectionTimeout('ElectrumWS: connect_error'))
  })<commit_msg>add transports to ElectrumWS opts<commit_after>var _ = require('lodash')
var inherits = require('util').inherits
var io = require('socket.io-client')
var Q = require('q')
var ws = require('ws')

var Network = require('./network')
var errors = require('../errors')
var util = require('../util')
var yatc = require('../yatc')


/**
 * [Electrum api (WebSocket)]{@link https://github.com/fanatid/electrumjs-server}
 *
 * @class ElectrumWS
 * @extends Network
 *
 * @param {Object} [opts]
 * @param {string} [opts.networkName=bitcoin]
 * @param {string} [opts.url]
 * @param {string[]} [opts.transports] Socket.IO transports (polling, websocket)
 */
function ElectrumWS(opts) {
  var self = this
  Network.call(self, opts)

  opts = _.extend({
    url: ElectrumWS.getURLs(self.getNetworkName())[0],
    transports: ws !== null ? ['websocket', 'polling'] : ['polling']
  }, opts)
  if (!_.isString(opts.url)) {
    throw new TypeError('Can\'t resolve network name `' + self.getNetworkName() + '` to url')
  }

  self._requestId = 0
  self._requests = {}
  self._lastResponse = Date.now()

  self._subscribedAddresses = {}

  self._socket = io(opts.url, {
    autoConnect: false,
    forceNew: true,
    reconnectionDelay: 10000,
    reconnectionDelayMax: 10000,
    randomizationFactor: 0,
    forceJSONP: false,
    jsonp: true,
    transports: opts.transports
  })

  self._socket.on('connect', function () {
    self._setReadyState(self.OPEN)
  })

  self._socket.on('connect_error', function () {
    self._setReadyState(self.CLOSED)
    self.emit('error', new errors.ConnectionTimeout('ElectrumWS: connect_error'))
  })
{'fraction_non_alphanumeric': 0.16948072634597006, 'fraction_numerical': 0.00828289264096846, 'mean_word_length': 3.9139280125195617, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6115852', 'n_tokens_mistral': 1095, 'n_tokens_neox': 1046, 'n_words': 223}