npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

rollback-netcode

v0.0.6

Published

P2P rollback netcode library for browser-based multiplayer games

Readme

Rollback Netcode

npm version license

Note: This library is under active development. APIs may change.

A TypeScript library for P2P rollback netcode in browser-based multiplayer games. Supports 4+ players with WebRTC—no dedicated server required.

Live Demo | API Reference | FAQ

Features

  • Rollback netcode - Simulate optimistically, rollback and resimulate on misprediction
  • N-player support - 4+ players, not limited to 2
  • P2P networking - WebRTC DataChannels, works in any modern browser
  • Dynamic join/leave - Players can join or leave during gameplay
  • Desync detection - Periodic state hashing with automatic recovery
  • Transport-agnostic - WebRTC included, or bring your own

Installation

npm install rollback-netcode

Quick Start

1. Implement the Game Interface

Your game must implement four methods:

import type { Game, PlayerId } from 'rollback-netcode';

class MyGame implements Game {
  private state = { x: 100, y: 100 };

  serialize(): Uint8Array {
    const buffer = new ArrayBuffer(8);
    const view = new DataView(buffer);
    view.setFloat32(0, this.state.x);
    view.setFloat32(4, this.state.y);
    return new Uint8Array(buffer);
  }

  deserialize(data: Uint8Array): void {
    const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
    this.state.x = view.getFloat32(0);
    this.state.y = view.getFloat32(4);
  }

  step(inputs: Map<PlayerId, Uint8Array>): void {
    for (const [, input] of inputs) {
      if (input[0] & 0x01) this.state.x -= 5;  // left
      if (input[0] & 0x02) this.state.x += 5;  // right
      if (input[0] & 0x04) this.state.y -= 5;  // up
      if (input[0] & 0x08) this.state.y += 5;  // down
    }
  }

  hash(): number {
    return Math.floor(this.state.x * 1000 + this.state.y);
  }
}

2. Create a Session

import { createSession, WebRTCTransport } from 'rollback-netcode';

const transport = new WebRTCTransport('my-player-id');

transport.setSignalingCallbacks({
  onSignal: (peerId, signal) => {
    // Send signal to peer via your signaling server
    signalingServer.send(peerId, signal);
  }
});

// Handle incoming signals from your signaling server
signalingServer.onSignal((fromPeerId, signal) => {
  if (signal.type === 'description') {
    transport.handleRemoteDescription(fromPeerId, signal.description);
  } else {
    transport.handleRemoteCandidate(fromPeerId, signal.candidate);
  }
});

const session = createSession({ game: new MyGame(), transport });

session.on('playerJoined', (player) => console.log(`${player.id} joined`));
session.on('desync', () => console.log('Desync detected, recovering...'));

3. Host or Join

// Host creates a room
const roomId = await session.createRoom();

// Others join
await session.joinRoom(roomId, hostPeerId);

4. Game Loop

session.start();  // Host only

function gameLoop() {
  const input = new Uint8Array([
    (keys.left  ? 0x01 : 0) |
    (keys.right ? 0x02 : 0) |
    (keys.up    ? 0x04 : 0) |
    (keys.down  ? 0x08 : 0)
  ]);

  session.tick(input);
  render(game);
  requestAnimationFrame(gameLoop);
}

Examples

See the examples/ directory:

  • local-transport - Browser demo using simulated network (no server needed)
  • webrtc - Real WebRTC connections with a minimal signaling server

Documentation

Requirements

  • Node.js >= 22.0.0 (development)
  • Modern browser with WebRTC (Chrome 56+, Firefox 44+, Safari 11+, Edge 79+)

License

MIT