PubSub

Note: Currently PubSub's are supported for Node.js only.

You may want to run a single room across multiple servers to horizontally scale your API. For that a PubSub will be necessary to share the events, and Persistance will be necessary for syncing storage state across servers.

Usage Example

Let's step through how we'd setup a pubsub to our pluv.io API.

Installation

Install your PubSub and Persistance of your choosing:

1# For the server
2npm install @pluv/pubsub-redis @pluv/persistance-redis
3# Peer-dependencies
4npm install ioredis yjs

Setup your PubSub and Persistance

Create your pluv.io instance with your selected PubSub and Persistance:

1// server/io.ts
2
3import { yjs } from "@pluv/crdt-yjs";
4import { createIO } from "@pluv/io";
5import { platformNode } from "@pluv/platform-node";
6import { PubSubRedis } from "@pluv/pubsub-redis";
7import { PersistanceRedis } from "@pluv/persistance-redis";
8import { Redis } from "ioredis";
9
10// Setup redis. You can also use a Redis Cluster
11const redis = new Redis({
12 /* redis config here */
13});
14
15export const io = createIO({
16 crdt: yjs,
17 platform: platformNode({
18 persistance: new PersistanceRedis({ client: redis }),
19 pubSub: new PubSubRedis({
20 publisher: redis,
21 subscriber: redis,
22 }),
23 }),
24});

Available Libraries

Below are the available pubsubs and libraries written for pluv.io. Check the roadmap to see what other providers are to be supported in the future.

PubSubs

Persistances