Events
Events enable real-time communication from actors to clients. While clients use actions to send data to actors, events allow actors to push updates to connected clients instantly.
Events work through persistent connections such as WebSocket or SSE.
Publishing Events from Actors
Broadcasting to All Clients
Use c.broadcast(eventName, data)
to send events to all connected clients:
Sending to Specific Connections
Send events to individual connections using conn.send(eventName, data)
:
Send events to all connections except the sender:
Subscribing to Events from Clients
Clients must establish a connection to receive events from actors. Use .connect()
to create a persistent connection, then listen for events.
Basic Event Subscription
Use connection.on(eventName, callback)
to listen for events:
One-time Event Listeners
Use connection.once(eventName, callback)
for events that should only trigger once:
Removing Event Listeners
Use the callback returned from .on()
to remove event listeners:
More About Connections
For more details on actor connections, including connection lifecycle, authentication, and advanced connection patterns, see the Connections documentation.