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

Commit e362b04

Browse files
authoredFeb 17, 2020
fix: remove use of assert module (#87)
The polyfill is big, we can simulate it by throwing an Error and it doesn't work under React Native.
1 parent bea3dd1 commit e362b04

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed
 

‎src/compat/querier.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict'
22

3-
const assert = require('assert')
43
const EE = require('events')
54
const MDNS = require('multicast-dns')
65
const Multiaddr = require('multiaddr')
@@ -14,7 +13,9 @@ const { SERVICE_TAG_LOCAL, MULTICAST_IP, MULTICAST_PORT } = require('./constants
1413
class Querier extends EE {
1514
constructor (peerId, options) {
1615
super()
17-
assert(peerId, 'missing peerId parameter')
16+
if (!peerId) {
17+
throw new Error('missing peerId parameter')
18+
}
1819
options = options || {}
1920
this._peerIdStr = peerId.toB58String()
2021
// Re-query every 60s, in leu of network change detection

‎src/compat/responder.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
'use strict'
22

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

98
class Responder {
109
constructor (peerInfo) {
11-
assert(peerInfo, 'missing peerInfo parameter')
10+
if (!peerInfo) {
11+
throw new Error('missing peerInfo parameter')
12+
}
13+
1214
this._peerInfo = peerInfo
1315
this._peerIdStr = peerInfo.id.toB58String()
1416
this._onQuery = this._onQuery.bind(this)

‎src/index.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const multicastDNS = require('multicast-dns')
44
const EventEmitter = require('events').EventEmitter
5-
const assert = require('assert')
65
const debug = require('debug')
76
const log = debug('libp2p:mdns')
87
const query = require('./query')
@@ -11,7 +10,9 @@ const GoMulticastDNS = require('./compat')
1110
class MulticastDNS extends EventEmitter {
1211
constructor (options = {}) {
1312
super()
14-
assert(options.peerInfo, 'needs a PeerInfo to work')
13+
if (!options.peerInfo) {
14+
throw new Error('needs a PeerInfo to work')
15+
}
1516

1617
this.broadcast = options.broadcast !== false
1718
this.interval = options.interval || (1e3 * 10)

0 commit comments

Comments
 (0)
This repository has been archived.