In Matrix, everything happens inside a room. A room is a persistent, shared conversation space identified by aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/matrix-org/matrix-js-sdk/llms.txt
Use this file to discover all available pages before exploring further.
roomId. It holds a timeline of MatrixEvent objects — messages, state changes, reactions, and more. The matrix-js-sdk gives you high-level models for both.
The Room model
ARoom object represents everything the SDK knows about a single Matrix room: its timeline, current and historical state, members, name, receipts, threads, and notification counts.
Accessing rooms
After the client has synced at least once (SyncState.Prepared), rooms are available through the client:
Key room properties
Iterating the timeline
The timeline is an ordered array ofMatrixEvent objects. The following pattern from the README demonstrates printing messages from every room:
RoomEvent enum
Listen toRoom objects (or re-emitted via MatrixClient) for these events:
| Constant | Value | Fired when |
|---|---|---|
RoomEvent.Timeline | "Room.timeline" | A new event is added to (or removed from) the timeline |
RoomEvent.TimelineReset | "Room.timelineReset" | The live timeline was reset due to a limited sync |
RoomEvent.Name | "Room.name" | The room’s display name changed |
RoomEvent.MyMembership | "Room.myMembership" | The local user’s membership changed |
RoomEvent.Receipt | "Room.receipt" | A read receipt was received |
RoomEvent.Tags | "Room.tags" | Room tags were updated |
RoomEvent.AccountData | "Room.accountData" | Room-scoped account data changed |
RoomEvent.UnreadNotifications | "Room.UnreadNotifications" | Unread notification counts changed |
Automatic room joining on invite
The MatrixEvent model
Every item in a room timeline is aMatrixEvent. It wraps the raw event JSON from the server and exposes typed accessors.
The raw IEvent structure
Common MatrixEvent methods
Common event types
m.room.message
A user message. The
content.msgtype field distinguishes text (m.text), images (m.image), files (m.file), and more.m.room.member
Membership change for a user.
state_key is the affected user ID. content.membership is join, invite, leave, or ban.m.room.name
State event that sets the room’s display name.
content.name holds the value.m.room.topic
State event for the room topic.
content.topic holds the value.Sending events
Send a raw event
Convenience helpers
Threads
WhenthreadSupport: true is passed to startClient(), the SDK groups events that share a thread relation into Thread objects.
Room members
Member state is managed throughRoomState. You can access current members and listen for changes:
When
lazyLoadMembers: true is set in startClient(), member events are not fetched during initial sync. Call room.loadMembersIfNeeded() before accessing members to ensure they are populated.