View on GitHub

WebPEER

P2P Network Inside Browser

WebPEER

WebPEER is a Decentralized P2P Network in the Browser. It allows developers to build peer-to-peer webapps without relying on centralized servers or specialized browsers. Aims to return internet control back to users.

>DEMO<

WebPEER

Spirit

In the early days of the World Wide Web, the internet was more open and more like a peer-to-peer network, where every user had equal standing on the network. This project aims to restore that early spirit through web standards, so that no single entity controls the network. However, the reality that standard web browsers have many limitations makes this dream a significant challenge. WebPEER seeks to address these challenges to see what is possible on today’s web by reusing already invented components.

Implementation

The JavaScript implementation of WebPEER Network designed as a minimal, essential API. It uses IPFS and the libp2p modular stack for the specific purpose of propagating messages over the network via direct WebRTC connections between browsers. The consequence is that these messages can arrive asynchronously depending on how many iterations they have gone through.

Bootstrapping

When a new peer is created, it doesn’t know the addresses of existing peers on the network. While manually entering peer addresses is possible, it’s impractical. Another strategy is to use federated media, leveraging public protocols like Torrent to facilitate address exchange. Once the peer addresses are obtained, the peer can establish a direct browser-to-browser connection to the WebPEER Network.

Security

WebPEER Network run over libp2p gossipsub protocol to enables secure communication between peers.

By default, the gossipsub implementation will sign all messages with the author’s private key, and require a valid signature before accepting or propagating a message further. This prevents messages from being altered in flight, and allows recipients to authenticate the sender.

However, as a cooperative protocol, it may be possible for peers to interfere with the message routing algorithm in a way that disrupts the flow of messages through the network.

Benefit

Ideas

Try it out!

Browser Support

Chrome Firefox Opera Edge Brave Safari

Quickstart

NPM:

npm install webpeerjs

CDN :

<script type="importmap">
{
	"imports": {
		"webpeerjs" : "https://esm.sh/webpeerjs"
	}
}
</script>

Usage

import { createWebPEER } from 'webpeerjs'

const config = {
	appName : 'myAppHelloWorld'
}

const peer = await createWebPEER();

console.log(`My peer id : ${peer.id}`)

const room = peer.joinRoom('lobbyroom')

room.onMessage((message,id) => {
	console.log(`Message from ${id} : ${message}`)
})

room.onMembers((data) => {
	console.log(`Members : ${data}`)
	room.sendMessage('hello')
})
	

API

peer = await createWebPEER(config)

Create a new peer.

config - Configuration object contains:

peer.id

Get the unique ID of this peer.

peer.status

Get the peer status, returns connecting or connected.

room = peer.joinRoom(namespace)

Join to a room, returns an object.

See Also

License

MIT (c) 2024 Nuzulul Zulkarnain