example-telemetryEnabled.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no" />
  6. <title>HTML5 Speedtest</title>
  7. <style type="text/css">
  8. html,body{
  9. border:none; padding:0; margin:0;
  10. background:#FFFFFF;
  11. color:#202020;
  12. }
  13. body{
  14. text-align:center;
  15. font-family:"Roboto",sans-serif;
  16. }
  17. h1{
  18. color:#404040;
  19. }
  20. #startStopBtn{
  21. display:inline-block;
  22. margin:0 auto;
  23. color:#6060AA;
  24. background-color:rgba(0,0,0,0);
  25. border:0.15em solid #6060FF;
  26. border-radius:0.3em;
  27. transition:all 0.3s;
  28. box-sizing:border-box;
  29. width:8em; height:3em;
  30. line-height:2.7em;
  31. cursor:pointer;
  32. box-shadow: 0 0 0 rgba(0,0,0,0.1), inset 0 0 0 rgba(0,0,0,0.1);
  33. }
  34. #startStopBtn:hover{
  35. box-shadow: 0 0 2em rgba(0,0,0,0.1), inset 0 0 1em rgba(0,0,0,0.1);
  36. }
  37. #startStopBtn.running{
  38. background-color:#FF3030;
  39. border-color:#FF6060;
  40. color:#FFFFFF;
  41. }
  42. #startStopBtn:before{
  43. content:"Start";
  44. }
  45. #startStopBtn.running:before{
  46. content:"Abort";
  47. }
  48. #test{
  49. margin-top:2em;
  50. margin-bottom:12em;
  51. }
  52. div.testArea{
  53. display:inline-block;
  54. width:14em;
  55. height:9em;
  56. position:relative;
  57. box-sizing:border-box;
  58. }
  59. div.testName{
  60. position:absolute;
  61. top:0.1em; left:0;
  62. width:100%;
  63. font-size:1.4em;
  64. z-index:9;
  65. }
  66. div.meterText{
  67. position:absolute;
  68. bottom:1.5em; left:0;
  69. width:100%;
  70. font-size:2.5em;
  71. z-index:9;
  72. }
  73. #dlText{
  74. color:#6060AA;
  75. }
  76. #ulText{
  77. color:#309030;
  78. }
  79. #pingText,#jitText{
  80. color:#AA6060;
  81. }
  82. div.meterText:empty:before{
  83. color:#505050 !important;
  84. content:"0.00";
  85. }
  86. div.unit{
  87. position:absolute;
  88. bottom:2em; left:0;
  89. width:100%;
  90. z-index:9;
  91. }
  92. div.testGroup{
  93. display:inline-block;
  94. }
  95. @media all and (max-width:65em){
  96. body{
  97. font-size:1.5vw;
  98. }
  99. }
  100. @media all and (max-width:40em){
  101. body{
  102. font-size:0.8em;
  103. }
  104. div.testGroup{
  105. display:block;
  106. margin: 0 auto;
  107. }
  108. }
  109. </style>
  110. <script type="text/javascript">
  111. function I(id){return document.getElementById(id);}
  112. var w=null; //speedtest worker
  113. function startStop(){
  114. if(w!=null){
  115. //speedtest is running, abort
  116. w.postMessage('abort');
  117. w=null;
  118. I("startStopBtn").className="";
  119. initUI();
  120. }else{
  121. //test is not running, begin
  122. w=new Worker('speedtest_worker.min.js');
  123. w.postMessage('start {"telemetry_level":"basic"}'); //Add optional parameters (see doc.md)
  124. I("startStopBtn").className="running";
  125. w.onmessage=function(e){
  126. var data=JSON.parse(e.data);
  127. var status=data.testState
  128. if(status>=4){
  129. //test completed
  130. I("startStopBtn").className="";
  131. w=null;
  132. }
  133. I("ip").textContent=data.clientIp;
  134. I("dlText").textContent=(status==1&&data.dlStatus==0)?"...":data.dlStatus;
  135. I("ulText").textContent=(status==3&&data.ulStatus==0)?"...":data.ulStatus;
  136. I("pingText").textContent=data.pingStatus;
  137. I("jitText").textContent=data.jitterStatus;
  138. };
  139. }
  140. }
  141. //poll the status from the worker every 200ms (this will also update the UI)
  142. setInterval(function(){
  143. if(w) w.postMessage('status');
  144. },200);
  145. //function to (re)initialize UI
  146. function initUI(){
  147. I("dlText").textContent="";
  148. I("ulText").textContent="";
  149. I("pingText").textContent="";
  150. I("jitText").textContent="";
  151. I("ip").textContent="";
  152. }
  153. </script>
  154. </head>
  155. <body>
  156. <h1>HTML5 Speedtest - Telemetry example</h1>
  157. <div id="startStopBtn" onclick="startStop()"></div>
  158. <div id="test">
  159. <div class="testGroup">
  160. <div class="testArea">
  161. <div class="testName">Download</div>
  162. <div id="dlText" class="meterText"></div>
  163. <div class="unit">Mbps</div>
  164. </div>
  165. <div class="testArea">
  166. <div class="testName">Upload</div>
  167. <div id="ulText" class="meterText"></div>
  168. <div class="unit">Mbps</div>
  169. </div>
  170. </div>
  171. <div class="testGroup">
  172. <div class="testArea">
  173. <div class="testName">Ping</div>
  174. <div id="pingText" class="meterText"></div>
  175. <div class="unit">ms</div>
  176. </div>
  177. <div class="testArea">
  178. <div class="testName">Jitter</div>
  179. <div id="jitText" class="meterText"></div>
  180. <div class="unit">ms</div>
  181. </div>
  182. </div>
  183. <div id="ipArea">
  184. IP Address: <span id="ip"></span>
  185. </div>
  186. </div>
  187. <div>Basic telemetry is active; results will be saved in your database, without the full log. If the results don't appear, check the settings in telemetry_settings.php</div>
  188. <a href="https://github.com/adolfintel/speedtest">Source code</a>
  189. <script type="text/javascript">initUI();</script>
  190. </body>
  191. </html>