2020-01-09 04:34:58 +01:00
|
|
|
import ObjectMultiplex from 'obj-multiplex'
|
|
|
|
import pump from 'pump'
|
2016-04-08 23:24:10 +02:00
|
|
|
|
2018-04-16 17:29:43 +02:00
|
|
|
/**
|
|
|
|
* Sets up stream multiplexing for the given stream
|
|
|
|
* @param {any} connectionStream - the stream to mux
|
2020-01-13 19:36:36 +01:00
|
|
|
* @returns {stream.Stream} - the multiplexed stream
|
2018-04-16 17:29:43 +02:00
|
|
|
*/
|
2020-01-09 04:34:58 +01:00
|
|
|
export function setupMultiplex (connectionStream) {
|
2017-09-08 06:17:49 +02:00
|
|
|
const mux = new ObjectMultiplex()
|
|
|
|
pump(
|
|
|
|
connectionStream,
|
|
|
|
mux,
|
|
|
|
connectionStream,
|
|
|
|
(err) => {
|
2019-11-20 01:03:20 +01:00
|
|
|
if (err) {
|
|
|
|
console.error(err)
|
|
|
|
}
|
2017-09-08 06:17:49 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
return mux
|
2016-06-21 22:18:32 +02:00
|
|
|
}
|