1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-05-27 22:01:05 +03:00
Kegan Dougal 9b4ba0afe8 Redo build process for browsers and node. Update examples.
We now rely on browserify for building browser-specific versions of the JS
SDK. This can be initiated by running 'npm run build-js'. Node versions are
unaffected.
2015-06-03 15:51:48 +01:00
2015-03-04 13:37:04 +00:00
2015-06-03 10:08:31 +01:00
2015-03-05 22:39:09 +00:00
2015-03-04 17:37:46 +00:00
2015-03-09 20:22:56 +00:00

Matrix Javascript SDK

This is the Matrix Client-Server v1 SDK for Javascript. This SDK can be run in a browser (using browserify or stand-alone with a suitable request.js) or in Node.js.

Quickstart

In a browser

Host examples/browser (e.g. using python -m SimpleHTTPServer) and check the console to see a working version.

In Node

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));
});

Run examples/node via node app.js to see a working version.

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 Pixar 228 MiB
Languages
TypeScript 99.3%
Python 0.5%
JavaScript 0.2%