View on GitHub

WebPEER

P2P Network Inside Browser

WebPEER

WebPEER is a P2P Network that Runs in a Standard Browser.

>DEMO<

WebPEER

Security

WebPEER Network run over libp2p gossipsub protocol to enables 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.

Features

Ideas

Try it out!

Browser Support

Chrome Firefox Opera Edge Brave Safari

Quickstart

NPM install:

npm install webpeerjs

CDN :

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

Example

import { createWebPEER } from 'webpeerjs'

const config = {
	networkName : 'myNetwork'
}

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.onMembersChange((data) => {
	console.log(`Members : ${data}`)
	room.sendMessage('hello')
})
	

API

peer = await createWebPEER(config)

Create a new peer node.

config - Configuration object contains:

peer.id

Get the unique ID of the peer node.

peer.status

Get the peer node status, returns connected or disconnected.

room = peer.joinRoom(namespace)

Join to a room, returns an object.

See Also

License

MIT (c) 2024 Nuzulul Zulkarnain