WARNING: This document has not yet been accepted for consideration or approved in any official manner by the XMPP Standards Foundation, and this document is not yet an XMPP Extension Protocol (XEP). If this document is accepted as a XEP by the XMPP Council, it will be published at <http://xmpp.org/extensions/> and announced on the <[email protected]> mailing list.

A common complaint about the Matrix protocol is its use of HTTP as its
baseline transport. As everyone knows, HTTP is a terrible protocol to use as
a transport for real-time communications. To remedy this, this specification
defines a transport for the Matrix Client-Server API using a proven real-time
communications protocol, namely XMPP.

The Matrix specification is large; it is said to include a kitchen sink,
and no doubt includes other fixtures as well, given its ability to create
plumbed rooms. Further complications in writing a full specification arise
from the fact that, unfortunately, no one can be told what the Matrix is; you
have to see it for yourself. Thus rather than attempting to present a
complete API, this specification presents a general way to transform an
HTTP-based API call as specified in Matrix Client-Server API [1] to an XMPP-based API call.

Since Matrix user IDs (MXIDs) are in a different form from JIDs, they
must be mapped to a valid JID that can be used where the XMPP stream
expects a valid JID. This can be done simply by mapping the MXID
@localpart:domain to the JID
[email protected]_matrix.domain, where precislocalpart is
localpart prepared according to the UsernameCaseMapped profile
defined in RFC 7613 [2] § 3.2. In most cases, this identity map will leave
the localpart unchanged. The _matrix subdomain is prepended to
the domain in order to avoid collisions in the case where a domain serves
both Matrix and XMPP users.

To begin the session, the Matrix client opens an XML stream with the
Matrix server. The XML stream follows the normal lifecycle of an XMPP
stream as specified in XMPP Core [3]. The authentication step is used in
place of the /login Matrix HTTP endpoint.

The server MUST treat the closing of the stream as if the
/logout Matrix HTTP endpoint was called.

Once an XML stream is established and ready for exchanging XML stanzas,
the client can begin sending requests to the server.

An HTTP Matrix request can easily be transformed to an XMPP request
using HTTP Over XMPP Transport (XEP-0332) [4]. Since the request is intended to be processed directly by
the server, the "to" attribute is omitted in the
<iq> request stanza. In order to distinguish the request
from a normal XEP-0332 request, the Host header is set to the
special value "[matrix]", which will never occur in a real HTTP
Host header. Since the XML stream is authenticated, there is no
need to send the access token in the request as is required in the
HTTP-based API.

Unexpected changes in Matrix can result in stanzas being re-sent. When
clients detect such instances of déjà vu, they should find an exit and
disconnect gracefully as soon as possible in order to avoid unexpected
termination.

Appendix B: Author Information

Hubert Chathi

Appendix C: Legal Notices

Copyright

Permissions

Permission is hereby granted, free of charge, to any person obtaining a copy of this specification (the "Specification"), to make use of the Specification without restriction, including without limitation the rights to implement the Specification in a software program, deploy the Specification in a network service, and copy, modify, merge, publish, translate, distribute, sublicense, or sell copies of the Specification, and to permit persons to whom the Specification is furnished to do so, subject to the condition that the foregoing copyright notice and this permission notice shall be included in all copies or substantial portions of the Specification. Unless separate permission is granted, modified works that are redistributed shall not contain misleading information regarding the authors, title, number, or publisher of the Specification, and shall not claim endorsement of the modified works by the authors, any organization or project to which the authors belong, or the XMPP Standards Foundation.

Disclaimer of Warranty

## NOTE WELL: This Specification is provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. ##

Limitation of Liability

In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall the XMPP Standards Foundation or any author of this Specification be liable for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising from, out of, or in connection with the Specification or the implementation, deployment, or other use of the Specification (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if the XMPP Standards Foundation or such author has been advised of the possibility of such damages.

IPR Conformance

This XMPP Extension Protocol has been contributed in full conformance with the XSF's Intellectual Property Rights Policy (a copy of which can be found at <https://xmpp.org/about/xsf/ipr-policy> or obtained by writing to XMPP Standards Foundation, P.O. Box 787, Parker, CO 80134 USA).

Appendix D: Relation to XMPP

The Extensible Messaging and Presence Protocol (XMPP) is defined in the XMPP Core (RFC 6120) and XMPP IM (RFC 6121) specifications contributed by the XMPP Standards Foundation to the Internet Standards Process, which is managed by the Internet Engineering Task Force in accordance with RFC 2026. Any protocol defined in this document has been developed outside the Internet Standards Process and is to be understood as an extension to XMPP rather than as an evolution, development, or modification of XMPP itself.

Appendix E: Discussion Venue

The primary venue for discussion of XMPP Extension Protocols is the <[email protected]> discussion list.

Appendix F: Requirements Conformance

The following requirements keywords as used in this document are to be interpreted as described in RFC 2119: "MUST", "SHALL", "REQUIRED"; "MUST NOT", "SHALL NOT"; "SHOULD", "RECOMMENDED"; "SHOULD NOT", "NOT RECOMMENDED"; "MAY", "OPTIONAL".

Appendix H: Revision History

Version 0.0.2 (2017-04-01)

The first version was designed to be a perfect spec. Where none
suffered, where everyone would be happy. It was a disaster. No client
would accept the spec. Some believed we lacked the programming language to
describe the perfect spec.