AY пре 4 година
родитељ
комит
074806336e
4 измењених фајлова са 68 додато и 290 уклоњено
  1. 0 102
      web/Speedtest/dl.html
  2. 67 24
      web/Speedtest/index.html
  3. 1 3
      web/Speedtest/special/wspeedtest.js
  4. 0 161
      web/Speedtest/ul.html

+ 0 - 102
web/Speedtest/dl.html

@@ -1,102 +0,0 @@
-<!DOCTYPE html>
-<html>
-
-<head>
-    <meta name="apple-mobile-web-app-capable" content="yes" />
-    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1" />
-    <meta charset="UTF-8">
-    <meta name="theme-color" content="#4b75ff">
-    <link rel="stylesheet" href="../script/semantic/semantic.min.css">
-    <script src="../script/jquery.min.js"></script>
-    <script src="../script/ao_module.js"></script>
-    <script src="../script/semantic/semantic.min.js"></script>
-    <title>WebSocket Test</title>
-</head>
-
-<body>
-    <br><br>
-    <div class="ui container">
-        <h3>WebSocket Testing Interface</h3>
-        <div class="ui form">
-            <div class="field">
-                <label>Recv</label>
-                <textarea id="incoming"></textarea>
-            </div>
-            <div class="field">
-                <label>Send</label>
-                <input type="text" id="sendMsg">
-            </div>
-            <div class="field">
-                <button class="ui blue button" onclick="sendws();">Send</button>
-            </div>
-        </div>
-        <br>
-        <button class="ui button" onclick="openws();">Open Connection</button>
-    </div>
-
-    <script>
-        var ws;
-        var nolog = false;
-
-        $(window).ready(function() {
-            $("#incoming").val("");
-        });
-
-        //Send WebSocket
-        function sendws() {
-            var value = $("#sendMsg").val();
-            ws.send(value);
-            log("✉️ " + value)
-            $("#sendMsg").val("");
-        }
-
-        //Open WebSocket connection to test script
-        function openws() {
-            log("⏱️ Opening...");
-            let socket = new WebSocket(getWSEndpoint() + "/system/ajgi/interface?script=Speedtest/special/wspeedtest.js");
-            ws = socket;
-
-            socket.onopen = function(e) {
-                log("✔️ Opened");
-                socket.send("DWL");
-            };
-
-            socket.onmessage = function(event) {
-                log(`✔️: ${event.data}`);
-            };
-
-            socket.onclose = function(event) {
-                if (event.wasClean) {
-                    log(`📪 Connection Closed Cleanly code=${event.code} reason=${event.reason}`);
-                } else {
-                    // e.g. server process killed or network down
-                    // event.code is usually 1006 in this case
-                    log(`❌ Connection Closed Unexpectedly`);
-                }
-            };
-
-            socket.onerror = function(error) {
-                log(`❌ ERROR! ${error.message}`);
-            };
-        }
-
-        function log(content) {
-            if (content.indexOf("DATA:") == -1) {
-                $("#incoming").val($("#incoming").val() + content + "\n");
-                $("#incoming").scrollTop($("#incoming")[0].scrollHeight);
-            }
-        }
-
-        function getWSEndpoint() {
-            //Open opeartion in websocket
-            let protocol = "wss://";
-            if (location.protocol !== 'https:') {
-                protocol = "ws://";
-            }
-            wsControlEndpoint = (protocol + window.location.hostname + ":" + window.location.port);
-            return wsControlEndpoint;
-        }
-    </script>
-</body>
-
-</html>

+ 67 - 24
web/Speedtest/index.html

@@ -43,14 +43,33 @@
             </div>
         </div>
         <br>
-        <button class="ui fluid button" onclick="startBench();">Test</button>
+        <div>
+            <div class="ui top attached teal progress" id="progressbar" style="display: none">
+                <div class="bar">
+                    <div class="progress"></div>
+                </div>
+            </div>
+            <button class="ui fluid button" onclick="startBench();" id="startbtn">Test</button>
+        </div>
     </div>
 
 </body>
 <script>
     ao_module_setFixedWindowSize();
