7. Merge: Presence
Lesson 7: Merge: Presence
merge: 'presence' tracks a list of connected users. It handles two events:
'join'- adds a user to the list (deduplicated by key)'leave'- removes a user from the list by key
Unlike 'crud' which manages generic items, 'presence' is designed for tracking who's here right now.
Try it
The stream is set up with merge: 'presence'. Add two RPCs:
join(name)- creates a user object with akeyfield (use the name), adds it to the array if not already there, and publishes a'join'eventleave(name)- removes the user from the array and publishes a'leave'event with{ key: name }
Then update the component: add a name input with a Join button, a Leave button when joined, and a list of online users. Try joining as different names in User A and User B!
WebSocket
0
No messages yet