1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-09 10:22:46 +03:00

Matrix Javascript SDK

image

This is the Matrix Client-Server v1 SDK for JavaScript. This SDK can be run in a browser or in Node.js.

Quickstart

In a browser

Copy dist/browser-matrix-$VERSION.js and add that as a <script> to your page. There will be a global variable matrixcs attached to window through which you can access the SDK.

Please check examples/browser for a working example.

In Node.js

npm install matrix-js-sdk

var sdk = require("matrix-js-sdk");
var client = sdk.createClient("https://matrix.org");
client.publicRooms(function(err, data) {
  console.log("Public Rooms: %s", JSON.stringify(data));
});

Please check examples/node to see a working version.

Contributing

This section is for people who want to modify the SDK. If you just want to use this SDK, skip this section.

First, you need to pull in the right build tools (we use browserify and watchify):

$ npm install

Building

To build a browser version from scratch when developing:

$ npm run build

To constantly do builds when files are modified (using watchify):

$ npm run watch

API

Please see the client server API for more information on the HTTP calls.

Matrix Client

MatrixClient is constructed via sdk.createClient(args) where args can be:

  • baseUrl (String) : The home server base URL to make requests to.
  • credentials (Object) : Consists of a baseUrl (String), a userId (String) and an accessToken (String).
  • credentials, config (Object, Object) : As before, but with a config which has the following options:
    • noUserAgent (Boolean: default false) : Set to true to stop setting a User-Agent on requests. This is typically done when using the SDK in a browser which logs errors when trying to clobber the User-Agent.

At any point these values can be modified by accessing matrixClient.credentials and matrixClient.config.

Promises

Promises are supported using Q, but are not enabled by default. To enable them, simply call sdk.usePromises() like so:

var sdk = require("matrix-js-sdk");
sdk.usePromises();
var client = sdk.createClient("https://matrix.org");
client.publicRooms().then(function(data) {
  console.log("Public Rooms: %s", JSON.stringify(data));
});

You will need to npm install q as it is not a hard dependency on this project.

Request

MatrixClient requires a request module in order to function. This is usually done for you when using npm. You can manually inject this by calling sdk.request(<request>). Wrappers around request allow you to easily support different HTTP libraries (such as AngularJS's $http).

Description
Клиент-серверный SDK Matrix для JavaScript
Readme 244 MiB
Languages
TypeScript 99.4%
Python 0.4%
JavaScript 0.2%