Skip to content

Commit

Permalink
fix: also support ipfs.libp2p
Browse files Browse the repository at this point in the history
  • Loading branch information
pgte authored and Pedro Teixeira committed Jan 25, 2019
1 parent c5ada17 commit f4f8ebd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Pushable = require('pull-pushable')
const PROTOCOL = require('./protocol')
const encoding = require('./encoding')
const getPeerId = require('./peer-id')
const libp2p = require('./libp2p')

module.exports = class Connection extends EventEmitter {
constructor (id, ipfs, room) {
Expand Down Expand Up @@ -48,7 +49,7 @@ module.exports = class Connection extends EventEmitter {
return // early
}

this._ipfs._libp2pNode.dialProtocol(peerAddresses[0], PROTOCOL, (err, conn) => {
libp2p(this._ipfs).dialProtocol(peerAddresses[0], PROTOCOL, (err, conn) => {
if (err) {
this.emit('disconnect')
return // early
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const PROTOCOL = require('./protocol')
const Connection = require('./connection')
const encoding = require('./encoding')
const directConnection = require('./direct-connection-handler')
const libp2p = require('./libp2p')

const DEFAULT_OPTIONS = {
pollInterval: 1000
Expand Down Expand Up @@ -130,7 +131,7 @@ class PubSubRoom extends EventEmitter {
})
})

this._ipfs._libp2pNode.handle(PROTOCOL, directConnection.handler)
libp2p(this._ipfs).handle(PROTOCOL, directConnection.handler)

directConnection.emitter.on(this._topic, this._handleDirectMessage)
}
Expand Down
5 changes: 5 additions & 0 deletions src/libp2p.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict'

module.exports = (ipfs) => {
return ipfs._libp2pNode || ipfs.libp2p
}

0 comments on commit f4f8ebd

Please sign in to comment.