1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-08-16 18:21:59 +03:00

Make the client object be an event emitter rather than a matrixclient to avoid us being tempted to gut wrench stuff directly into the Matrix Client.

This commit is contained in:
David Baker
2016-03-15 11:05:05 +00:00
parent 5833654aa6
commit 85f2754300

View File

@@ -45,7 +45,7 @@ module.exports.PREFIX_IDENTITY_V1 = "/_matrix/identity/api/v1";
/** /**
* Construct a MatrixHttpApi. * Construct a MatrixHttpApi.
* @constructor * @constructor
* @param {MatrixClient} client The matrix client instance to use. * @param {EventEmitter} event_emitter The event emitter to use for emitting events
* @param {Object} opts The options to use for this HTTP API. * @param {Object} opts The options to use for this HTTP API.
* @param {string} opts.baseUrl Required. The base client-server URL e.g. * @param {string} opts.baseUrl Required. The base client-server URL e.g.
* 'http://localhost:8008'. * 'http://localhost:8008'.
@@ -61,10 +61,10 @@ module.exports.PREFIX_IDENTITY_V1 = "/_matrix/identity/api/v1";
* @param {Object} opts.extraParams Optional. Extra query parameters to send on * @param {Object} opts.extraParams Optional. Extra query parameters to send on
* requests. * requests.
*/ */
module.exports.MatrixHttpApi = function MatrixHttpApi(client, opts) { module.exports.MatrixHttpApi = function MatrixHttpApi(event_emitter, opts) {
utils.checkObjectHasKeys(opts, ["baseUrl", "request", "prefix"]); utils.checkObjectHasKeys(opts, ["baseUrl", "request", "prefix"]);
opts.onlyData = opts.onlyData || false; opts.onlyData = opts.onlyData || false;
this.client = client; this.event_emitter = event_emitter;
this.opts = opts; this.opts = opts;
this.uploads = []; this.uploads = [];
}; };
@@ -275,7 +275,7 @@ module.exports.MatrixHttpApi.prototype = {
callback, method, path, queryParams, data, localTimeoutMs callback, method, path, queryParams, data, localTimeoutMs
).catch(function(err) { ).catch(function(err) {
if (err.errcode == 'M_UNKNOWN_TOKEN') { if (err.errcode == 'M_UNKNOWN_TOKEN') {
self.client.emit("Session.logged_out"); self.event_emitter.emit("Session.logged_out");
} }
throw err; throw err;
}); });