You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-21 04:02:35 +03:00
Actually allow MatrixClient to not have a store. Update jsdoc.
This commit is contained in:
@@ -4,6 +4,10 @@ Changes in 0.1.1
|
|||||||
Breaking changes:
|
Breaking changes:
|
||||||
* `Room.calculateRoomName` is now private. Use `Room.recalculate` instead, and
|
* `Room.calculateRoomName` is now private. Use `Room.recalculate` instead, and
|
||||||
access the calculated name via `Room.name`.
|
access the calculated name via `Room.name`.
|
||||||
|
* `new MatrixClient(...)` no longer creates a `MatrixInMemoryStore` if
|
||||||
|
`opts.store` is not specified. Instead, the `createClient` global function
|
||||||
|
creates it and passes it to the constructor. This change will not affect
|
||||||
|
users who have always used `createClient` to create a `MatrixClient`.
|
||||||
|
|
||||||
New properties:
|
New properties:
|
||||||
* `User.events`
|
* `User.events`
|
||||||
|
@@ -10,23 +10,30 @@ var MatrixEvent = require("./models/event").MatrixEvent;
|
|||||||
var EventStatus = require("./models/event").EventStatus;
|
var EventStatus = require("./models/event").EventStatus;
|
||||||
var Room = require("./models/room");
|
var Room = require("./models/room");
|
||||||
var User = require("./models/user");
|
var User = require("./models/user");
|
||||||
var MatrixInMemoryStore = require("./store/memory").MatrixInMemoryStore;
|
|
||||||
var utils = require("./utils");
|
var utils = require("./utils");
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// Internal: rate limiting
|
// Internal: rate limiting
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a Matrix Client.
|
* Construct a Matrix Client. Only directly construct this if you want to use
|
||||||
|
* custom modules. Normally, {@link createClient} should be used
|
||||||
|
* as it specifies 'sensible' defaults for these modules.
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {external:EventEmitter}
|
* @extends {external:EventEmitter}
|
||||||
* @param {Object} opts The configuration options for this client.
|
* @param {Object} opts The configuration options for this client.
|
||||||
* @param {string} opts.baseUrl Required. The base URL to the client-server HTTP API.
|
* @param {string} opts.baseUrl Required. The base URL to the client-server
|
||||||
* @param {Function} opts.request Required. The function to invoke for HTTP requests.
|
* HTTP API.
|
||||||
|
* @param {Function} opts.request Required. The function to invoke for HTTP
|
||||||
|
* requests. The value of this property is typically <code>require("request")
|
||||||
|
* </code> as it returns a function which meets the required interface. See
|
||||||
|
* {@link requestFunction} for more information.
|
||||||
* @param {string} opts.accessToken The access_token for this user.
|
* @param {string} opts.accessToken The access_token for this user.
|
||||||
* @param {string} opts.userId The user ID for this user.
|
* @param {string} opts.userId The user ID for this user.
|
||||||
* @param {Object} opts.store Optional. The data store to use. Defaults to
|
* @param {Object} opts.store Optional. The data store to use. If not specified,
|
||||||
* {@link module:store/memory.MatrixInMemoryStore}.
|
* this client will not store any HTTP responses.
|
||||||
|
* @param {Object} opts.scheduler Optional. The scheduler to use. If not
|
||||||
|
* specified, this client will not retry requests on failure.
|
||||||
*/
|
*/
|
||||||
function MatrixClient(opts) {
|
function MatrixClient(opts) {
|
||||||
utils.checkObjectHasKeys(opts, ["baseUrl", "request"]);
|
utils.checkObjectHasKeys(opts, ["baseUrl", "request"]);
|
||||||
@@ -34,7 +41,8 @@ function MatrixClient(opts) {
|
|||||||
["baseUrl", "request", "accessToken", "userId", "store"]
|
["baseUrl", "request", "accessToken", "userId", "store"]
|
||||||
);
|
);
|
||||||
|
|
||||||
this.store = opts.store || new MatrixInMemoryStore();
|
this.store = opts.store;
|
||||||
|
this.scheduler = opts.scheduler;
|
||||||
// track our position in the overall eventstream
|
// track our position in the overall eventstream
|
||||||
this.fromToken = undefined;
|
this.fromToken = undefined;
|
||||||
this.clientRunning = false;
|
this.clientRunning = false;
|
||||||
|
@@ -35,15 +35,18 @@ module.exports.request = function(r) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a Matrix Client. Identical to {@link module:client.MatrixClient}
|
* Construct a Matrix Client. Similar to {@link module:client~MatrixClient}
|
||||||
* except the 'request' option is already specified.
|
* except that the 'request', 'store' and 'scheduler' dependencies are satisfied.
|
||||||
* @param {(Object|string)} opts The configuration options for this client. If
|
* @param {(Object|string)} opts The configuration options for this client. If
|
||||||
* this is a string, it is assumed to be the base URL.
|
* this is a string, it is assumed to be the base URL. These configuration
|
||||||
|
* options will be passed directly to {@link module:client~MatrixClient}.
|
||||||
* @param {string} opts.baseUrl The base URL to the client-server HTTP API.
|
* @param {string} opts.baseUrl The base URL to the client-server HTTP API.
|
||||||
* @param {string} opts.accessToken Optional. The access_token for this user.
|
* @param {string} opts.accessToken Optional. The access_token for this user.
|
||||||
* @param {string} opts.userId Optional. The user ID for this user.
|
* @param {string} opts.userId Optional. The user ID for this user.
|
||||||
* @param {Object} opts.store Optional. The data store to use. Defaults to
|
* @param {Object} opts.store Optional. The data store to use. Defaults to
|
||||||
* {@link module:store/memory.MatrixInMemoryStore}.
|
* {@link module:store/memory.MatrixInMemoryStore}.
|
||||||
|
* @param {Object} opts.scheduler Optional. The scheduler to use. Defaults to
|
||||||
|
* {@link module:scheduler.BasicScheduler}.
|
||||||
* @return {MatrixClient} A new matrix client.
|
* @return {MatrixClient} A new matrix client.
|
||||||
*/
|
*/
|
||||||
module.exports.createClient = function(opts) {
|
module.exports.createClient = function(opts) {
|
||||||
@@ -53,6 +56,7 @@ module.exports.createClient = function(opts) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
opts.request = request;
|
opts.request = request;
|
||||||
|
opts.store = new module.exports.MatrixInMemoryStore();
|
||||||
return new module.exports.MatrixClient(opts);
|
return new module.exports.MatrixClient(opts);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user