Simple WebRTC Peer 2 Peer connections using WebTorrent trackers as the signalling server. Use WebTorrent trackers for any kind of WebRTC app ! 🔥 Make WebRTC apps fast & easy ! 🚀⭐
Simple library to establish P2P connections, communicate messages using WebTorrent Trackers (WebSocket) as the signalling server. Make any kind of WebRTC app using WebTorrent trackers as general-purpose WebRTC signalling servers.
Works in both browser & node environment.
The amazing WebTorrent library created a new kind of Torrent Trackers called "WebSocket Trackers" also known as "WebTorrent Trackers". Some torrent clients can use these new trackers to share files.
WebRTC is the method by which browsers can communicate to other browsers peer to peer (P2P). WebTorrent makes use of WebRTC for sharing Torrents on web.
But, to establish P2P connections, a signalling server is needed. Signalling servers can be made in any way. But, you'll have to host it yourself. In WebTorrent, it's the WebSocket trackers that are the signalling servers. What if we use those trackers to establish P2P connections for our apps ?! That is what P2PT does ! :)
How do we find peers for torrent to download ? We use a magnet link. That magnet link has a unique identifier for our torrent called the Info Hash. This ID will be unique for all torrents.
Similarly, to build our apps, we use a identifier. This identifier is converted to a valid Info Hash and sent to our WebTorrent trackers who will give us a list of web peers. These web peers would be the other users also using our app :
var p2pt = new P2PT(trackersAnnounceURLs, 'myApp')
And that is how P2PT works.
Add yours here ! Send a PR ! 🚀
Open this webpage in two separate browser windows. You'll see the messages. It's a codepen, you can fiddle with the code there.