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 can be sent to clients connected using .connect(). They have no effect on low-level WebSocket connections.
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.
API Reference
RivetEvent- Base event interfaceRivetMessageEvent- Message event typeRivetCloseEvent- Close event typeUniversalEvent- Universal event typeUniversalMessageEvent- Universal message eventUniversalErrorEvent- Universal error eventEventUnsubscribe- Unsubscribe function type