+    $('#progressbar').progress({
+        label: 'ratio',
+        text: {
+            ratio: ''
+        },
+        total: 100,
+        percent: 0
+    });
 
     function startBench() {
+        $('#progressbar').removeAttr('style');
+        $('#progressbar').progress('set progress', 0);
+        $("#startbtn").attr('disabled', 'disabled');
+        $("#startbtn").html('Testing...');
         downloadBench();
     }
 
@@ -61,6 +80,7 @@
         socket.onopen = function(e) {
             $("#dl").text("⌛");
             socket.send("DWL");
+            $('#progressbar').progress('set progress', 0);
         };
 
         socket.onmessage = function(event) {
@@ -70,13 +90,18 @@
                     $("#dl").text(bandwidth[0]);
                     $("#dll").text("Download (" + bandwidth[1] + ")");
                     uploadBench();
-					//pingTest();
+                }
+                if (event.data.indexOf("TIME_DIFF") != -1) {
+                    let timediff = parseInt(event.data.split("=")[1]);
+                    $('#progressbar').progress('increment', timediff / 5 * 100);
                 }
             }
         };
 
         socket.onerror = function(error) {
-            $("#dl").text("❌");
+            if ($("#dl").text() != "⌛") {
+                $("#dl").text("❌");
+            }
         };
     }
 
@@ -91,32 +116,40 @@
         };
 
         socket.onerror = function(error) {
-            $("#ul").text("❌");
+            if ($("#ul").text() != "⌛") {
+                $("#ul").text("❌");
+            }
         };
     }
 
     function executeULTest(socket) {
-		let CurrentMB = 0;
+        $('#progressbar').progress('set progress', 0);
+        let CurrentMB = 0;
         let start = new Date();
-		while(socket.bufferedAmount < 10485760 * 10) {
-			socket.send(new ArrayBuffer(32768));
-			CurrentMB += 32768;
-		}
-		let checker = setInterval(function(){ 
-			if(socket.bufferedAmount == 0) {
-				let end = new Date();
-				CurrentDif = (end.getTime() - start.getTime()) / 1000;
-				socket.send("stop");
-				let bandwidth = bytesToSpeed(CurrentMB / CurrentDif).split(" ");
-				$("#ul").text(bandwidth[0]);
-				$("#ull").text("Upload (" + bandwidth[1] + ")");
-				clearInterval(checker);
-				pingTest();
-			}
-		}, 100);
+        while (socket.bufferedAmount < 10485760 * 10) {
+            socket.send(new ArrayBuffer(32768));
+            CurrentMB += 32768;
+        }
+        let checker = setInterval(function() {
+            if (socket.bufferedAmount == 0) {
+                let end = new Date();
+                CurrentDif = (end.getTime() - start.getTime()) / 1000;
+                socket.send("stop");
+                let bandwidth = bytesToSpeed(CurrentMB / CurrentDif).split(" ");
+                $("#ul").text(bandwidth[0]);
+                $("#ull").text("Upload (" + bandwidth[1] + ")");
+                $('#progressbar').progress('set progress', 0);
+                clearInterval(checker);
+                pingTest();
+            } else {
+                //(1 - (socket.bufferedAmount / (10485760 * 10))) * 100
+                $('#progressbar').progress('set progress', 100 - (socket.bufferedAmount / 1048576));
+            }
+        }, 100);
     }
 
     function pingTest() {
+        $('#progressbar').progress('set progress', 0);
         let clientSendTimeStamp = [];
         let serverResponseTimeStamp = [];
         let clientReceiveTimeStamp = [];
@@ -132,10 +165,16 @@
         socket.onmessage = function(event) {
             clientReceiveTimeStamp.push(new Date().getTime());
             serverResponseTimeStamp.push(event.data);
+            if (clientReceiveTimeStamp.length == 5) {
+                setTimeout(showPingResult, 2000, clientSendTimeStamp, serverResponseTimeStamp, clientReceiveTimeStamp);
+            }
+            $('#progressbar').progress('increment', 16.67);
         };
 
         socket.onerror = function(error) {
-            $("#ping").text("❌");
+            if ($("#ping").text() != "⌛") {
+                $("#ping").text("❌");
+            }
         };
     }
 
