Neutered Paranoid Meerkat

    simple-peer-files
    TypeScript icon, indicating that this package has built-in type declarations

    1.2.3 • Public • Published

    WebRTC Simple File Transfer

    A simple library to send & receive files over WebRTC data channels. All you need to pass is a simple-peer object, the file, and an ID!

    Features

    • Pause/Resume file transfers
    • No file size limit
    • Independent, just pass a simple-peer object
    • Multiple file transfers at the same time using the same simple-peer object

    Examples

    Apps Made With SPF

    Simple Example

    Open this webpage in two separate browser windows. This simple example is based on the example shown in simple-peer README

    Sender :

    import SimplePeerFiles from 'simple-peer-files'
    const spf = new SimplePeerFiles()
    
    function readyToSend () {
      // peer is the SimplePeer object connection to receiver
      spf.send(peer, 'myFileID', file).then(transfer => {
        transfer.on('progress', sentBytes => {
          console.log(sentBytes)
        })
        transfer.start()
      })
    }
    

    Receiver :

    import SimplePeerFiles from 'simple-peer-files'
    const spf = new SimplePeerFiles()
    
    // peer is the SimplePeer object connection to sender
    spf.receive(peer, 'myFileID').then(transfer => {
      transfer.on('progress', sentBytes => {
        console.log(sentBytes)
      })
    
      // Call readyToSend() in the sender side
      peer.send('heySenderYouCanSendNow')
    })
    

    You have to call spf.receive() in receiver before you call spf.send() in sender. This is to prepare the receiver to accept file before sending starts. This also allows to implement a functionality for the receiver to accept or reject the file.

    Install

    npm i simple-peer-files

    DownloadsWeekly Downloads

    68

    Version

    1.2.3

    License

    MPL-2.0

    Unpacked Size

    63.2 kB

    Total Files

    25

    Last publish

    Collaborators

    • subins2000