Skip to main content
In Matrix, everything happens inside a room. A room is a persistent, shared conversation space identified by a 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

A Room 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 of MatrixEvent objects. The following pattern from the README demonstrates printing messages from every room:
You can also iterate the stored timeline directly:

RoomEvent enum

Listen to Room objects (or re-emitted via MatrixClient) for these events:

Automatic room joining on invite

The MatrixEvent model

Every item in a room timeline is a MatrixEvent. 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

The SDK queues outbound events locally and applies “local echo” — the sent event appears in the timeline immediately with an EventStatus of sending. If the request fails, the status transitions to not_sent. Always supply a MatrixScheduler if you want automatic retry on network errors.

Threads

When threadSupport: true is passed to startClient(), the SDK groups events that share a thread relation into Thread objects.
The RoomEvent.Timeline event fires for both the main timeline and thread timelines. Check event.threadRootId or the toStartOfTimeline parameter to distinguish them.

Room members

Member state is managed through RoomState. 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.