Skip to content

Commit

Permalink
Implement bandwidth test
Browse files Browse the repository at this point in the history
  • Loading branch information
okuoku committed Sep 26, 2023
1 parent 8916164 commit fcfd8c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion nestdevicemw.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ndc from "node-datachannel";
import jose from "node-jose";
import crypto from "crypto";
import fs from "fs";
import tester from "./test_bandwidth_node.mjs";

// Read config and keyblob
const keys = JSON.parse(fs.readFileSync("./keys.json"));
Expand Down Expand Up @@ -96,6 +97,7 @@ function new_session(){ // => UUID

// Activate
dc = conn.createDataChannel("default");
tester.dc_tester(dc);
}


Expand Down Expand Up @@ -188,7 +190,7 @@ async function mw_con(ctx, next){
}
}

ndc.initLogger("Debug");
//ndc.initLogger("Debug");
init();

export default {
Expand Down
3 changes: 3 additions & 0 deletions pages/site/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
<button id="setdevicekey">Set Device Key</button>
<a target="_blank" id="runlink" rel="opener">Start session</a>
</p>
<p id="dataarea">
Waiting for connection...
</p>
</body>
</html>
15 changes: 15 additions & 0 deletions pages/site/index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import jose from "node-jose";
import tester from "../../test_bandwidth_browser.mjs";

const setdevicekeyEl = document.getElementById("setdevicekey");
const runlinkEl = document.getElementById("runlink");
const dataareaEl = document.getElementById("dataarea");

const devicekeyEl = document.getElementById("devicekey");
const BASEURL = window.location.protocol + "//" +
Expand Down Expand Up @@ -44,7 +46,20 @@ async function newRTC(ses,req){
}

peer.ondatachannel = function(c){
let prevtime = 0;
let prevsize = 0;
console.log("On dataChannel", c);
tester.dc_tester(c.channel, function(data){
console.log("Data", data);
const res = JSON.parse(data);
const nowtime = res.curtime - prevtime;
const nowsize = res.sent - prevsize;

const mibparsec = nowsize / nowtime * 1000 / 1024 / 1024;
dataareaEl.innerText = `${mibparsec} MiB/sec`;
prevtime = res.curtime;
prevsize = res.sent;
});
}


Expand Down

0 comments on commit fcfd8c9

Please sign in to comment.