Created
October 24, 2017 15:21
-
-
Save mrLSD/1a34546022db52968a298578ef856b94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <title>Proxy tester</title> | |
| <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> | |
| <script type="text/javascript"> | |
| $(function() { | |
| var conn; | |
| var msg = $("#msg"); | |
| var log = $("#log"); | |
| replyOkJson = $('#replyOkJson')[0]; | |
| function appendLog(msg) { | |
| var d = log[0] | |
| var doScroll = d.scrollTop == d.scrollHeight - d.clientHeight; | |
| msg.appendTo(log) | |
| if (doScroll) { | |
| d.scrollTop = d.scrollHeight - d.clientHeight; | |
| } | |
| } | |
| $("#form").on('submit', function() { | |
| if (!conn) { | |
| return false; | |
| } | |
| if (!msg.val()) { | |
| return false; | |
| } | |
| conn.send(msg.val()); | |
| msg.val(""); | |
| return false; | |
| }); | |
| if (window["WebSocket"]) { | |
| conn = new WebSocket("ws://{{$}}/ws"); | |
| conn.onclose = function(evt) { | |
| appendLog($("<div><b>Connection closed.</b></div>")) | |
| } | |
| conn.onmessage = function(evt) | |
| { | |
| var events = JSON.parse(evt.data); | |
| appendLog($("<div/>").text(evt.data)) | |
| console.log('got message', events); | |
| var ok = []; | |
| for(var i = 0; i < events.length; i++) | |
| { | |
| var evt = events[i]; | |
| if(evt.value) | |
| { | |
| console.log('push ok for', evt); | |
| ok.push({ | |
| eventName: evt.eventName, | |
| proxyEventId :evt.proxyEventId, | |
| reply: { status: "ok" } | |
| }); | |
| } | |
| } | |
| if(ok.length && replyOkJson.checked) | |
| { | |
| console.log('send ok for', ok); | |
| conn.send(JSON.stringify(ok)); | |
| } | |
| } | |
| } | |
| else | |
| { | |
| appendLog($("<div><b>Your browser does not support WebSockets.</b></div>")) | |
| } | |
| }); | |
| </script> | |
| <style type="text/css"> | |
| html { | |
| overflow: hidden; | |
| } | |
| body { | |
| overflow: hidden; | |
| padding: 0; | |
| margin: 0; | |
| width: 100%; | |
| height: 100%; | |
| background: gray; | |
| } | |
| #log { | |
| background: white; | |
| margin: 0; | |
| padding: 0.5em 0.5em 0.5em 0.5em; | |
| position: absolute; | |
| top: 0.5em; | |
| left: 0.5em; | |
| right: 0.5em; | |
| bottom: 13em; | |
| overflow: auto; | |
| } | |
| #form { | |
| padding: 0 0.5em 0 0.5em; | |
| margin: 0; | |
| position: absolute; | |
| bottom: 1em; | |
| left: 0px; | |
| width: 100%; | |
| overflow: hidden; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div id="log"></div> | |
| <form id="form"> | |
| <input type="submit" value="Send" style="height:10% ; width:10%"/> | |
| <!-- <input type="text" rows="10" id="msg" size="120" maxlength="9999999"/> --> | |
| <textarea name="text" cols="80" rows="5" id="msg"></textarea> | |
| <input type="checkbox" id="replyOkJson" checked=true value="replyOkJson">reply Ok Json<br> | |
| </form> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment