index.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta name="apple-mobile-web-app-capable" content="yes" />
  5. <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1, maximum-scale=1" />
  6. <meta charset="UTF-8">
  7. <meta name="theme-color" content="#4b75ff">
  8. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  9. <script src="../script/jquery.min.js"></script>
  10. <script src="../script/ao_module.js"></script>
  11. <script src="../script/semantic/semantic.min.js"></script>
  12. <title>WebSocket Test</title>
  13. </head>
  14. <body>
  15. <br><br>
  16. <div class="ui container">
  17. <h3>WebSocket Testing Interface</h3>
  18. <div class="ui form">
  19. <div class="field">
  20. <label>Recv</label>
  21. <textarea id="incoming"></textarea>
  22. </div>
  23. <div class="field">
  24. <label>Send</label>
  25. <input type="text" id="sendMsg">
  26. </div>
  27. <div class="field">
  28. <button class="ui blue button" onclick="sendws();">Send</button>
  29. </div>
  30. </div>
  31. <br>
  32. <button class="ui button" onclick="openws();">Open Connection</button>
  33. </div>
  34. <script>
  35. var ws;
  36. var nolog = false;
  37. $(window).ready(function() {
  38. $("#incoming").val("");
  39. });
  40. //Send WebSocket
  41. function sendws() {
  42. var value = $("#sendMsg").val();
  43. ws.send(value);
  44. log("✉️ " + value)
  45. $("#sendMsg").val("");
  46. }
  47. //Open WebSocket connection to test script
  48. function openws() {
  49. log("⏱️ Opening...");
  50. let socket = new WebSocket(getWSEndpoint() + "/system/ajgi/interface?script=Speedtest/special/wspeedtest.js");
  51. ws = socket;
  52. socket.onopen = function(e) {
  53. log("✔️ Opened");
  54. socket.send("DWL");
  55. };
  56. socket.onmessage = function(event) {
  57. log(`✔️: ${event.data}`);
  58. };
  59. socket.onclose = function(event) {
  60. if (event.wasClean) {
  61. log(`📪 Connection Closed Cleanly code=${event.code} reason=${event.reason}`);
  62. } else {
  63. // e.g. server process killed or network down
  64. // event.code is usually 1006 in this case
  65. log(`❌ Connection Closed Unexpectedly`);
  66. }
  67. };
  68. socket.onerror = function(error) {
  69. log(`❌ ERROR! ${error.message}`);
  70. };
  71. }
  72. function log(content) {
  73. if (content.indexOf("DATA:") == -1) {
  74. $("#incoming").val($("#incoming").val() + content + "\n");
  75. $("#incoming").scrollTop($("#incoming")[0].scrollHeight);
  76. }
  77. }
  78. function getWSEndpoint() {
  79. //Open opeartion in websocket
  80. let protocol = "wss://";
  81. if (location.protocol !== 'https:') {
  82. protocol = "ws://";
  83. }
  84. wsControlEndpoint = (protocol + window.location.hostname + ":" + window.location.port);
  85. return wsControlEndpoint;
  86. }
  87. </script>
  88. </body>
  89. </html>