<commit_before>'use strict'

// const debug = require('debug')
// const log = debug('libp2p:tcp')
const SWS = require('simple-websocket')
const mafmt = require('mafmt')

exports = module.exports = WebSockets

function WebSockets () {
  if (!(this instanceof WebSockets)) {
    return new WebSockets()
  }

  const listeners = []

  this.dial = function (multiaddr, options) {
    if (!options) {
      options = {}
    }

    options.ready = options.ready || function noop () {}
    const maOpts = multiaddr.toOptions()
    const conn = new SWS('ws://' + maOpts.host + ':' + maOpts.port)
    conn.on('connect', options.ready)
    conn.getObservedAddrs = () => {
      return [multiaddr]
    }
    return conn
  }

  this.createListener = (multiaddrs, options, handler, callback) => {
    if (typeof options === 'function') {
      callback = handler
      handler = options
      options = {}
    }

    if (!Array.isArray(multiaddrs)) {
      multiaddrs = [multiaddrs]
    }

    var count = 0

    multiaddrs.forEach((m) => {
      const listener = SWS.createServer((conn) => {
        conn.getObservedAddrs = () => {
          return [] // TODO think if it makes sense for WebSockets
        }
        handler(conn)
      })

      listener.listen(m.toOptions().port, () => {
        if (++count === multiaddrs.length) {
          callback()
        }
      })
      listeners.push(listener)
    })
  }

  this.close = (callback) => {
    if (listeners.length === 0) {
      callback(new Error('there are no listeners'))
    }
    var count = 0<commit_msg>chore: release version v0.4.1<commit_after>'use strict'

const debug = require('debug')
const log = debug('libp2p:websockets')
const SWS = require('simple-websocket')
const mafmt = require('mafmt')

exports = module.exports = WebSockets

function WebSockets () {
  if (!(this instanceof WebSockets)) {
    return new WebSockets()
  }

  const listeners = []

  this.dial = function (multiaddr, options) {
    if (!options) {
      options = {}
    }

    options.ready = options.ready || function noop () {}
    const maOpts = multiaddr.toOptions()
    const conn = new SWS('ws://' + maOpts.host + ':' + maOpts.port)
    conn.on('connect', options.ready)
    conn.getObservedAddrs = () => {
      return [multiaddr]
    }
    return conn
  }

  this.createListener = (multiaddrs, options, handler, callback) => {
    if (typeof options === 'function') {
      callback = handler
      handler = options
      options = {}
    }

    if (!Array.isArray(multiaddrs)) {
      multiaddrs = [multiaddrs]
    }

    var count = 0

    multiaddrs.forEach((m) => {
      const listener = SWS.createServer((conn) => {
        conn.getObservedAddrs = () => {
          return [] // TODO think if it makes sense for WebSockets
        }
        handler(conn)
      })

      listener.listen(m.toOptions().port, () => {
        if (++count === multiaddrs.length) {
          callback()
        }
      })
      listeners.push(listener)
    })
  }

  this.close = (callback) => {
    if (listeners.length === 0) {
      log('Called close with no active listeners')
      return callback()
    }
    var count = 0
{'fraction_non_alphanumeric': 0.14597846738442052, 'fraction_numerical': 0.0034832172260924636, 'mean_word_length': 2.407766990291262, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, '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': '5779211', 'n_tokens_mistral': 995, 'n_tokens_neox': 976, 'n_words': 225}