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

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.1
    0
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.1
    0
  • 0.1.0
    1

Package Sidebar

Install

npm i pipe-channels

Weekly Downloads

1

Version

0.1.1

License

ISC

Last publish

Collaborators

  • pgte