Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// defer piping, so consumer can attach event listeners
// otherwise we might lose events
process.nextTick(() => {
duplex.pipe(this._parser)
})
this._generator.on('error', this.emit.bind(this, 'error'))
this._parser.on('error', this.emit.bind(this, 'error'))
this.stream = duplex
duplex.on('error', this.emit.bind(this, 'error'))
duplex.on('close', this.emit.bind(this, 'close'))
Duplexify.call(this, this._generator, this._parser, { objectMode: true })
// MQTT.js basic default
if (opts.notData !== true) {
var that = this
this.once('data', function (connectPacket) {
that.setOptions(connectPacket)
that.on('data', emitPacket)
if (cb) {
cb()
}
that.emit('data', connectPacket)
})
}
}
function StreamChannels (opts, onchannel) {
if (!(this instanceof StreamChannels)) return new StreamChannels(opts, onchannel)
if (typeof opts === 'function') {
onchannel = opts
opts = null
}
if (!opts) opts = {}
duplexify.call(this)
var self = this
this.destroyed = false
this.limit = opts.limit || 1024
this.state = null // set by someone else. here for perf
this._outgoing = []
this._incoming = []
this._waiting = 0
this._encode = new Sink()
this._decode = lpstream.decode({allowEmpty: true, limit: opts.messageLimit || 5 * 1024 * 1024})
this._decode.on('data', parse)
this._keepAlive = 0
this._remoteKeepAlive = 0
this.on('finish', function () {
debug('finished')
self.finalize()
})
this._decoder.pipe(parse)
if (this._process) {
this._process.pipe(through.obj(function (node, enc, cb) {
self.emit('node', node, cb) || cb()
}))
}
var hwm = opts.highWaterMark || 16
Duplexify.call(this, this._decoder, this._encoder, frame ? {} : {objectMode: true, highWaterMark: hwm})
}
var Pumpify = function() {
var streams = toArray(arguments)
if (!(this instanceof Pumpify)) return new Pumpify(streams)
Duplexify.call(this, null, null, opts)
if (streams.length) this.setPipeline(streams)
}
var Pumpify = function() {
var streams = toArray(arguments)
if (!(this instanceof Pumpify)) return new Pumpify(streams)
Duplexify.call(this, null, null, opts)
if (streams.length) this.setPipeline(streams)
}
function Protocol (opts) {
if (!(this instanceof Protocol)) return new Protocol(opts)
if (!opts) opts = {}
duplexify.call(this)
var self = this
this.inflight = 0
this.id = opts.id || crypto.randomBytes(32)
this.remoteId = null
this._parser = lpstream.decode({limit: MAX_MESSAGE})
this._generator = lpstream.encode()
this._parser.on('data', parse)
this._handshook = false
this._channels = {}
this._remote = []
this._local = ids()
var Pumpify = function() {
var streams = toArray(arguments)
if (!(this instanceof Pumpify)) return new Pumpify(streams)
Duplexify.call(this, null, null, opts)
if (streams.length) this.setPipeline(streams)
}
function Protocol () {
if (!(this instanceof Protocol)) return new Protocol()
var self = this
var encode = lpstream.encode()
var decode = lpstream.decode()
this._encoder = encode
this._requests = []
decode.on('data', function (data) {
self._decode(data)
})
duplexify.call(this, decode, encode)
}
var Pumpify = function() {
var streams = toArray(arguments)
if (!(this instanceof Pumpify)) return new Pumpify(streams)
Duplexify.call(this, null, null, opts)
if (streams.length) this.setPipeline(streams)
}
function ProtocolStream (opts) {
if (!(this instanceof ProtocolStream)) return new ProtocolStream(opts)
if (!opts) opts = {}
this._encode = lpstream.encode()
this._decode = lpstream.decode({limit: 5 * 1024 * 1024})
this._requests = []
this._handshook = false
this.destroyed = false
duplexify.call(this, this._decode, this._encode)
var self = this
this._decode.on('data', function (data) {
self._parse(data)
})
this._send(0, opts)
}