Event Listeners
Subscribe to real-time events from the server.
Event Listeners
Use these methods to react to real-time updates. Each returns an unsubscribe function.
Message Events
onMessage(listener: (message: Message) => void)onMessageEdited(listener: (data: { messageId: string; roomId: string; content: string; editedAt: Date; editedBy: string }) => void)onMessageDeleted(listener: (data: { messageId: string; roomId: string; deletedBy: string }) => void)onReaction(listener: (data: { messageId: string; roomId: string; userId: string; username: string; emoji: string; reactedAt: Date }) => void)onReadReceipt(listener: (data: { messageId: string; roomId: string; readBy: string; readAt: Date }) => void)
Typing Events
onTypingStart(listener: (data: { userId: string; username: string; roomId: string }) => void)onTypingStop(listener: (data: { userId: string; username: string; roomId: string }) => void)
Presence Events
onUserOnline(listener: (data: Pick<User, 'id' | 'username'>) => void)onUserOffline(listener: (data: Pick<User, 'id' | 'username'> & { lastSeen: Date }) => void)onUserStatus(listener: (data: Pick<User, 'id' | 'username' | 'status'> & { lastSeen: Date }) => void)
Room Events
onRoomUserJoined(listener: (data: { roomId: string; user: Pick<User, 'id' | 'username' | 'displayName'> }) => void)onRoomUserLeft(listener: (data: { roomId: string; user: Pick<User, 'id' | 'username'> }) => void)onRoomDeleted(listener: (data: { roomId: string }) => void)onKickedFromRoom(listener: (data: { roomId: string; reason: string }) => void)
Error Events
onError(listener: (data: { code: string; message: string }) => void)
Note: All onXxx methods return an unsubscribe function. The server uses structured error codes (see ErrorCodes in @ravex/types or server source).
Usage Example
const unsubscribe = client.onMessage((msg) => {
console.log(msg);
});
// later
unsubscribe();You can also use the lower-level client.on(), client.off(), and client.once() for advanced use cases.