P is for peer-to-peer networking with browsers
P is a small framework used to create browser-to-browser networks (as opposed to just a connection). With P, you can:
- Connect to other browsers using a simple WebSocket server.
- Connect to other browsers using your established connections to other browsers. This is what makes P unique: it allows for transitive connections across peers, allowing easy creation of mesh networks.
After a connection is established the middleman is no longer nescessary – no proxies are involved.
This is made possible by an unstable and young technology -- WebRTC. Currently, only Chrome and Firefox support this technology.
onramp, a simple WebSocket server, is used as the signaling channel to establish initial connections.
API
// Initializingvar rootNode = P; // create the root node // Connection managementvar webSocketNode = rootNode; // connect to an onramp WebSocket servervar webRtcNode = webSocketNode; // connect to a peer using an onramp connectionvar webRtcNode = webRtcNode; // connect to a peer using an existing peer connectionanyNode; // close the connectionanyNode; // return true if the connection is openvar nodeArray = anyNode; // returns an array of all peer connections // Firewalling connectionsvar protectedNode = P; // Send offerData with a connection requestanyNode; // Sending and receiving messageswebRtcNode; // send a message to a peer; can be json, string, or arraybufferwebRtcNode; // listens for messages from a peerwebRtcNode; // listens for array buffers from a peer // EventsanyNode; // emitted when a connection is made via this peeranyNode; // emitted when this connection is open and readyanyNode; // emitted when this connection is closedanyNode; // listens for errors for this connectionanyNode; // stops listening to an event
Documentation
Release Notes
- 0.3.1 - Added 'firewall' option to firewall RTC requests.
- 0.3 - Major refactor of internals and simplification of API, Firefox support, and respectable unit test coverage.
- 0.2 - Public release