peer-file is a little library for doing p2p file transfers over webrtc.
Install
$ npm install peer-file
Usage
<scriptsrc="/lib/peer.js"></script>
<scriptsrc="build.js"></script>
var send =require('peer-file/send')
var receive =require('peer-file/receive')
var peer =newPeer('some-id')
peer.on('connection',function(connection){
connection.on('open',function(){
// Receive
receive(connection)
.on('incoming',function(file){
this.accept(file)||this.reject(file)
})
.on('progress',function(file,bytesReceived){
Math.ceil(bytesReceived /file.size*100)
})
.on('complete',function(file){
newBlob(file.data,{ type:file.type})
})
// Send
var file =input.files[0]
send(connection, file)
.on('progress',function(bytesSent){
Math.ceil(bytesSent /file.size*100)
})
})
})
peer-file was developed using peerjs, however it isn’t bound to that library. So long as the provided connection object emits data events, has a send method, and can handle JSON, it could be substituted.