GithubHelp home page GithubHelp logo

imclab / p2pxhr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from peer5/p2pxhr

0.0 1.0 0.0 2.83 MB

An API that seamlessly empowers your xhr request through an on-the-fly peer-to-peer network created from your site's visitors

p2pxhr's Introduction

P2PXHR

P2PXHR is a framework that seamlessly power-ups your xhr (AJAX) requests through an on-the-fly peer-to-peer network created from your site's visitors.
It seamlessly chooses between your servers and other peers to get the response.
It is intended to make your content delivery better by making your content deliver when your servers are loaded.
Built on top of [WebRTC][1] DataChannels.

How

The client side gets a URL indicating the resource that needs to be fetch. It then connects to a nodejs service (coordinator) that awares of all users that have/need this resource. The coordinator creates a mesh network by connecting peers that most likely can help each other. The client in the meantime fetches HTTP chunks using HTTP range requests for some blocks. Once connected to other peers the client requests needed blocks from them.

Illustration: The client can be connected to 3 peers at the same time, requesting blocks #12, #15, #54 from peer1, #123 from peer2, #58, #59 from peer3 and at the same time serving blocks #2, #3, #4. At the same time this client requests blocks #6-#9 from the HTTP server.

Demos

File download demo - live

Simple img demo - live

Lazy load img demo - live

The image request sends an xhr request for receiving an image from the network. The file downloader sends an xhr request for receiving a larger file. It indicates the amount of data transferred from peers and regular HTTP. In case no additional peers are downloading the file at the moment, open another tab in incognito mode to see the peer-to-peer magic in action.

Getting started

Basic example of creating a new assisted xhr request using p2pxhr:

var request = new peer5.Request();
request.open('GET', 'http://path/to/a/big/file.json');
request.onload = function(e) {
  console.log(this.response);
  ...
};
request.send();

This means you can simply search and replace XMLHttpRequest with peer5.Request() in your code, and you are all set with peer-assisted requests.

Uploading a.k.a seeding

TBD

Supported Browsers

Desktop

  • Chrome 26+
  • Firefox 23+
  • Opera 18

Android:

  • Chrome 29+
  • Firefox 24+
  • Opera 12

Derived from the [WebRTC][1] supported browsers [1]: http://en.wikipedia.org/wiki/WebRTC

p2pxhr's People

Contributors

russoj avatar shacharz avatar whadar avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.