receive.ejs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Sendd - Receive a file</title>
  5. <link rel='stylesheet' href='/stylesheets/style.css' />
  6. <script src="http://cdn.peerjs.com/0.3/peer.js"></script>
  7. </head>
  8. <body>
  9. <h1>Receive a file</h1>
  10. <p>Give the sender the following id:</p>
  11. <script>
  12. // No API key required when not using cloud server
  13. var peer = new Peer({host: 'localhost', port: 9000, path: '/node_modules/peerjs'});
  14. peer.on('open', function(id) {
  15. document.body.appendChild(document.createTextNode(peer.id));
  16. });
  17. peer.on('connection', function(conn) {
  18. conn.on('data', function(data) {
  19. var dataBlob = new Blob([data.file], {type: data.type});
  20. var url = window.URL.createObjectURL(dataBlob);
  21. var a = document.createElement("a");
  22. var linkText = document.createTextNode("Download");
  23. a.appendChild(linkText);
  24. a.href = url;
  25. a.setAttribute("download", data.name);
  26. document.body.appendChild(a);
  27. });
  28. });
  29. </script>
  30. </body>
  31. </html>