is in preview! Please wait for a v1.0.0 stable release before using this in production.

Creating Rooms

Rooms are the channels that WebSockets can enter and leave (i.e. connect and disconnect). Events emitted by sockets in a room will be broadcasted only to other sockets within the same room.

Creating a PluvRoom

To create a PluvRoom, you must first have a PluvClient defined. Refer to the create client documentation to do so.

// frontend/room.ts

import { yjs } from "@pluv/crdt-yjs";
import { z } from "zod";
import { client } from "./io";

const ROOM_NAME = "my-test-room";

export const room = client.createRoom(ROOM_NAME, {
    // Define your presence schema
    presence: z.object({
        selectionId: z.nullable(z.string()),
    // Define the user's initial presence value
    initialPresence: {
        selectionId: null,
    // Define the initial storage for the room
    initialStorage: yjs.doc(() => ({
        messages: yjs.array(["hello world!"]),

Connect to your PluvRoom

import { client } from "./io";

// connect by room name
await client.enter(ROOM_NAME);

// or connect by room instance
await client.enter(room);

Leave your PluvRoom

import { client } from "./io";

// leave by room name

// or leave by room instance