<commit_before>import { NativeModules, DeviceEventEmitter } from 'react-native'
import { EventEmitter } from 'events'

const RNZeroconf = NativeModules.RNZeroconf

export default class Zeroconf extends EventEmitter {
  constructor(props) {
    super(props)

    this._services = {}
    this._publishedServices = {}
    this._dListeners = {}

    this.addDeviceListeners()
  }

  /**
   * Add all event listeners
   */
  addDeviceListeners() {
    if (Object.keys(this._dListeners).length) {
      return this.emit('error', new Error('RNZeroconf listeners already in place.'))
    }

    this._dListeners.start = DeviceEventEmitter.addListener('RNZeroconfStart', () =>
      this.emit('start'),
    )

    this._dListeners.stop = DeviceEventEmitter.addListener('RNZeroconfStop', () =>
      this.emit('stop'),
    )

    this._dListeners.error = DeviceEventEmitter.addListener('RNZeroconfError', err =>
      this.emit('error', err),
    )

    this._dListeners.found = DeviceEventEmitter.addListener('RNZeroconfFound', service => {
      if (!service || !service.name) {
        return
      }
      const { name } = service

      this._services[name] = service
      this.emit('found', name)
      this.emit('update')
    })

    this._dListeners.remove = DeviceEventEmitter.addListener('RNZeroconfRemove', service => {
      if (!service || !service.name) {
        return
      }
      const { name } = service

      delete this._services[name]

      this.emit('remove', name)
      this.emit('update')
    })

    this._dListeners.resolved = DeviceEventEmitter.addListener('RNZeroconfResolved', service => {
      if (!service || !service.name) {
        return
      }

      this._services[service.name] = service
      this.emit('resolved', service)
      this.emit('update')
    })

    this._dListeners.published = DeviceEventEmitter.addListener(
      'RNZeroconfServiceRegistered',
      service => {
        if (!service || !service.name) {
          return
        }

        this._publishedServices[service.name] = service
        this.emit('published', service)
      },
    )

    this._dListeners.unpublished = DeviceEventEmitter.addListener(
      'RNZeroconfServiceUnregistered',
      service => {
        if (!service || !service.name) {
          return
        }

        delete this._publishedServices[service.name]
        this.emit('unpublished', service)
      },
    )
  }

  /**
   * Remove all event listeners and clean map
   */
  removeDeviceListeners() {
    Object.keys(this._dListeners).forEach(name => this._dListeners[name].remove())
    this._dListeners = {}
  }

  /**
   * Get all the services already resolved
   */
  getServices() {
    return this._services
  }

  /**
   * Scan for Zeroconf services,
   * Defaults to _http._tcp. on local domain
   */
  scan(type = 'http', protocol = 'tcp', domain = 'local.') {
    this._services = {}
    this.emit('update')
    RNZeroconf.scan(type, protocol, domain)
  }

  /**
   * Stop current scan if any
   */
  stop() {
    RNZeroconf.stop()
  }

  /**
   * Publish a service
   */
  publishService(type, protocol, domain = 'local.', name, port, txt = {}) {
    RNZeroconf.registerService(type, protocol, domain, name, port, txt)
  }

  /**
   * Unpublish a service
   */
  unpublishService(name) {
    RNZeroconf.unregisterService(name)
  }
}<commit_msg>Convert all the values for TXT to strings (#125)<commit_after>import { NativeModules, DeviceEventEmitter } from 'react-native'
import { EventEmitter } from 'events'

const RNZeroconf = NativeModules.RNZeroconf

export default class Zeroconf extends EventEmitter {
  constructor(props) {
    super(props)

    this._services = {}
    this._publishedServices = {}
    this._dListeners = {}

    this.addDeviceListeners()
  }

  /**
   * Add all event listeners
   */
  addDeviceListeners() {
    if (Object.keys(this._dListeners).length) {
      return this.emit('error', new Error('RNZeroconf listeners already in place.'))
    }

    this._dListeners.start = DeviceEventEmitter.addListener('RNZeroconfStart', () =>
      this.emit('start'),
    )

    this._dListeners.stop = DeviceEventEmitter.addListener('RNZeroconfStop', () =>
      this.emit('stop'),
    )

    this._dListeners.error = DeviceEventEmitter.addListener('RNZeroconfError', err =>
      this.emit('error', err),
    )

    this._dListeners.found = DeviceEventEmitter.addListener('RNZeroconfFound', service => {
      if (!service || !service.name) {
        return
      }
      const { name } = service

      this._services[name] = service
      this.emit('found', name)
      this.emit('update')
    })

    this._dListeners.remove = DeviceEventEmitter.addListener('RNZeroconfRemove', service => {
      if (!service || !service.name) {
        return
      }
      const { name } = service

      delete this._services[name]

      this.emit('remove', name)
      this.emit('update')
    })

    this._dListeners.resolved = DeviceEventEmitter.addListener('RNZeroconfResolved', service => {
      if (!service || !service.name) {
        return
      }

      this._services[service.name] = service
      this.emit('resolved', service)
      this.emit('update')
    })

    this._dListeners.published = DeviceEventEmitter.addListener(
      'RNZeroconfServiceRegistered',
      service => {
        if (!service || !service.name) {
          return
        }

        this._publishedServices[service.name] = service
        this.emit('published', service)
      },
    )

    this._dListeners.unpublished = DeviceEventEmitter.addListener(
      'RNZeroconfServiceUnregistered',
      service => {
        if (!service || !service.name) {
          return
        }

        delete this._publishedServices[service.name]
        this.emit('unpublished', service)
      },
    )
  }

  /**
   * Remove all event listeners and clean map
   */
  removeDeviceListeners() {
    Object.keys(this._dListeners).forEach(name => this._dListeners[name].remove())
    this._dListeners = {}
  }

  /**
   * Get all the services already resolved
   */
  getServices() {
    return this._services
  }

  /**
   * Scan for Zeroconf services,
   * Defaults to _http._tcp. on local domain
   */
  scan(type = 'http', protocol = 'tcp', domain = 'local.') {
    this._services = {}
    this.emit('update')
    RNZeroconf.scan(type, protocol, domain)
  }

  /**
   * Stop current scan if any
   */
  stop() {
    RNZeroconf.stop()
  }

  /**
   * Publish a service
   */
  publishService(type, protocol, domain = 'local.', name, port, txt = {}) {
    if (Object.keys(txt).length !== 0) {
      Object.entries(txt).map(([key, value]) => txt[key] = value.toString());
    }

    RNZeroconf.registerService(type, protocol, domain, name, port, txt);
  }

  /**
   * Unpublish a service
   */
  unpublishService(name) {
    RNZeroconf.unregisterService(name)
  }
}
{'fraction_non_alphanumeric': 0.13470519556333918, 'fraction_numerical': 0.0005837711617046118, 'mean_word_length': 2.6863905325443787, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, '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': '4172951', 'n_tokens_mistral': 2130, 'n_tokens_neox': 2106, 'n_words': 385}