Skip to content

Commit

Permalink
Merge pull request #10 from Temasys/jo-datachannel-update
Browse files Browse the repository at this point in the history
DataChannel update
  • Loading branch information
johache authored Jul 25, 2017
2 parents 59eb1c9 + 5b87009 commit b016e4e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/content/datachannel/arraybuffer/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var typeList = [Int8Array,
var bufSize = 12;
var sendBuf = null;
var receiveBuf = null;
var crypto = isIE ? window.msCrypto : window.crypto;

var localConnection, remotePeerConnection, sendChannel, receiveChannel, pcConstraint, dataConstraint;
var sctpSelect = document.querySelector('input#useSctp');
Expand Down Expand Up @@ -114,8 +115,7 @@ function startSending() {
function sendData() {
// create a new buffer
sendBuf = new typeList[sendCounter](bufSize);
for (var i = 0; i < bufSize; i++)
sendBuf[i] = (Math.random() * 100);
crypto.getRandomValues(sendBuf);

// log the value
console.log('send: ');
Expand Down
3 changes: 2 additions & 1 deletion src/content/datachannel/datatransfer/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var receivedSize = 0;
var bytesToSend = 0;
var nSent = 0;
var nReceived = 0;
var stringToSendRepeatedly;

sendButton.onclick = createConnection;

Expand Down Expand Up @@ -98,7 +99,7 @@ function sendGeneratedData() {
nSent = 0;

var chunkSize = 16384;
var stringToSendRepeatedly = randomAsciiString(chunkSize);
stringToSendRepeatedly = randomAsciiString(chunkSize);
var bufferFullThreshold = 5 * chunkSize;
var usePolling = true;
if (typeof sendChannel.bufferedAmountLowThreshold === 'number') {
Expand Down
25 changes: 23 additions & 2 deletions src/content/datachannel/filetransfer/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,36 @@ function sendData() {
sendProgress.max = file.size;
receiveProgress.max = file.size;
fileType = file.type.length > 0 ? file.type : 'text/plain';
var chunkSize = 512 * 32;
var chunkSize = 16384;
var bufferFullThreshold = 5 * chunkSize;
var usePolling = true;
if (typeof sendChannel.bufferedAmountLowThreshold === 'number') {
trace('Using the bufferedamountlow event for flow control');
usePolling = false;

// Reduce the buffer fullness threshold, since we now have more efficient
// buffer management.
bufferFullThreshold = chunkSize / 2;

// This is "overcontrol": our high and low thresholds are the same.
sendChannel.bufferedAmountLowThreshold = bufferFullThreshold;
}
// Listen for one bufferedamountlow event.
var listener = function() {
sendChannel.removeEventListener('bufferedamountlow', listener);
sliceFile(offset);
};
var sliceFile = function(offset) {
var reader = new window.FileReader();
reader.onload = (function() {
return function(e) {
var packet = new Int8Array(e.target.result, 0, e.target.result.byteLength);
if (sendChannel.bufferedAmount > bufferFullThreshold) {
setTimeout(sliceFile, 150, offset);
if (usePolling) {
setTimeout(sliceFile, 150, offset);
} else {
sendChannel.addEventListener('bufferedamountlow', listener);
}
return;
}
sendChannel.send(packet);
Expand Down

0 comments on commit b016e4e

Please sign in to comment.