Advertisement
Weslei_Ramos

Untitled

Sep 14th, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.03 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset="utf-8">
  5.     <title>birl</title>
  6. </head>
  7. <body>
  8.     <p id="saida"></p>
  9.     <textarea id="textArea">
  10. JAULA SHOW
  11.     CE QUER VER ISSO: "BIRL PORRA!"
  12. SAINDO DA JAULA
  13.     </textarea>
  14.     <button id="enviar">Enviar</button>
  15.     <script type="text/javascript">
  16.         window.addEventListener('load', function() {
  17.             var txtArea = document.getElementById('textArea');
  18.             var webSocket = new WebSocket('ws://127.0.0.1:8080');
  19.             var ultimoCodigo = "";
  20.  
  21.             webSocket.addEventListener('open', function() {
  22.                 console.log('conectado');
  23.             });
  24.  
  25.             webSocket.addEventListener('message', function(msg) {
  26.                 var json = JSON.parse(msg.data);
  27.                 document.getElementById('saida').innerHTML = json['output'];
  28.             });
  29.  
  30.             document.getElementById('enviar').addEventListener('click', function() {
  31.                 if (textArea.value != ultimoCodigo) {
  32.                     var json = {
  33.                         codigo : txtArea.value
  34.                     };
  35.                     webSocket.send(JSON.stringify(json));
  36.                     ultimoCodigo = json.codigo;
  37.                 }
  38.             });
  39.         })
  40.     </script>
  41. </body>
  42. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement