Added sample speedtest request
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import { Component } from '@angular/core';
|
||||
import axios from "axios";
|
||||
|
||||
@Component({
|
||||
selector: 'app-download',
|
||||
@ -9,4 +10,32 @@ import { Component } from '@angular/core';
|
||||
})
|
||||
export class DownloadComponent {
|
||||
|
||||
constructor() {
|
||||
this.speedTest();
|
||||
}
|
||||
|
||||
private speedTest() {
|
||||
const start = new Date().getTime(); // Start timer
|
||||
|
||||
axios({
|
||||
method: 'get',
|
||||
url: 'http://localhost:/api/v1/speed-test',
|
||||
responseType: 'arraybuffer',
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*', // Allow CORS
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
const end = new Date().getTime(); // End timer
|
||||
const duration = (end - start) / 1000; // Convert ms to seconds
|
||||
const bitsLoaded = response.data.byteLength * 8;
|
||||
const speedBps = bitsLoaded / duration;
|
||||
const speedKbps = speedBps / 1024;
|
||||
const speedMbps = speedKbps / 1024;
|
||||
console.log(`Download speed: ${speedMbps.toFixed(2)} Mbps`);
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error during download test:', error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user