Examples menu

Chat Room multiplayer

Chat with other visitors in the Random room, or switch rooms in the list. Each room is a custom scope built with Scope::build(), and your username is a SESSION signal.

Custom scopes isolate each room. Messages in "lobby" never leak to "general": each room has its own broadcast channel built with Scope::build().
Session-scoped usernames persist across tabs. Your username is stored in SESSION scope, so switching rooms or opening a new tab keeps the same identity.
Presence + typing indicators update in real time. When a tab closes, the onCleanup hook removes its user from the room's list.
addScope() joins the room's scope, so the room's broadcasts re-render the page. The page itself stays in TAB scope, which keeps the message draft private.
SQLite persistence keeps message history across server restarts. Each room's messages are stored in chat.db, and the view loads the last 50 on every render.
Multi-room architecture: open two rooms side by side. Each room's scope is independent, so typing in Lobby has no effect on General.
One worker: this demo keeps who is in each room in PHP statics, which each worker holds on its own. See What stays per worker before you run it with withWorkerNum().
Random
UserC4B3 (you)
User6161 01:34:30
啊
KeenLynx 01:51:04
222
UserF7F1 17:37:39
kljhlhkj
UserF7F1 17:37:41
hkjlkjh
Unknown 17:37:45
hello?
Unknown 17:37:49
w
Unknown 17:37:54
why am i unknown suddenly?
Unknown 17:38:00
i am known now?
Unknown 17:38:01
now
UserF7F1 17:38:03
ee
UserF7F1 17:38:04
e
UserF7F1 17:38:05
e
UserF7F1 17:38:07
thats odd
Unknown 17:38:08
its all me
Unknown 17:38:12
hmm
Unknown 17:38:14
fuck
Unknown 17:38:15
kjshdfjkhasfkj
Unknown 17:38:24
<h1>foo</h1>

Signals

username string session scope

Persists across tabs. Same identity whether you switch rooms or open new tabs.

messageInput string tab scope initial: empty string

Current message draft. Private to this tab.

typingIndicator array custom scope

Custom room scope. Who is typing and when that expires. Shows "User is typing..." to everyone in the same room until the server clears it.

Actions

sendMessage

Appends message to the room, clears input, clears the sender's typing indicator, and broadcasts to room.

updateTyping

Sets the typing indicator with username and broadcasts to room. The server clears it 5 s after the last keystroke.

Views

chat_room.html.twig

Sidebar room list + chat panel with message list, user presence, and typing indicator. Uses onCleanup for cleanup.