substream.js
function SubStream(stream, name, options) {
    if (!(this instanceof SubStream)) return new SubStream(stream, name, options);

    options = options || {};

    this.readyState = stream.readyState;  // Copy the current readyState.
    this.stream = stream;                 // The underlaying stream.
    this.name = name;                     // The stream namespace/name.
    this.primus = options.primus;         // Primus reference.

    //
    // Register the SubStream on the socket.
    //
    if (!stream.streams) stream.streams = {};
    if (!stream.streams[name]) stream.streams[name] = this;

    Stream.call(this);

    //
    // No need to continue with the execution if we don't have any events that
    // need to be proxied.
    //
    if (!options.proxy) return;

    for (var i = 0, l = options.proxy.length, event; i < l; i++) {
      event = options.proxy[i];
      this.stream.on(event, this.emits(event));
    }
  }
function SubStream(stream, name, options) {
    if (!(this instanceof SubStream)) return new SubStream(stream, name, options);

    options = options || {};

    this.readyState = stream.readyState;  // Copy the current readyState.
    this.stream = stream;                 // The underlaying stream.
    this.name = name;                     // The stream namespace/name.
    this.primus = options.primus;         // Primus reference.

    //
    // Register the SubStream on the socket.
    //
    if (!stream.streams) stream.streams = {};
    if (!stream.streams[name]) stream.streams[name] = this;

    Stream.call(this);

    //
    // No need to continue with the execution if we don't have any events that
    // need to be proxied.
    //
    if (!options.proxy) return;

    for (var i = 0, l = options.proxy.length, event; i < l; i++) {
      event = options.proxy[i];
      this.stream.on(event, this.emits(event));
    }
  }
function SubStream ( stream , name , options ) { if ( ! ( this instanceof SubStream ) ) return new SubStream ( stream , name , options ) ; options = options || { } ; this . readyState = stream . readyState ; // Copy the current readyState. this . stream = stream ; // The underlaying stream. this . name = name ; // The stream namespace/name. this . primus = options . primus ; // Primus reference. // // Register the SubStream on the socket. // if ( ! stream . streams ) stream . streams = { } ; if ( ! stream . streams [ name ] ) stream . streams [ name ] = this ; Stream . call ( this ) ; // // No need to continue with the execution if we don't have any events that // need to be proxied. // if ( ! options . proxy ) return ; for ( var i = 0 , l = options . proxy . length , event ; i < l ; i ++ ) { event = options . proxy [ i ] ; this . stream . on ( event , this . emits ( event ) ) ; } }
Streams provides a streaming, namespaced interface on top of a regular
stream.

Options:

- proxy: Array of addition events that need to be re-emitted.

@constructor
@param {Stream} stream The stream that needs we're streaming over.
@param {String} name The name of our stream.
@param {object} options SubStream configuration.
@api public
Streams provides a streaming namespaced interface on top of a regular stream .