send.ejs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Sendd - Send a file</title>
  5. <link rel='stylesheet' href='/stylesheets/style.css' />
  6. <script src="http://cdn.peerjs.com/0.3/peer.js"></script>
  7. <script>
  8. // No API key required when not using cloud server
  9. var peer = new Peer({host: 'localhost', port: 9000, path: '/node_modules/peerjs'});
  10. peer.on('open', function(id) {
  11. console.log('My peer ID is: ' + id);
  12. });
  13. function send() {
  14. // TODO figure out why this isn't calling the bottom stuff
  15. var valid = true;
  16. if(!document.getElementById("file_to_send").files[0]) {
  17. valid = false;
  18. alert("Please select a file.");
  19. }
  20. if(!document.getElementById("dest_id").value) {
  21. valid = false;
  22. alert("Please provide a Destination ID.");
  23. }
  24. if(!valid){
  25. return;
  26. }
  27. var blob = new Blob([document.getElementById("file_to_send").files[0]], {type: document.getElementById("file_to_send").files[0].type});
  28. var con = peer.connect(document.getElementById("dest_id").value);
  29. con.send({
  30. name: document.getElementById("file_to_send").files[0].name,
  31. file: blob,
  32. type: document.getElementById("file_to_send").files[0].type
  33. });
  34. }
  35. </script>
  36. </head>
  37. <body>
  38. <h1>Send a file</h1>
  39. <input type="file" id="file_to_send"><br/><br/>
  40. <label>Destination ID (ask your reciever to send it to you):</label><br/>
  41. <input type="text" id="dest_id"></br></br>
  42. <button type="button" onclick="send();">Send</button>
  43. </body>
  44. </html>