PageRenderTime 62ms CodeModel.GetById 20ms app.highlight 12ms RepoModel.GetById 18ms app.codeStats 1ms

/js/lib/Socket.IO-node/example/chat-ssl.html

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
HTML | 61 lines | 52 code | 9 blank | 0 comment | 0 complexity | 31978262d7e8a926dce775e6cb808760 MD5 | raw file
 1<!doctype html>
 2<html>
 3  <head>
 4    <title>socket.io client test</title>
 5        
 6    <script src="/json.js"></script> <!-- for ie -->
 7    <script src="/socket.io/socket.io.js"></script>
 8  </head>
 9  <body>
10    
11    <script>
12      function message(obj){
13        var el = document.createElement('p');
14        if ('announcement' in obj) el.innerHTML = '<em>' + esc(obj.announcement) + '</em>';
15        else if ('message' in obj) el.innerHTML = '<b>' + esc(obj.message[0]) + ':</b> ' + esc(obj.message[1]);
16        document.getElementById('chat').appendChild(el);
17        document.getElementById('chat').scrollTop = 1000000;
18      }
19      
20      function send(){
21        var val = document.getElementById('text').value;
22        socket.send(val);
23        message({ message: ['you', val] });
24        document.getElementById('text').value = '';
25      }
26      
27      function esc(msg){
28        return msg.replace(/</g, '&lt;').replace(/>/g, '&gt;');
29      };
30      
31      var socket = new io.Socket(null, {port: 443, secure: true, rememberTransport: false});
32      socket.connect();
33      socket.on('message', function(obj){
34        if ('buffer' in obj){
35          document.getElementById('form').style.display='block';
36          document.getElementById('chat').innerHTML = '';
37          
38          for (var i in obj.buffer) message(obj.buffer[i]);
39        } else message(obj);
40      });
41    </script>
42    
43    <h1>Sample chat client</h1>
44    <div id="chat"><p>Connecting...</p></div>
45    <form id="form" onsubmit="send(); return false">
46      <input type="text" autocomplete="off" id="text"><input type="submit" value="Send">
47    </form>
48    
49    <style>
50      #chat { height: 300px; overflow: auto; width: 800px; border: 1px solid #eee; font: 13px Helvetica, Arial; }
51      #chat p { padding: 8px; margin: 0; }
52      #chat p:nth-child(odd) { background: #F6F6F6; }
53      #form { width: 782px; background: #333; padding: 5px 10px; display: none; }
54      #form input[type=text] { width: 700px; padding: 5px; background: #fff; border: 1px solid #fff; }
55      #form input[type=submit] { cursor: pointer; background: #999; border: none; padding: 6px 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px; margin-left: 5px; text-shadow: 0 1px 0 #fff; }
56      #form input[type=submit]:hover { background: #A2A2A2; }
57      #form input[type=submit]:active { position: relative; top: 2px; }
58    </style>
59    
60  </body>
61</html>