0/12
1. Your First RPC

Lesson 1: Your First RPC

svelte-realtime lets you write server functions and call them from components.

On the right you see two files:

  • src/live/counter.ts - the server code
  • src/routes/+page.svelte - the component

live() wraps a function as an RPC endpoint. Clients call it over WebSocket like a normal async function.

live.stream() creates a reactive subscription. All connected clients receive updates when ctx.publish() is called.

Try it

Edit the server file to add a decrement function. It should decrease the count and publish the update. Then add a button for it in the component.

WebSocket
0
No messages yet
User A
User B