0/24
24. Rooms

Lesson 24: Rooms

live.room() is the culmination of everything you've learned. It bundles a data stream and its actions into one cohesive unit:

export const whiteboard = live.room({
  topic: 'whiteboard',
  init: () => items,
  merge: 'crud',
  key: 'id',
  actions: {
    addItem: (ctx, text, x, y) => { ... },
    clearBoard: (ctx) => { ... }
  }
});

The actions are automatically registered as RPCs and can be imported directly in your component. The stream, merge strategy, and actions all live together.

Try it

Build a collaborative whiteboard room with:

  • addItem(ctx, text, x, y) - creates an item with id, text, x, y, and a random color. Publishes 'created'
  • clearBoard(ctx) - empties the items array and publishes 'set' with []

This is the final lesson - you now know every major feature of svelte-realtime.

WebSocket
0
No messages yet
User A
User B