Framework for creating peer-to-peer browser networks
P is a small framework used to create browser-to-browser networks (as opposed to just a connection). With P, you can:
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.
// Initializing var rootNode = Pcreate; // create the root node // Connection management var webSocketNode = rootNodeconnectaddress; // connect to an onramp WebSocket server var webRtcNode = webSocketNodeconnectaddress; // connect to a peer using an onramp connection var webRtcNode = webRtcNodeconnectaddress; // connect to a peer using an existing peer connection anyNodeclose; // close the connection anyNodeisOpen; // return true if the connection is open var nodeArray = anyNodegetPeers; // returns an array of all peer connections // Firewalling connections var protectedNode = Pcreate // Only accept RTC connection offers which send 'secret' as the offer data // this firewall rule will apply to any child nodes as well return offerData === 'secret'; ; // Send offerData with a connection request anyNodeconnectaddress: address offerData: 'secret'; // Sending and receiving messages webRtcNodesendmessage; // send a message to a peer; can be json, string, or arraybuffer webRtcNodeon'message' {}; // listens for messages from a peer webRtcNodeon'array buffer' {}; // listens for array buffers from a peer // Events anyNodeon'connection' {}; // emitted when a connection is made via this peer anyNodeon'open' {}; // emitted when this connection is open and ready anyNodeon'close' {}; // emitted when this connection is closed anyNodeon'error' {}; // listens for errors for this connection anyNoderemoveListenereventName optionalCallback; // stops listening to an event