Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

pipe-channels

0.1.1 • Public • Published

pipe-channels

By Build Status

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

install

npm i pipe-channels

Downloadsweekly downloads

2

version

0.1.1

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability