mesheam-reliable

0.1.0 • Public • Published

Reliable transfer over DataChannels

Reliable

new Reliable(dc): A reliable utility class for DataChannel. Takes in a DataChannel object.

  • .send(msg): Takes any message and sends it reliably.
  • .onmessage(msg): Called when data is received.

Reliable.higherBandwidthSDP(sdp): This need to be applied to all offer/answer SDPs for Reliable to function properly. Returns the new SDP with added bandwidth. See usage below.

// Assuming 2 PeerConnections pc1, pc2.
pc1.createOffer(function(offer) {
  offer.sdp = Reliable.higherBandwidthSDP(offer.sdp);
  pc1.setLocalDescription(offer, ...);
});

...

// Same process for answer.
pc2.createAnswer(function(answer) {
  answer.sdp = Reliable.higherBandwidthSDP(answer.sdp);
  pc2.setLocalDescription(answer, ...);
});

Internal message format

ACK

This is an ACK for a chunk of the message.

[
  /* type */  'ack',
  /* id */    message_id,
  /* ACK */   n   // The next chunk # expected.
]

Chunk

This is a chunk of the message.

[
  /* type */  'chunk',
  /* id */    message_id,
  /* n */     n,       // The chunk #.
  /* chunk */ chunk   // The actual binary chunk.
]

END

This is the end of a message.

[
  /* type */  'end',
  /* id */    message_id,
  /* n */     n       // The last index.
]

Unchunked message

This is a message that was able to be sent without being chunked.

[
  /* type */  'no',
  /* msg */   payload
]

Future plans

Use stream API.

Readme

Keywords

none

Package Sidebar

Install

npm i mesheam-reliable

Weekly Downloads

0

Version

0.1.0

License

none

Unpacked Size

131 kB

Total Files

9

Last publish

Collaborators

  • kidandcat