Skip to content
This repository has been archived by the owner on Jul 21, 2023. It is now read-only.

Commit

Permalink
fix: remove use of assert module (#87)
Browse files Browse the repository at this point in the history
The polyfill is big, we can simulate it by throwing an Error and it doesn't work under React Native.
  • Loading branch information
achingbrain authored Feb 17, 2020
1 parent bea3dd1 commit e362b04
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/compat/querier.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict'

const assert = require('assert')
const EE = require('events')
const MDNS = require('multicast-dns')
const Multiaddr = require('multiaddr')
Expand All @@ -14,7 +13,9 @@ const { SERVICE_TAG_LOCAL, MULTICAST_IP, MULTICAST_PORT } = require('./constants
class Querier extends EE {
constructor (peerId, options) {
super()
assert(peerId, 'missing peerId parameter')
if (!peerId) {
throw new Error('missing peerId parameter')
}
options = options || {}
this._peerIdStr = peerId.toB58String()
// Re-query every 60s, in leu of network change detection
Expand Down
6 changes: 4 additions & 2 deletions src/compat/responder.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
'use strict'

const OS = require('os')
const assert = require('assert')
const MDNS = require('multicast-dns')
const log = require('debug')('libp2p:mdns:compat:responder')
const { SERVICE_TAG_LOCAL } = require('./constants')

class Responder {
constructor (peerInfo) {
assert(peerInfo, 'missing peerInfo parameter')
if (!peerInfo) {
throw new Error('missing peerInfo parameter')
}

this._peerInfo = peerInfo
this._peerIdStr = peerInfo.id.toB58String()
this._onQuery = this._onQuery.bind(this)
Expand Down
5 changes: 3 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const multicastDNS = require('multicast-dns')
const EventEmitter = require('events').EventEmitter
const assert = require('assert')
const debug = require('debug')
const log = debug('libp2p:mdns')
const query = require('./query')
Expand All @@ -11,7 +10,9 @@ const GoMulticastDNS = require('./compat')
class MulticastDNS extends EventEmitter {
constructor (options = {}) {
super()
assert(options.peerInfo, 'needs a PeerInfo to work')
if (!options.peerInfo) {
throw new Error('needs a PeerInfo to work')
}

this.broadcast = options.broadcast !== false
this.interval = options.interval || (1e3 * 10)
Expand Down

0 comments on commit e362b04

Please sign in to comment.