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

Commit

Permalink
fix: correct handling of multiplex options
Browse files Browse the repository at this point in the history
and switch to dignifiedquire/multiplex
  • Loading branch information
dignifiedquire authored Feb 21, 2017
1 parent 8003fde commit fa78df4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
27 changes: 23 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
sudo: false
language: node_js
node_js:
- "4.0"

matrix:
include:
- node_js: 4
env: CXX=g++-4.8
- node_js: 6
env:
- SAUCE=true
- CXX=g++-4.8
- node_js: stable
env: CXX=g++-4.8

# Make sure we have new NPM.
before_install:
Expand All @@ -10,10 +19,20 @@ before_install:
script:
- npm run lint
- npm test
- npm run coverage

addons:
firefox: 'latest'

before_script:
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start

after_success:
- npm run coverage-publish

addons:
firefox: 'latest'
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"pull-pair": "^1.1.0"
},
"dependencies": {
"multiplex": "diasdavid/multiplex",
"multiplex": "dignifiedquire/multiplex",
"pull-catch": "^1.0.0",
"pull-stream": "^3.5.0",
"pull-stream-to-stream": "^1.3.3",
Expand All @@ -53,4 +53,4 @@
"Victor Bjelkholm <[email protected]>",
"greenkeeperio-bot <[email protected]>"
]
}
}
9 changes: 6 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const multiplex = require('multiplex')
const Multiplex = require('multiplex')
const toStream = require('pull-stream-to-stream')

const MULTIPLEX_CODEC = require('./multiplex-codec')
Expand All @@ -16,10 +16,13 @@ function create (rawConn, isListener) {
// but .destroy will trigger a 'close' event.
stream.on('end', () => stream.destroy())

const mpx = multiplex()
const mpx = new Multiplex({
halfOpen: true,
initiator: !isListener
})
pump(stream, mpx, stream)

return new Muxer(rawConn, mpx, isListener)
return new Muxer(rawConn, mpx)
}

exports = module.exports = create
Expand Down
10 changes: 2 additions & 8 deletions src/muxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ const pullCatch = require('pull-catch')
const MULTIPLEX_CODEC = require('./multiplex-codec')

module.exports = class MultiplexMuxer extends EventEmitter {
constructor (conn, multiplex, isListener) {
constructor (conn, multiplex) {
super()

this._id = (isListener ? 0 : -1)

this.multiplex = multiplex
this.conn = conn
this.multicodec = MULTIPLEX_CODEC
this.isListener = isListener

multiplex.on('close', () => this.emit('close'))
multiplex.on('error', (err) => this.emit('error', err))
Expand All @@ -34,9 +30,7 @@ module.exports = class MultiplexMuxer extends EventEmitter {
// method added to enable pure stream muxer feeling
newStream (callback) {
callback = callback || noop
this._id = this._id + 2

const stream = this.multiplex.createStream(this._id)
let stream = this.multiplex.createStream()

const conn = new Connection(
catchError(toPull.duplex(stream)),
Expand Down

0 comments on commit fa78df4

Please sign in to comment.