Skip to content

Instantly share code, notes, and snippets.

@flaviocopes
Created November 23, 2018 11:08
Show Gist options
  • Save flaviocopes/0843a32f8e68965b094a6b55f8f1f652 to your computer and use it in GitHub Desktop.
Save flaviocopes/0843a32f8e68965b094a6b55f8f1f652 to your computer and use it in GitHub Desktop.

Revisions

  1. flaviocopes created this gist Nov 23, 2018.
    16 changes: 16 additions & 0 deletions sender.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    document.addEventListener('DOMContentLoaded', event => {
    const peer = new Peer('sender', { host: 'localhost', port: 9000, path: '/' })

    const conn = peer.connect('receiver')

    document.querySelector('input').onchange = function(event) {
    const file = event.target.files[0]
    const blob = new Blob(event.target.files, { type: file.type })

    conn.send({
    file: blob,
    filename: file.name,
    filetype: file.type
    })
    }
    })