Send video bitrate and user bandwidth to Watchman (#7145)
* adding functionality to detect user download speed * calculating bandwidth speed more intelligently * saving download speed and updating it every 30s * all the functionality should be done needs testing * fix linting * use a 1mb file for calculating bandwidth * add optional chaining plugin to babel and get bitrate from texttrack * allow optional chaining for flow * ignore flow error * disable bandwidth checking functionality * fix flow error
This commit is contained in:
parent
b44be39252
commit
e3791aefdc
8 changed files with 90 additions and 7 deletions
ui/util
20
ui/util/detect-user-bandwidth.js
Normal file
20
ui/util/detect-user-bandwidth.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
const imageAddr = 'https://upload.wikimedia.org/wikipedia/commons/b/b9/Pizigani_1367_Chart_1MB.jpg';
|
||||
const downloadSize = 1093957; // this must match with the image above
|
||||
|
||||
let startTime, endTime;
|
||||
async function measureConnectionSpeed() {
|
||||
startTime = (new Date()).getTime();
|
||||
const cacheBuster = '?nnn=' + startTime;
|
||||
|
||||
const download = new Image();
|
||||
download.src = imageAddr + cacheBuster;
|
||||
// this returns when the image is finished downloading
|
||||
await download.decode();
|
||||
endTime = (new Date()).getTime();
|
||||
const duration = (endTime - startTime) / 1000;
|
||||
const bitsLoaded = downloadSize * 8;
|
||||
const speedBps = (bitsLoaded / duration).toFixed(2);
|
||||
return Math.round(Number(speedBps));
|
||||
}
|
||||
|
||||
module.exports = measureConnectionSpeed;
|
Loading…
Add table
Add a link
Reference in a new issue