2017-12-14 06:02:51 +00:00
2015-07-10 14:41:19 -07:00
2017-12-14 06:02:39 +00:00
2016-11-03 09:02:16 +00:00
2016-11-03 09:02:16 +00:00
2017-12-14 05:53:10 +00:00
2015-07-10 14:18:31 -07:00
2017-12-14 05:53:10 +00:00

interface-stream-muxer

Travis CI Dependency Status js-standard-style

A test suite and interface you can use to implement a stream muxer. "A one stop shop for all your muxing needs"

The primary goal of this module is to enable developers to pick and swap their stream muxing module as they see fit for their application, without having to go through shims or compatibility issues. This module and test suite was heavily inspired by abstract-blob-store.

Publishing a test suite as a module lets multiple modules all ensure compatibility since they use the same test suite.

The API is presented with both Node.js and Go primitives, however, there is not actual limitations for it to be extended for any other language, pushing forward the cross compatibility and interop through diferent stacks.

Modules that implement the interface

Send a PR to add a new one if you happen to find or write one.

Badge

Include this badge in your readme if you make a new module that uses interface-stream-muxer API.

Usage

Node.js

Install interface-stream-muxer as one of the dependencies of your project and as a test file. Then, using mocha (for JavaScript) or a test runner with compatible API, do:

const test = require('interface-stream-muxer')

const common = {
  setup (cb) {
    cb(null, yourMuxer)
  },
  teardown (cb) {
    cb()
  }
}

// use all of the test suits
test(common)

Go

WIP

API

A valid (read: that follows this abstraction) stream muxer, must implement the following API.

Attach muxer to a Connection

  • JavaScript muxedConn = muxer(conn, isListener)
  • Go muxedConn, err := muxer.Attach(conn, isListener)

This method attaches our stream muxer to an instance of Connection defined by interface-connection.

If err is passed, no operation should be made in conn.

isListener is a bool that tells the side of the socket we are, isListener = true for listener/server and isListener = false for dialer/client side.

muxedConn interfaces our established Connection with the other endpoint, it must offer an interface to open a stream inside this connection and to receive incomming stream requests.

Dial(open/create) a new stream

  • JavaScript stream = muxedConn.newStream([function (err, stream)])
  • Go stream, err := muxedConn.newStream()

This method negotiates and opens a new stream with the other endpoint.

If err is passed, no operation should be made in stream.

stream interface our established Stream with the other endpoint, it must implement the Duplex pull-stream interface in JavaScript or the ReadWriteCloser in Go.

Listen(wait/accept) a new incoming stream

  • JavaScript muxedConn.on('stream', function (stream) {})
  • Go stream := muxedConn.Accept()

Each time a dialing peer initiates the new stream handshake, a new stream is created on the listening side.

In JavaScript, the Event Emitter pattern is expected to be used in order to receive new incoming streams, while in Go, it expects to wait when Accept is called.

Description
No description provided
Readme 3 MiB
Languages
JavaScript 100%