Subtitle:
The fundamental data units exchanged in Matrix communication
Core Idea:
In Matrix, all data is exchanged as JSON events with specific types and metadata, providing a flexible yet structured approach to representing messages, state changes, and all other communication within the system.
Key Principles:
- Typed Structure:
- Each event has a type that defines its purpose and expected structure.
- Namespaced Types:
- Event types are namespaced (e.g.,
m.room.messagefor core Matrix events, custom namespaces for extensions).
- Event types are namespaced (e.g.,
- Metadata and Content Separation:
- Events separate metadata (sender, room, timestamps) from content payload.
Why It Matters:
- Extensibility:
- New event types can be created for custom applications without modifying the core protocol.
- Semantic Understanding:
- Clients can interpret and render different events appropriately based on their types.
- History Preservation:
- Events form an immutable record of all actions and messages within a room.
How to Implement:
- Event Creation:
- Structure JSON objects with required fields and appropriate type.
- Message Events:
- Use for transient communication (e.g., chat messages, calls).
- State Events:
- Use for persistent room state (e.g., name, topic, membership).
Example:
- Scenario:
- A user sends a text message in a Matrix room.
- Application:
- Client creates an
m.room.messageevent with content includingmsgtype: "m.text"and the message body.
- Client creates an
- Result:
- The event is added to the room's event graph and propagated to all members' homeservers.
Connections:
- Related Concepts:
- Event Graphs in Matrix: How events are stored and ordered
- Room Structure in Matrix: The container for events
- Broader Concepts:
- Matrix Protocol: The communication protocol using JSON events
- Event-Driven Architecture: Design pattern used in distributed systems
References:
- Primary Source:
- Matrix Specification: Events section
- Additional Resources:
- Matrix Event format documentation
- Matrix Room Event schemas
- Matrix State Event documentation
Tags:
#matrix #events #json #messaging #eventdriven #datastructure
Connections:
Sources:
- From: Matrix Specification