libfabric

Scalable multiplayer for the web

About

libfabric is a JavaScript library for peer-to-peer browser game networking. It's free, easy to use, and ridiculously scalable. It was developed with the goal of leveling the playing field for indie developers and small game studios who are limited in labour and money. Click here to learn more about the technical details.

Installation

If you're using a bundler like webpack or Browserify,

npm install yousefamar/p2p-peer
otherwise you can simply include the library through a CDN
<script src="https://cdn.jsdelivr.net/gh/yousefamar/p2p-peer/pkg/dist-web/index.min.js"></script>

Usage

Warning: libfabric is still in beta, and full documentation of methods and events is coming soon!

There are two layers of abstraction with which you can use libfabric. The first is to basically treat it as a server with "rooms" as namespaces through which you can broadcast events with arbitrary names and arbitrary objects that can be serialized into JSON.

import PeerNetwork from 'libfabric';

(async () => {
	const peerNet = new PeerNetwork();
	await peerNet.connect('https://libfabric.io'); // or https://sig.amar.io

	peerNet.on('connection', peer => {
		console.log('Peer', peer.uid, 'connected');

		peer.on('greeting', msg => console.log('Peer', peer.uid + ':', msg));

		peer.on('disconnect', () => console.log('Peer', peer.uid, 'disconnected'));
	});

	peerNet.on('uid', uid => {
		console.log(uid);

		let room = peerNet.join('test');
		room.eventEmitter.on('.', console.log);
	});

})();

The second is using room.syncedData which is an object that will automatically propagate and sync across the network. Newer updates always take priority over older updates.

Since 80% of traffic for the majority of games is position updates, each of peerNet.peers[].pos can be used to set/get peer virtual positions. These coordinates are special as they affect the way topologies are computed, and have configurable, game-specific optimisations (such as prediction/interpolation) applied to them.

Pricing

libfabric is absolutely free if you host your own signalling server. If you don't, it's still completely free if you're an indie developer or small game studio, if your game does not make any money, or if your game is open source. Otherwise, we divide usage into three plans:


Cotton

  • Unlimited use
  • No API key needed
  • Completely connected topologies
  • Superpeer topologies
  • Best for < 10 players per room

Linen

  • Unlimited use
  • All cotton topologies
  • AOI topologies
  • Proprietary topologies
  • Up to 50 players per room

Silk

  • Unlimited use
  • All cotton and linen topologies
  • ∞ players per room
  • Dedicated signalling server
  • 24 / 7 support