@@ -144,10 +183,9 @@
         socket.send(clientTime);
         clientSendTimeStamp.push(clientTime.getTime());
         count++;
+        $('#progressbar').progress('increment', 16.67);
         if (count < 3) {
             setTimeout(executePingTest, 1000, socket, clientSendTimeStamp, serverResponseTimeStamp, clientReceiveTimeStamp, count);
-        } else {
-            setTimeout(showPingResult, 2000, clientSendTimeStamp, serverResponseTimeStamp, clientReceiveTimeStamp);
         }
     }
 
@@ -162,6 +200,11 @@
         }
         $("#ping").text(Math.round((diff / clientSendTimeStamp.length) * 100) / 100);
         $("#pingl").text("Ping (ms)");
+        //restart the test
+        $('#progressbar').attr('style', 'display: none');
+        $("#startbtn").html('Re-Test');
+        $("#startbtn").attr('onclick', 'location.reload();');
+        $("#startbtn").removeAttr('disabled');
     }
 
     function getWSEndpoint() {

+ 1 - 3
web/Speedtest/special/wspeedtest.js

@@ -94,14 +94,12 @@ function downloadTest() {
     while (CurrentDif < 5) {
         var CurrentMB = Math.pow(2, CurrentPow);
         var start = new Date();
-		//websocket.send(start);
         for (var i = 0; i < CurrentMB; i++) {
             websocket.send("DATA:" + randomStr);
         }
         var end = new Date();
         CurrentDif = (end.getTime() - start.getTime()) / 1000;
-		//websocket.send(end);
-		//websocket.send(CurrentDif);
+        websocket.send("TIME_DIFF=" + CurrentDif);
         CurrentPow++;
     }
     websocket.send("TTL_SIZE=" + bytesToSize(CurrentMB * filesize));

+ 0 - 161
web/Speedtest/ul.html

@@ -1,161 +0,0 @@
-<!DOCTYPE html>
-<html>
-
-<head>
-    <meta name="apple-mobile-web-app-capable" content="yes" />
-    <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1" />
-    <meta charset="UTF-8">
-    <meta name="theme-color" content="#4b75ff">
-    <link rel="stylesheet" href="../script/semantic/semantic.min.css">
-    <script src="../script/jquery.min.js"></script>
-    <script src="../script/ao_module.js"></script>
-    <script src="../script/semantic/semantic.min.js"></script>
-    <title>WebSocket Test</title>
-</head>
-
-<body>
-    <br><br>
-    <div class="ui container">
-        <h3>WebSocket Testing Interface</h3>
-        <div class="ui form">
-            <div class="field">
-                <label>Recv</label>
-                <textarea id="incoming"></textarea>
-            </div>
-            <div class="field">
-                <label>Send</label>
-                <input type="text" id="sendMsg">
-            </div>
-            <div class="field">
-                <button class="ui blue button" onclick="sendws();">Send</button>
-            </div>
-        </div>
-        <br>
-        <button class="ui button" onclick="openws();">Open Connection</button>
-    </div>
-
-    <script>
-        var ws;
-        var nolog = false;
-
-        $(window).ready(function() {
-            $("#incoming").val("");
-        });
-
-        //Send WebSocket
-        function sendws() {
-            var value = $("#sendMsg").val();
-            ws.send(value);
-            log("✉️ " + value)
-            $("#sendMsg").val("");
-        }
-
-        //Open WebSocket connection to test script
-        function openws() {
-            log("⏱️ Opening...");
-            let socket = new WebSocket(getWSEndpoint() + "/system/ajgi/interface?script=Speedtest/special/wspeedtest.js");
-            ws = socket;
-
-            socket.onopen = function(e) {
-                log("✔️ Opened");
-                socket.send("UPL");
-                uploadtest(socket);
-            };
-
-            socket.onmessage = function(event) {
-                log(`✔️: ${event.data}`);
-            };
-
-            socket.onclose = function(event) {
-                if (event.wasClean) {
-                    log(`📪 Connection Closed Cleanly code=${event.code} reason=${event.reason}`);
-                } else {
-                    // e.g. server process killed or network down
-                    // event.code is usually 1006 in this case
-                    log(`❌ Connection Closed Unexpectedly`);
-                }
-            };
-
-            socket.onerror = function(error) {
-                log(`❌ ERROR! ${error.message}`);
-            };
-        }
-
-        function log(content) {
-            if (content.indexOf("DATA:") == -1) {
-                $("#incoming").val($("#incoming").val() + content + "\n");
-                $("#incoming").scrollTop($("#incoming")[0].scrollHeight);
-            }
-        }
-
-        function getWSEndpoint() {
-            //Open opeartion in websocket
-            let protocol = "wss://";
-            if (location.protocol !== 'https:') {
-                protocol = "ws://";
-            }
-            wsControlEndpoint = (protocol + window.location.hostname + ":" + window.location.port);
-            return wsControlEndpoint;
-        }
-
-        function uploadtest(socket) {
-            log("OK!");
-            var randomStr = rnd(32768);
-            var filesize = "DATA:".length + randomStr.length;
-            log("Generated");
-            setTimeout(executeULTest, 1000, socket, 0, 0, randomStr, filesize);
-        }
-
-        function executeULTest(socket, CurrentPow, CurrentDif, randomStr, filesize) {
-            var CurrentMB = Math.pow(2, CurrentPow);
-            log("Current File Size:" + bytesToSize(CurrentMB * filesize));
-            var start = new Date();
-            //websocket.send("Start: " + start.toString());
-            for (var i = 0; i < CurrentMB; i++) {
-                socket.send("DATA:" + randomStr);
-            }
-            var end = new Date();
-            //websocket.send("End: " + end.toString());
-            CurrentDif = (end.getTime() - start.getTime()) / 1000;
-            CurrentPow++;
-            if (CurrentDif < 5) {
-                setTimeout(executeULTest, 1000, socket, CurrentPow, CurrentDif, randomStr, filesize);
-            } else {
-                socket.send("stop");
-                log("Total transmitted:" + bytesToSize(CurrentMB * filesize));
-                log("Total time:" + CurrentDif + "s");
-                log("Bandwidth:" + bytesToSize(CurrentMB * filesize / CurrentDif) + "/s OR " + bytesToSpeed(CurrentMB * filesize / CurrentDif));
-            }
-        }
-
-        //https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
-        function rnd(length) {
-            var result = '';
-            var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
-            var charactersLength = characters.length;
-            for (var i = 0; i < length; i++) {
-                result += characters.charAt(Math.floor(Math.random() *
-                    charactersLength));
-            }
-            return result;
-        }
-
-        //https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript
-        function bytesToSize(bytes) {
-            var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
-            if (bytes == 0) return '0 Byte';
-            var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
-            return Math.round((bytes / Math.pow(1024, i)) * 100, 3) / 100 + ' ' + sizes[i];
-        }
-
-        function bytesToSpeed(bytes) {
-            bytes = bytes * 8;
-            var sizes = ['bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps'];
-            if (bytes == 0) return '0 Byte';
-            var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1000)));
-            return Math.round((bytes / Math.pow(1000, i)) * 100, 3) / 100 + ' ' + sizes[i];
-        }
-    </script>
-</body>
-
-</html>