0/24
22. Channels

Lesson 22: Channels

Streams have an init function that returns historical data. But sometimes you just want fire-and-forget events with no history.

live.channel() creates a lightweight pub/sub subscription:

export const alerts = live.channel('alerts', { merge: 'crud', key: 'id' });

No init function, no stored data. Subscribers only see events that happen after they connect. Perfect for notifications, typing indicators, or ephemeral signals.

By default channels use merge: 'set' (single latest value, like a status indicator). For an accumulating list of notifications, pass { merge: 'crud', key: 'id' } so each published item is appended.

Try it

  1. Create a notifications channel on the 'alerts' topic with merge: 'crud' and key: 'id'
  2. Create a notify(text) RPC that publishes a notification object to 'alerts' with event 'created'
  3. Each notification needs an id, text, and timestamp
WebSocket
0
No messages yet
User A
User B