Examples menu

Chat Room multiplayer

Chat with other visitors in the Lobby 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().
Lobby
User2CF1 (you)
User19E9 16:58:38
dsadsa
UserC927 21:35:22
yello
Unknown 01:08:51
nice
User8AE6 03:25:56
whatadoo
User65CB 06:24:05
vcnc
User7C0E 11:09:56
oi
User6161 01:34:08
111
User6161 01:34:12
222
User4E1F 08:20:51
d
User4E1F 08:20:57
dddd
KeenLynx 01:50:44
fh
User85AE 08:49:22
的撒大苏打
User85AE 08:49:26
阿大撒哇哇哇哇
UserDDA7 21:06:29
hello
Unknown 21:07:09
is anyone available for chat
Unknown 21:07:17
hi
User6F61 09:05:49
What's cooking, good lookin'
User20F6 05:15:31
u8iy
User1A7C 08:13:12
11
UserD380 11:39:52
test mate
UserD380 11:40:05
o
UserD380 11:40:10
pp
UserD380 11:40:20
oo
UserADD2 15:50:16
Re
UserADD2 15:50:17
Ee
UserADD2 15:50:20
Dd
User264C 03:20:16
eee
Unknown 20:18:05
waasssuuuupp
User1857 22:48:36
来了来了
UserD776 01:38:00
1
User51D9 07:45:07
asdfasd
User51D9 07:45:09
asdfasdfasdfasdfasdf
User2CFB 11:49:00
' OR 1=1--
User859B 11:50:30
' OR 1=1-- STRIX-SQLI-CHECK
UserEE18 15:27:31
<img src=x onerror=alert(1)>
User6A20 19:10:01
asdfasdf
User6F81 12:30:13
ok
User531B 09:53:51
heya
CoolHare 16:20:44
sdf
CoolHare 16:20:44
sd
CoolHare 16:20:45
sdf
CoolHare 16:20:45
sdf
CoolHare 16:20:55
<h1>yo</h1>\n\n
User0356 00:42:37
1
UserE672 09:36:15
' OR 1=1-- STRIX-SQLI-CHECK
User64F4 15:10:44
Hello
User64F4 15:10:51
Wow
User64F4 15:11:01
Heh
User7C5E 14:40:29
woooohoooo
User6078 14:09:27
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.