peer1.html 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>Peer Test</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta http-equiv="Content-Language" content="en-us">
  7. <meta name="description" content="">
  8. <meta name="keywords" content="">
  9. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
  10. <script type="text/javascript" src="/peer.js"></script>
  11. <script>
  12. $(document).ready(function() {
  13. connections = {};
  14. $('#connect').click(function() {
  15. var source = $('#source').val();
  16. sink = new Peer({ host: 'localhost', port: '9000', debug: true });
  17. sink.connect(source, { username: 'michelle' }, function(err, connection) {
  18. x = connection;
  19. console.log('got connection');
  20. console.log(connection);
  21. connection.on('data', function(data) {
  22. console.log(data);
  23. });
  24. connection.send('Hi there!');
  25. connections[source] = connection;
  26. });
  27. sink.on('ready', function() {
  28. });
  29. });
  30. });
  31. </script>
  32. </head>
  33. <body>
  34. This is a P2P peer.
  35. <br><br>
  36. Enter source ID to connect to:
  37. <br><input type="text" id="source"></input>
  38. <button id="connect">Connect</button>
  39. </body>
  40. </html>