DocumentationCore Protocol
@painda/chat
Full-featured room management and direct messaging built on the blazing fast Painda core.
Features
- RoomManager: Easily join, leave, and broadcast to specific rooms just like Socket.io.
- Direct Messaging: Send targeted whispers / private messages between specific client connection IDs.
- Decoupled: Use it alongside the Gaming or Video modules seamlessly.
Usage Example
import { PPServer } from "@painda/core";
import { RoomManager } from "@painda/chat";
const server = new PPServer({ port: 7001, registry });
const rooms = new RoomManager(server);
server.on("connection", (client) => {
// Join a room
rooms.join(client, "global-lobby");
// Broadcast to the room (excluding sender)
rooms.broadcastToRoom("global-lobby", {
type: "chat-message",
payload: "Hello world!"
}, client);
// Leave room
rooms.leave(client, "global-lobby");
});