Examples menu

Chat Room multiplayer

Chat with other visitors in the General 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().
General
User6036 (you)
User6161 01:34:16
2233
KeenLynx 01:50:56
22
WilyLynx 21:21:51
sxdfjh
WilyLynx 21:21:52
fdsdaf
WilyLynx 21:21:52
kjs
WilyLynx 21:21:52
ksjdaf
WilyLynx 21:21:52
fk
WilyLynx 21:21:53
kasjdh
WilyLynx 21:21:53
jhsdf
WilyLynx 21:21:54
jhsdf
WilyLynx 21:21:57
kaljshfdklh
WilyLynx 21:21:58
kljhsadfkj
WilyLynx 21:22:03
fdsa
WilyLynx 21:22:04
sdafsadf
WilyLynx 21:22:07
asdf
CoolHare 16:21:04
sdfsdf
CoolHare 16:21:05
sdf
CoolHare 16:21:05
sdfsdf
CoolHare 16:21:05
df
CoolHare 16:21:06
sdf
CoolHare 16:21:06
sdf
CoolHare 16:21:07
sdf
CoolHare 16:21:07
sdf
CoolHare 16:21:08
asdf
CoolHare 16:21:10
asdf
CoolHare 16:21:11
asdf

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.