New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

peer-file

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

peer-file

A little library for doing p2p file transfers over webrtc.

latest
npmnpm
Version
0.0.6
Version published
Maintainers
1
Created
Source

peer-file

peer-file is a little library for doing p2p file transfers over webrtc.

Browser support

Install

$ npm install peer-file 

Usage

<script src="/lib/peer.js"></script>
<script src="build.js"></script>
var send = require('peer-file/send')
var receive = require('peer-file/receive')
var peer = new Peer('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) {
        new Blob(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.

Complete API

// Single use
peerfile.send(connection, file)
  .on('accept', function() {})
  .on('reject', function() {})
  .on('progress', function(bytesSent) {})
  .on('complete', function() {})
  .on('cancel', function() {})
  .pause()
  .resume()
  .cancel()

// Long running
peerfile.receive(connection)
  .on('incoming', function(file) {})
  .on('progress', function(file, bytesReceived) {})
  .on('complete', function(file) {})
  .on('cancel', function(file) {})
  .accept(file)
  .reject(file)
  .pause(file)
  .resume(file)
  .cancel(file)

License

MIT

Keywords

webrtc

FAQs

Package last updated on 23 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts