Code Monkey home page Code Monkey logo

rtc-p2p's Introduction

rtc-p2p

This is a proof of concept and demo of using WebRTC data channels to create a browser-based P2P file sharing network. The actual implementation is just a proof-of-concept, and not actually optimized for any real world usage.

Browser Compatibility

So far, this has only been tested with Chrome 26. In order to work, the Enable RTCDataChannel flag must be enabled in Chrome on the chrome://flags configuration page.

Limitations

Since this is a proof-of-concept, it has a number of limitations that mean it cannot be used for real life file sharing:

  • Only the first 100 bytes of any file are shared. There is a size limit on each message on a data channel. Unfortunately, Chrome 26 doesn't support reliable transport, so the data channel is UDP-like rather than TCP-like. This means that building a reliable transport for transferring an entire file in multiple blocks would require some work, and is beyond the scope of this proof-of-concept.

  • File requests are sent to all available peers. If there are multiple peers with the same file available, they will all respond to the request.

  • Each peer automatically connects to all other peers. This is clearly not scalable, but works for the purposes of this demonstration.

Usage

Install with npm install and start with npm start. The server will start at http://localhost:8000.

Browse to the address above in two or more tabs, and register some files in each tab (preferrably text files).

Copy a file hash from one tab into another tab's Request File box and request the file. The first 100 bytes of the request file should be transferred.

Node? I thought this was P2P?

Files are transferred directly between peers, but a server is needed for two things:

  1. WebRTC requires a server or some sort of intermediary to exchange signaling and session data. This must be done before a connection between two peers can be established.

    In this case, each peer communicates with the server using WebSockets to exchange signaling data with other peers.

  2. rtc-p2p uses a web worker to compute the SHA1 hashes of registered files in the background. Web workers run on the client, but must be served from a server.

Further Reading

Slides from my presentation on this project at sthlm.js are available at: http://www.rvl.io/rohansingh/p2p

rtc-p2p's People

Contributors

rohansingh avatar

Watchers

Pierre Maoui 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.