/* Copyright 2016 OpenMarket Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ import React from 'react' var linkable_clients = [ { name: "Riot", logo: "img/riot-48px.png", author: "Vector Creations", homepage: "https://riot.im", room_url(alias) { return "https://riot.im/app/#/room/" + alias }, room_id_url(id) { return "https://riot.im/app/#/room/" + id }, user_url(userId) { return "https://riot.im/app/#/user/" + userId }, msg_url(msg) { return "https://riot.im/app/#/room/" + msg }, maturity: "Stable", comments: "Fully-featured Matrix client for Web, iOS & Android", }, { name: "Matrix Console", logo: "img/console-48px.png", author: "Matrix.org", homepage: "https://matrix.org", room_url(alias) { return "https://matrix.org/beta/#/room/" + alias }, room_id_url(id) { return "https://matrix.org/beta/#/room/" + id }, maturity: "Deprecated", comments: "The original developer-focused client for Web, iOS & Android", }, ]; var unlinkable_clients = [ { name: "Weechat", logo: "img/weechat-48px.png", author: "Tor Hveem", homepage: "https://github.com/torhve/weechat-matrix-protocol-script", maturity: "Late beta", room_instructions(alias) { return Type /join { alias } }, user_instructions(userId) { return Type /invite { userId } }, comments: "Commandline Matrix interface using Weechat", }, { name: "Quaternion", logo: "img/quaternion-48px.png", author: "Felix Rohrbach", homepage: "https://github.com/Fxrh/Quaternion", maturity: "Late alpha", room_instructions(alias) { return Type /join { alias } }, user_instructions(userId) { return Type /invite { userId } }, comments: "Qt5 and C++ cross-platform desktop Matrix client", }, { name: "Tensor", logo: "img/tensor-48px.png", author: "David A Roberts", homepage: "https://github.com/davidar/tensor", maturity: "Late alpha", room_instructions(alias) { return Type /join { alias } }, user_instructions(userId) { return Type /invite { userId } }, comments: "QML and JS cross-platform desktop Matrix client", }, { name: "Tensor2", logo: "img/tensor-48px.png", author: "David A Roberts", homepage: "https://github.com/davidar/tensor2", maturity: "Alpha", room_instructions(alias) { return Type /join { alias } }, user_instructions(userId) { return Type /invite { userId } }, comments: "QML and C++ cross-platform desktop Matrix client", }, { name: "PTO (Perpetually Talking Online)", logo: "img/pto-48px.png", author: "Torrie Fischer", homepage: "https://pto.im", //room_url(alias) { return "irc://irc.matrix.org/" + alias }, room_instructions(alias) { return Type /join { alias } }, user_instructions(userId) { return Type /invite { userId } }, maturity: "Alpha", comments: "Access any room anywhere in Matrix via good old IRC!", }, { name: "Mclient.el", logo: "", author: "Ryan Rix", homepage: "http://fort.kickass.systems:10082/cgit/personal/rrix/pub/matrix.el.git/", maturity: "Alpha", comments: "Matrix client for Gnu Emacs", } ]; export default React.createClass({ getInitialState() { return { error: null, entity: null, showLink: false, } }, onHashChange() { var entity = unescape(window.location.hash.substr(2)); // strip off #/ prefix if (!entity) { this.setState({ entity: null, showLink: false, error: null, }); return; } if (!this.isAliasValid(entity) && !this.isUserIdValid(entity) && !this.isMsglinkValid(entity) && !this.isRoomIdValid(entity)) { this.setState({ entity: entity, error: "Invalid room alias, user ID or message permalink '" + entity + "'", }); return; } this.setState({ entity: entity, showLink: true, error: null, }); }, componentWillMount() { if (window.location.hash) { this.onHashChange(); } }, componentDidMount() { window.addEventListener("hashchange", this.onHashChange); }, componentWillUnmount() { window.removeEventListener("hashchange", this.onHashChange); }, onSubmit(ev) { ev.preventDefault(); var entity = this.refs.prompt.value.trim(); if (!this.isAliasValid(entity) && !this.isUserIdValid(entity)) { this.setState({ error: "Invalid room alias or user ID" }); return; } var loc = window.location; loc.hash = "#/" + entity; window.location.assign(loc.href); this.setState({ showLink: true, entity: entity, error: null, }); }, // XXX: cargo-culted from matrix-react-sdk isAliasValid(alias) { // XXX: FIXME SPEC-1 return (alias.match(/^#([^\/:]+?):(.+)$/) && encodeURI(alias) === alias); }, isRoomIdValid(id) { // XXX: FIXME SPEC-1 return (id.match(/^!([^\/:]+?):(.+)$/) && encodeURI(id) === id); }, isUserIdValid(userId) { // XXX: FIXME SPEC-1 return (userId.match(/^@([^\/:]+?):(.+)$/) && encodeURI(userId) === userId); }, isMsglinkValid(msglink) { // XXX: FIXME SPEC-1 console.log(msglink); console.log(encodeURI(msglink)); return (msglink.match(/^[\!#]([^\/:]+?):(.+?)\/\$([^\/:]+?):(.+?)$/) && encodeURI(msglink) === msglink); }, render() { var error; if (this.state.error) { error =
{ this.state.error }
} var prompt; if (this.state.showLink) { var link = "https://matrix.to/#/" + this.state.entity; var isRoom = this.isAliasValid(this.state.entity); var isRoomId = this.isRoomIdValid(this.state.entity); var isUser = this.isUserIdValid(this.state.entity); var isMsg = this.isMsglinkValid(this.state.entity); var links; // name: "Vector", // logo: "", // author: "Vector.im", // link: "https://vector.im", // room_url: "https://vector.im/beta/#/room/", // user_url: "https://vector.im/beta/#/user/", // maturity: "Late beta", // comments: "Fully-featured Matrix client for Web, iOS & Android", var description; if (isRoom) { description = the { this.state.entity } room; } else if (isUser) { description = the user { this.state.entity }; } else if (isMsg) { description = this message; } links = (

Matrix is an ecosystem for open and interoperable communication.

To connect to { description }, please select an app:

Name
Description
Author
Maturity
Access { isMsg ? "message" : { this.state.entity } }
{ linkable_clients.map((client) => { var link; if (isRoom && client.room_url) { link = client.room_url(this.state.entity); } else if (isRoomId && client.room_id_url) { link = client.room_id_url(this.state.entity); } else if (isUser && client.user_url) { link = client.user_url(this.state.entity); } else if (isMsg && client.msg_url) { link = client.msg_url(this.state.entity); } if (!link) return
; return (
{ client.name }
{ client.homepage }
{ client.comments }
{ client.author }
{ client.maturity }
{ link }
); })} { unlinkable_clients.map((client) => { var instructions; if (isRoom && client.room_instructions) { instructions = client.room_instructions(this.state.entity); } else if (isUser && client.user_instructions) { instructions = client.user_instructions(this.state.entity); } else if (isMsg && client.msg_instructions) { instructions = client.msg_instructions(this.state.entity); } if (!instructions) return
; return (
{ client.name }
{ client.comments }
{ client.author }
{ client.maturity }
{ instructions }
); })}

To add clients to this list, please contact us or simply send us a pull request on github!

); prompt = [
{ link } { error }
, links ]; } else { prompt = [
{ error }
,
Create shareable links to Matrix rooms, users or messages
without being tied to a specific app.
]; } return (
[matrix] { prompt }

About

Matrix.to is a simple stateless URL redirecting service which lets users share links to entities in the Matrix.org ecosystem without being tied to any specific app. This lets users choose their own favourite Matrix client to participate in conversations rather than being forced to use the same app as whoever sent the link.

The service preserves user privacy by not sharing any information about the links being followed with the Matrix.to server - the redirection is calculated entirely clientside using JavaScript.

Links are designed to be human-friendly, both for reading and constructing, and are essentially a compatibility step in the journey towards a ubiquitous mx:// URL scheme.

As with all of Matrix, Matrix.to is released as open source under the terms of the Apache License v2.0 - get the source from Github.

); } })