phone-a-friend
phone-a-friend copied to clipboard
Utilizes WebRTC and service-workers in order to offload retrieval of assets from the server to other peers on the network
#Phone A Friend#
phone-a-friend
is a library utilizing service-workers and WebRTC in order to offload retrieval of assets from the server to other peers on the network.
In brief the way that it works is:
- A service worker is registered
- It intercepts all HTTP requests (images, css, AJAX)
- It asks the server if it knows of anyone on the network who has that asset already
- If not, the service worker will load the asset as normal
- If there is, a P2P connection will be made with them and the asset will be requested from them
- That asset is then checked to ensure integrity and if found valid, will be used
This project has several goals
- Make it easy for developers to integrate into their project
- Because it uses service workers, it does not require rewriting your application for all HTTP requests to be intercepted
- Ensure the integrity of assets loaded over the P2P network
- Using the web crypto api, a file is hashed and checked against a hash provided by the server to ensure integrity
- Save bandwidth
- Because we are loading assets via webRTC we can reduce bandwidth consumption on the server
###Getting Started### To get started with this project:
- clone this repository
- install redis http://redis.io/topics/quickstart
- install nodejs/iojs https://nodejs.org/ https://iojs.org/en/index.html
- install peerjs globally
npm install -g peerjs
- go into the server directory and run
npm start
- go into the client directory and run
npm start
- Pull up Chrome Canary and Chrome Beta and navigate to
http://localhost:8080/demo.html
- Open your console in each browser and refresh each one a few times and watch them load assets from one another
Please contribute and help make this project even better!