forked from node-webrtc/node-webrtc
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bandwidth test to reproduce issue node-webrtc#171
- Loading branch information
Showing
2 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
'use strict'; | ||
|
||
var wrtc = require('..'); | ||
|
||
/** | ||
* define window for simple-peer | ||
*/ | ||
global.window = { | ||
RTCPeerConnection: wrtc.RTCPeerConnection, | ||
RTCSessionDescription: wrtc.RTCSessionDescription, | ||
RTCIceCandidate: wrtc.RTCIceCandidate, | ||
// Firefox does not trigger "negotiationneeded" | ||
// this is a workaround to make simple-peer trigger the negotiation | ||
mozRTCPeerConnection: wrtc.RTCPeerConnection, | ||
}; | ||
|
||
var SimplePeer = require('simple-peer'); | ||
|
||
|
||
function bwtest(peer1, peer2) { | ||
var stats = { | ||
count: 0, | ||
bytes: 0, | ||
}; | ||
var SEND_DELAY_MS = 1; | ||
var NPACKETS = 100000; | ||
var PACKET_SIZE = 16 * 1024; | ||
var buffer = new ArrayBuffer(PACKET_SIZE); | ||
var n = 0; | ||
|
||
peer2.on('data', function(data) { | ||
stats.count += 1; | ||
stats.bytes += data.length; | ||
}); | ||
|
||
function send() { | ||
if (n >= NPACKETS) { | ||
console.log('DONE!', stats); | ||
return; | ||
} | ||
console.log('send', n, stats); | ||
peer1.send(buffer, function(err) { | ||
if (err) { | ||
console.error('ERROR!', stats); | ||
return; | ||
} | ||
n += 1; | ||
setTimeout(send, SEND_DELAY_MS); | ||
}); | ||
} | ||
|
||
send(); | ||
} | ||
|
||
function init(callback) { | ||
var INITIATOR_CONFIG = { | ||
initiator: true | ||
}; | ||
var peer1 = new SimplePeer(INITIATOR_CONFIG); | ||
var peer2 = new SimplePeer(); | ||
|
||
// when peer1 has signaling data, give it to peer2, and vice versa | ||
peer1.on('signal', peer2.signal.bind(peer2)); | ||
peer2.on('signal', peer1.signal.bind(peer1)); | ||
|
||
// wait for 'connect' event before using the data channel | ||
peer1.on('connect', callback.bind(null, peer1, peer2)); | ||
} | ||
|
||
init(bwtest); |