mirror of
https://github.com/librespeed/speedtest.git
synced 2024-05-10 18:54:52 +00:00
Ping test can now use timing from Performance API; New examples; Minor changes
This commit is contained in:
39
example-basic.html
Normal file
39
example-basic.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<meta charset="UTF-8" />
|
||||
<head>
|
||||
<title>HTML5 Speedtest</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>HTML5 Speedtest</h1>
|
||||
|
||||
<h4>IP Address</h4>
|
||||
<p id="ip"></p>
|
||||
|
||||
<h4>Download</h4>
|
||||
<p id="download"></p>
|
||||
|
||||
<h4>Upload</h4>
|
||||
<p id="upload"></p>
|
||||
|
||||
<h4>Latency</h4>
|
||||
<p id="ping"></p>
|
||||
|
||||
<script type="text/javascript">
|
||||
var w = new Worker('speedtest_worker.min.js') // create new worker
|
||||
setInterval(function () { w.postMessage('status') }, 100) // ask for status every 100ms
|
||||
w.onmessage = function (event) { // when status is received, split the string and put the values in the appropriate fields
|
||||
var data = event.data.split(';') // string format: status;download;upload;ping (speeds are in mbit/s) (status: 0=not started, 1=downloading, 2=uploading, 3=ping, 4=done, 5=aborted)
|
||||
document.getElementById('download').textContent = data[1] + ' Mbit/s'
|
||||
document.getElementById('upload').textContent = data[2] + ' Mbit/s'
|
||||
document.getElementById('ping').textContent = data[3] + ' ms, ' + data[5] + ' ms jitter'
|
||||
document.getElementById('ip').textContent = data[4]
|
||||
}
|
||||
w.postMessage('start') // start the speedtest (default params. keep garbage.php and empty.dat in the same directory as the js file)
|
||||
</script>
|
||||
|
||||
<a href="https://github.com/adolfintel/speedtest">Source code</a>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user