Skip to Content
Channels

Channels

Mesh lets clients subscribe to Redis pub/sub channels over WebSocket. Useful for chat, notifications, dashboards, and more.

Server: expose channels

Allow clients to subscribe to specific channels or patterns:

.("notifications:global"); .(/^chat:.+$/); // restrict access per connection .(/^private:chat:.+$/, async (, ) => { const = await ..(); return ?.isPremium === true; });

Server: publish messages

Send messages to all subscribers. Optionally store recent history:

// publish with no history await .( "notifications:global", .({ : "Red alert!", }) ); // publish with history (keeps last 50) await .( "chat:room1", .({ : "user-message", : "1", : "Hi", }), 50 );

History is stored in Redis under "mesh:history:<channel>" and trimmed to the specified size.

Server: enable persistence

For long-term storage beyond Redis, enable persistence for specific channels:

// Enable persistence for all chat channels .(/^chat:.+$/); // With custom options .("notifications:global", { : 1000, });

Persistence stores messages in a durable backend (SQLite by default, with support for Postgres), surviving server restarts.

Client: subscribe

const { , } = await client.subscribeChannel( "chat:room1", () => { .("Live message:", ); }, { : 3 } ); .("History:", ); // ["msg3", "msg2", "msg1"]

Client: unsubscribe

await .("chat:room1");

Use cases

  • Chat systems
  • Notification feeds
  • Live dashboards
  • Cross-server pub/sub

See Server SDK → Channels and Client SDK → Channels for full API details.

Last updated on
© 2025