Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/subins2000/simple-peer-files
A library to send files over WebRTC
https://github.com/subins2000/simple-peer-files
peer simplepeer transfers webrtc
Last synced: about 2 months ago
JSON representation
A library to send files over WebRTC
- Host: GitHub
- URL: https://github.com/subins2000/simple-peer-files
- Owner: subins2000
- License: mpl-2.0
- Created: 2020-08-09T22:02:44.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-04-20T07:11:44.000Z (over 1 year ago)
- Last Synced: 2024-10-13T15:56:01.474Z (3 months ago)
- Topics: peer, simplepeer, transfers, webrtc
- Language: TypeScript
- Homepage:
- Size: 2.92 MB
- Stars: 35
- Watchers: 1
- Forks: 9
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-webrtc - simple-peer-files - A library to send files over WebRTC. (Libraries / JavaScript)
README
# WebRTC Simple File Transfer
A simple library to send & receive files over WebRTC data channels. All you need to pass is a [simple-peer](https://www.npmjs.com/package/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
* [WebDrop](https://WebDrop.Space) - A web app to share files and messages across all your devices. [Try It Here!]()
### Simple Example
Open [this webpage](https://codepen.io/subins2000/pen/abNOggM) in two separate browser windows. This simple example is based on the example shown in [simple-peer README](https://github.com/feross/simple-peer#usage)
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.
Thanks to [Andrew Bastin's justshare](https://github.com/AndrewBastin/justshare-client/tree/master/src/api) for being a reference in making this library.