package
All the ways for doing requests/streams multiplexing over a single stream
npm install tentacoliGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Tagged topics.

Multiplexing requests and streams over a single connection since 2015.
npm i tentacoli --save'use strict'
var tentacoli = require('./')
var net = require('net')
var from = require('from2')
var through = require('through2')
var pump = require('pump')
var server = net.createServer(function (original) {
var stream = tentacoli()
pump(stream, original, stream)
stream.on('request', handle)
})
Yes, it is long.
Creates a new instance of Tentacoli, which is a Duplex stream and inherits from multiplex
It accepts the following option:
codec: an object with a encode and decode method, which will
be used to encode messages. Valid encoding libraries are
protocol-buffers and
msgpack5. The default one is JSON.
This capability is provided by
net-object-stream.maxInflight: max number of concurrent requests in
flight at any given moment.Sends a request to the remote peer.
message is a standard JS object, but all streams contained in its
streams property will be multiplexed and forwarded to the other
peer.callback will be called if an error occurred or a response is
available. The res.streams property will contain all streams
passed by the other peer.Sends a fire and forget request to the remote peer.
message is a standard JS object, but all streams contained in its
streams property will be multiplexed and forwarded to the other
peer.callback will be called if there is an error while sending the message, or after the message has been sent successfully.The 'request' event is emitted when there is an incoming request.
req is the standard JS object coming from request,
and all the streams contained in its
streams property will have been multiplexed and forwarded from
the other peer.reply is the function to send a reply to the other peer, and it
follows the standard node callback pattern: reply(err, res).
The res.streams property should contain all the streams
that need to be forwarded to the other peer.You will use websocket-stream to wire tentacoli to the websocket.
On the server:
'use strict'
var http = require('http')
var tentacoli = require('./')
var pump = require('pump')
var websocket = require('websocket-stream')
var server = http.createServer(serve)
websocket.createServer({
server: server
}, handle)
function handle (sock) {
var receiver = tentacoli()
pump(sock, receiver, sock)
receiver.on('request',
On the client:
'use strict'
var tentacoli = require('../')
var ws = require('websocket-stream')
var pump = require('pump')
var from = require('from2')
var URL = require('url')
var serverOpts = URL.parse(document.URL)
serverOpts.path = undefined
serverOpts.pathname = undefined
serverOpts.protocol = 'ws'
var server = URL.format(serverOpts)
Browserify offers a way of packaging up this module for front-end usage. You will just need to install/specify the brfs transform.
As an example:
browserify -t brfs tentacoli.js > bundle.jsWebPack offers the more popular way of packaging up node modules for browser usage. You will just need to install/specify the brfs transform.
You should install webpack, transform-loader and brfs:
npm i webpack transform-loader brfs websocket-stream --saveThen, set this as your webpack configuration:
'use strict'
module.exports = {
module: {
postLoaders: [{
loader: "transform?brfs"
}]
}
}To build:
webpack --config webpack.config.js yourfile.js build.jsThis library would not be possible without the great work of @mafintosh, @substack and @maxodgen. This library is fully based on their work, look at package.json!
Another great source of inspriation was jschan from which I borrowed a lot of ideas. Thanks Adrian Roussow for all the discussions around microservices, streams and channels.
Many thanks to @mcdonnelldean for providing an excuse to write this random idea out.
This project is kindly sponsored by nearForm.
MIT
Estimated unpacked size across 37 packages.
1.4 MB
Includes dependencies.
^3.2.1
5.0.0
^2.1.0
2.1.0