Skip to content

network

Networking primitives for JollyPixel's collaborative editors

💃 Getting Started ​

This package is available in the Node Package Repository and can be easily installed with npm or yarn.

bash
$ npm i @jolly-pixel/network

👀 Usage example ​

Vite server ​

ts
import * as network from "@jolly-pixel/network";
import {
  createWebSocketNetworkPlugin
} from "@jolly-pixel/network/plugins/vite.ts";

export default {
  plugins: [
    createWebSocketNetworkPlugin({
      extensions: [
        new network.PresenceOnlyExtension("echo", "echo", {
          broadcast: true
        })
      ]
    })
  ]
};

Browser client ​

ts
import * as network from "@jolly-pixel/network/client";

const client = new network.Client();
const room = client.room("echo");

room.on("message", (payload) => console.log(payload));
room.on("peer-joined", (event) => console.log(`${event.clientId} joined`));
room.on("peer-left", (event) => console.log(`${event.clientId} left`));
room.join();
room.send({ hello: "world" });

📚 API ​

  • Client: client connection and room handles
  • Server: room multiplexer
  • Extension: room-side base class, including worker-mode extensions
  • Rights: role-based access control
  • Transports: Vite plugin and websocket wiring
  • SyncAdapter: client-side sync sessions
  • Conflicts: server-side conflict resolution

ARCHITECTURE.md covers the wire format and connection lifecycle.

✨ Contributors guide ​

Read the contributing guide before submitting a change.

Once you have finished your development, check that the tests (and linter) are still good by running the following script:

bash
$ npm run test
$ npm run lint

CAUTION

In case you introduce a new feature or fix a bug, make sure to include tests for it as well.

📃 License ​

MIT