pipe-channels
v0.1.1
Published
Node channels negotiation
Downloads
13
Maintainers
Readme
pipe-channels
Channels as streams inside a stream, negotiated.
Install
$ npm install pipe-channels --save
Server
var Channels = require('pipe-channels');
var server = Channels.createServer();
// listen for new channel requests:
server.on('request', function(request) {
// request.payload has arbitrary values passed in by client
if (request.payload.token == 'this is a token') {
var channel = request.grant(); // channel is an object stream
} else {
request.deny('just because'); // deny the channel
}
});
// pipe server into duplex stream
stream.pipe(server).pipe(stream);
Client
var client = require('pipe-channels').createClient();
var payload = { token: 'this is a token'};
// ask for a channel, passing in any arbitrary payload:
client.channel(payload, function(err, channel) {
if (err) {
console.error('could not get a channel because', err.message);
} else {
// now I have a channel, an object stream that I can pipe
stream.pipe(channel).pipe(stream);
}
});
License
ISC