index.js
/**
  # rtc-dcstream

  Node streams2 interface for working with WebRTC data channels. This stream
  implementation will cater for current data size limits in the WebRTC
  data channels.

  ## Example Usage

  The example below shows how to use the `rtc-dcstream` module to stream data
  via a datachannel to *n* remote participants.  In this case we are using
  the W3C FileReader API and streaming dropped data files over the data
  channel:

  <<< examples/file-transfer.js

  ## Alternative Implementations

  In addition to this module, the following are other modules that wrap
  WebRTC data channel communication via a node streaming interface:

  - [rtc-data-stream](https://github.com/kumavis/rtc-data-stream)

  ## Reference

  To be completed.

**/
rtc-dcstream
Node streams2 interface for working with WebRTC data channels. This stream
implementation will cater for current data size limits in the WebRTC
data channels.

Example Usage

The example below shows how to use the `rtc-dcstream` module to stream data
via a datachannel to *n* remote participants.  In this case we are using
the W3C FileReader API and streaming dropped data files over the data
channel.



Alternative Implementations

In addition to this module, the following are other modules that wrap
WebRTC data channel communication via a node streaming interface.

[rtc-data-stream]

Reference

To be completed.
rtc - dcstream Node streams2 interface for working with WebRTC data channels . This stream implementation will cater for current data size limits in the WebRTC data channels . Example Usage The example below shows how to use the ` rtc - dcstream ` module to stream data via a datachannel to * n * remote participants . In this case we are using the W3C FileReader API and streaming dropped data files over the data channel . Alternative Implementations In addition to this module the following are other modules that wrap WebRTC data channel communication via a node streaming interface . [ rtc - data - stream ] Reference To be completed .
function RTCChannelStream(channel) {
  if (! (this instanceof RTCChannelStream)) {
    return new RTCChannelStream(channel);
  }
  stream.Duplex.call(this, {
    decodeStrings: false,
    objectMode: true
  });
  this._rq = [];
  this._wq = [];
  this._bytesWritten = 0;
  this._closed = channel.readyState === 'closed';
  this.channel = channel;
  channel.binaryType = 'arraybuffer';
  this._handlers = {
    message: this._handleMessage.bind(this),
    close: this._handleClose.bind(this),
    open: this._handleOpen.bind(this)
  };
  if (typeof channel.addEventListener == 'function') {
    channel.addEventListener('message', this._handlers.message);
    channel.addEventListener('close', this._handlers.close);
    channel.addEventListener('open', this._handlers.open);
  } else {
    channel.onmessage = this._handlers.message;
    channel.onclose = this._handlers.close;
    channel.onopen = this._handlers.open;
  }
  if (channel.readyState === 'open') {
    this._handlers.open();
  }
  this.once('finish', this._dcsend.bind(this, ENDOFSTREAM));
}
function RTCChannelStream ( channel ) { if ( ! ( this instanceof RTCChannelStream ) ) { return new RTCChannelStream ( channel ) ; } stream . Duplex . call ( this , { decodeStrings : false , objectMode : true } ) ; this . _rq = [ ] ; this . _wq = [ ] ; this . _bytesWritten = 0 ; this . _closed = channel . readyState === 'closed' ; this . channel = channel ; channel . binaryType = 'arraybuffer' ; this . _handlers = { message : this . _handleMessage . bind ( this ) , close : this . _handleClose . bind ( this ) , open : this . _handleOpen . bind ( this ) } ; if ( typeof channel . addEventListener == 'function' ) { channel . addEventListener ( 'message' , this . _handlers . message ) ; channel . addEventListener ( 'close' , this . _handlers . close ) ; channel . addEventListener ( 'open' , this . _handlers . open ) ; } else { channel . onmessage = this . _handlers . message ; channel . onclose = this . _handlers . close ; channel . onopen = this . _handlers . open ; } if ( channel . readyState === 'open' ) { this . _handlers . open ( ) ; } this . once ( 'finish' , this . _dcsend . bind ( this , ENDOFSTREAM ) ) ; }
rtc-dcstream
Node streams2 interface for working with WebRTC data channels.
rtc - dcstream Node streams2 interface for working with WebRTC data channels .
// super // create the internal read and write queues // initialise the closed state // save a reference to the channel // set the channel binaryType to arraybuffer // initialise the message handlers // attach channel listeners // Check if the channel is already open, and if it is, fire the open handler // send an ENDOFSTREAM marker on finish