Compare commits

...

17 Commits

Author SHA1 Message Date
Kegan Dougal f665748fe5 Add 0.2.1 browser-dist. 2015-09-11 10:59:44 +01:00
Kegan Dougal 92e3a28315 Add gendoc script 2015-09-11 10:24:38 +01:00
Kegan Dougal 4e26790418 Merge branch 'develop' 2015-09-11 10:17:20 +01:00
Kegan Dougal f1793ff96d Merge branch 'release-v0.2.1' into develop 2015-09-11 10:17:09 +01:00
Kegan Dougal 22a9db6c29 Add CHANGELOG and bump to 0.2.1 2015-09-11 10:12:54 +01:00
Kegsay 7a4a3a1239 Merge pull request #19 from matrix-org/matthew/http_exceptions
#19 - Gracefully fail when synchronous errors occur when calling the request function
2015-09-02 09:57:29 +01:00
Kegan Dougal 3c01e2db43 Style checks 2015-09-02 09:50:43 +01:00
Matthew Hodgson 3b9f1728c7 turn HTTP exceptions into errbacks or rejected deferreds rather than bubbling them up and expecting the app to have try blocks eeeeeeeeeverywhere 2015-08-31 18:26:27 +01:00
Kegan Dougal 6d6868df73 Mention the user_id of the inviter for invited room names 2015-08-14 17:09:21 +01:00
Kegan Dougal c1c2731f2e Set the Content-Type on uploads
Most browsers seem to set this if you forget, but some don't.
2015-08-14 15:09:31 +01:00
David Baker e859119bde Support allowDefault flag on room avatars too 2015-08-13 17:12:09 +01:00
David Baker 9fab329a70 Add option to prevent the SDK from returning default avatar URLs. 2015-08-13 17:07:34 +01:00
Kegan Dougal deaaee4986 Add 'opts' to joinRoom function.
Add 'syncRoom' option to allow developers to join rooms without doing a
room initial sync. This is a breaking change.
2015-08-04 12:57:30 +01:00
Kegan Dougal 54a5c38b66 Do not retry requests which 40[0/1/3]. Set 'errcode' on MatrixErrors 2015-07-29 10:30:07 +01:00
Kegan Dougal 7f9c88e53f Add create/getAlias and sendNotice/sendHtmlNotice methods. 2015-07-28 14:51:26 +01:00
Kegan Dougal 3864472057 Fix test race condition.
It was possible for the test to end (via done()) before the final /events req
was flushed, resulting in a fail as there were requests outstanding. We now wait
until the final flush is done before done()ing.
2015-07-28 13:40:02 +01:00
Kegan Dougal 759dece725 Minor JSDoc fix. 2015-07-28 13:27:57 +01:00
11 changed files with 10213 additions and 26 deletions
+1
View File
@@ -1,3 +1,4 @@
.jsdoc
node_modules
.lock-wscript
build/Release
+35
View File
@@ -1,3 +1,38 @@
Changes in 0.2.1
================
Bug fixes:
* The `Content-Type` of file uploads is now explicitly set, without relying
on the browser to do it for us.
Improvements:
* The `MatrixScheduler.RETRY_BACKOFF_RATELIMIT` function will not retry when
the response is a 400,401,403.
* The text returned from a room invite now includes who the invite was from.
* There is now a try/catch block around the `request` function which will
reject/errback appropriately if an exception is thrown synchronously in it.
Breaking changes:
* `MatrixClient.joinRoom` has changed from `(roomIdOrAlias, callback)` to
`(roomIdOrAlias, opts, callback)`.
New methods:
* `MatrixClient.createAlias(alias, roomId)`
* `MatrixClient.getRoomIdForAlias(alias)`
* `MatrixClient.sendNotice(roomId, body, txnId, callback)`
* `MatrixClient.sendHtmlNotice(roomId, body, htmlBody, callback)`
Modified methods:
* `MatrixClient.joinRoom(roomIdOrAlias, opts)` where `opts` can include a
`syncRoom: true|false` flag to control whether a room initial sync is
performed after joining the room.
* `MatrixClient.getAvatarUrlForMember` has a new last arg `allowDefault` which
returns the default identicon URL if `true`.
* `MatrixClient.getAvatarUrlForRoom` has a new last arg `allowDefault` which
is passed through to the default identicon generation for
`getAvatarUrlForMember`.
Changes in 0.2.0
================
+1 -1
View File
@@ -216,7 +216,7 @@ API Reference
=============
A hosted reference can be found at
http://matrix-org.github.io/matrix-js-sdk/global.html
http://matrix-org.github.io/matrix-js-sdk/index.html
This SDK uses JSDoc3 style comments. You can manually build and
host the API reference from the source files like this:
+10023
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
+100 -7
View File
@@ -502,11 +502,22 @@ MatrixClient.prototype.createRoom = function(options, callback) {
/**
* Join a room. If you have already joined the room, this will no-op.
* @param {string} roomIdOrAlias The room ID or room alias to join.
* @param {Object} opts Options when joining the room.
* @param {boolean} opts.syncRoom True to do a room initial sync on the resulting
* room. If false, the <strong>returned Room object will have no current state.
* </strong> Default: true.
* @param {module:client.callback} callback Optional.
* @return {module:client.Promise} Resolves: Room object.
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
MatrixClient.prototype.joinRoom = function(roomIdOrAlias, callback) {
MatrixClient.prototype.joinRoom = function(roomIdOrAlias, opts, callback) {
// to help people when upgrading..
if (utils.isFunction(opts)) {
throw new Error("Expected 'opts' object, got function.");
}
opts = opts || {
syncRoom: true
};
var room = this.getRoom(roomIdOrAlias);
if (room && room.hasMembershipState(this.credentials.userId, "join")) {
return q(room);
@@ -518,7 +529,10 @@ MatrixClient.prototype.joinRoom = function(roomIdOrAlias, callback) {
function(res) {
var roomId = res.room_id;
var room = createNewRoom(self, roomId);
return _syncRoom(self, room);
if (opts.syncRoom) {
return _syncRoom(self, room);
}
return q(room);
}, function(err) {
_reject(callback, defer, err);
}).done(function(room) {
@@ -1003,6 +1017,22 @@ MatrixClient.prototype.sendTextMessage = function(roomId, body, txnId, callback)
return this.sendMessage(roomId, content, txnId, callback);
};
/**
* @param {string} roomId
* @param {string} body
* @param {string} txnId Optional.
* @param {module:client.callback} callback Optional.
* @return {module:client.Promise} Resolves: TODO
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
MatrixClient.prototype.sendNotice = function(roomId, body, txnId, callback) {
var content = {
msgtype: "m.notice",
body: body
};
return this.sendMessage(roomId, content, txnId, callback);
};
/**
* @param {string} roomId
* @param {string} body
@@ -1058,6 +1088,24 @@ MatrixClient.prototype.sendHtmlMessage = function(roomId, body, htmlBody, callba
return this.sendMessage(roomId, content, callback);
};
/**
* @param {string} roomId
* @param {string} body
* @param {string} htmlBody
* @param {module:client.callback} callback Optional.
* @return {module:client.Promise} Resolves: TODO
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
MatrixClient.prototype.sendHtmlNotice = function(roomId, body, htmlBody, callback) {
var content = {
msgtype: "m.notice",
format: "org.matrix.custom.html",
body: body,
formatted_body: htmlBody
};
return this.sendMessage(roomId, content, callback);
};
/**
* Upload a file to the media repository on the home server.
* @param {File} file object
@@ -1093,6 +1141,42 @@ MatrixClient.prototype.sendTyping = function(roomId, isTyping, timeoutMs, callba
);
};
/**
* Create an alias to room ID mapping.
* @param {string} alias The room alias to create.
* @param {string} roomId The room ID to link the alias to.
* @param {module:client.callback} callback Optional.
* @return {module:client.Promise} Resolves: TODO.
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
MatrixClient.prototype.createAlias = function(alias, roomId, callback) {
var path = utils.encodeUri("/directory/room/$alias", {
$alias: alias
});
var data = {
room_id: roomId
};
return this._http.authedRequest(
callback, "PUT", path, undefined, data
);
};
/**
* Get room info for the given alias.
* @param {string} alias The room alias to resolve.
* @param {module:client.callback} callback Optional.
* @return {module:client.Promise} Resolves: Object with room_id and servers.
* @return {module:http-api.MatrixError} Rejects: with an error response.
*/
MatrixClient.prototype.getRoomIdForAlias = function(alias, callback) {
var path = utils.encodeUri("/directory/room/$alias", {
$alias: alias
});
return this._http.authedRequest(
callback, "GET", path
);
};
/**
* @param {string} roomId
* @param {string} eventId
@@ -1309,17 +1393,21 @@ MatrixClient.prototype.setAvatarUrl = function(url, callback) {
* @param {Number} height The desired height of the thumbnail.
* @param {string} resizeMethod The thumbnail resize method to use, either
* "crop" or "scale".
* @param {Boolean} allowDefault (optional) Passing false causes this method to
* return null if the user has no avatar image. Otherwise, a default image URL
* will be returned.
* @return {?string} the avatar URL or null.
*/
MatrixClient.prototype.getAvatarUrlForMember =
function(member, width, height, resizeMethod) {
function(member, width, height, resizeMethod, allowDefault) {
if (!member || !member.events.member) {
return null;
}
if (allowDefault === undefined) { allowDefault = true; }
var rawUrl = member.events.member.getContent().avatar_url;
if (rawUrl) {
return this._http.getHttpUriForMxc(rawUrl, width, height, resizeMethod);
} else {
} else if (allowDefault) {
return this._http.getIdenticonUri(member.userId, width, height);
}
return null;
@@ -1333,10 +1421,13 @@ MatrixClient.prototype.getAvatarUrlForMember =
* @param {Number} height The desired height of the thumbnail.
* @param {string} resizeMethod The thumbnail resize method to use, either
* "crop" or "scale".
* @param {Boolean} allowDefault (optional) Passing false causes this method to
* return null if the user has no avatar image. Otherwise, a default image URL
* will be returned.
* @return {?string} the avatar URL or null.
*/
MatrixClient.prototype.getAvatarUrlForRoom =
function(room, width, height, resizeMethod) {
function(room, width, height, resizeMethod, allowDefault) {
if (!room || !room.currentState || !room.currentState.members) {
return null;
@@ -1348,7 +1439,9 @@ MatrixClient.prototype.getAvatarUrlForRoom =
});
if (members[0]) {
return this.getAvatarUrlForMember(members[0], width, height, resizeMethod);
return this.getAvatarUrlForMember(
members[0], width, height, resizeMethod, allowDefault
);
}
return null;
};
@@ -2362,7 +2455,7 @@ module.exports.CRYPTO_ENABLED = CRYPTO_ENABLED;
/**
* Fires whenever an incoming call arrives.
* @event module:client~MatrixClient#"Call.incoming"
* @param {MatrixCall} call The incoming call.
* @param {module:webrtc/call~MatrixCall} call The incoming call.
* @example
* matrixClient.on("Call.incoming", function(call){
* call.answer(); // auto-answer
+34 -14
View File
@@ -205,6 +205,9 @@ module.exports.MatrixHttpApi.prototype = {
url += "&filename=" + encodeURIComponent(file.name);
xhr.open("POST", url);
if (file.type) {
xhr.setRequestHeader("Content-Type", file.type);
}
xhr.send(file);
} else {
var queryParams = {
@@ -375,23 +378,38 @@ module.exports.MatrixHttpApi.prototype = {
}
}
var defer = q.defer();
this.opts.request(
{
uri: uri,
method: method,
withCredentials: false,
qs: queryParams,
body: data,
json: true,
_matrix_opts: this.opts
},
requestCallback(defer, callback, this.opts.onlyData)
);
try {
this.opts.request(
{
uri: uri,
method: method,
withCredentials: false,
qs: queryParams,
body: data,
json: true,
_matrix_opts: this.opts
},
requestCallback(defer, callback, this.opts.onlyData)
);
}
catch (ex) {
defer.reject(ex);
if (callback) {
callback(ex);
}
}
return defer.promise;
}
};
/*
* Returns a callback that can be invoked by an HTTP request on completion,
* that will either resolve or reject the given defer as well as invoke the
* given userDefinedCallback (if any).
*
* If onlyData is true, the defer/callback is invoked with the body of the
* response, otherwise the result code.
*/
var requestCallback = function(defer, userDefinedCallback, onlyData) {
userDefinedCallback = userDefinedCallback || function() {};
@@ -422,12 +440,14 @@ var requestCallback = function(defer, userDefinedCallback, onlyData) {
* information specific to the standard Matrix error response.
* @constructor
* @param {Object} errorJson The Matrix error JSON returned from the homeserver.
* @prop {string} name The Matrix 'errcode' value, e.g. "M_FORBIDDEN".
* @prop {string} errcode The Matrix 'errcode' value, e.g. "M_FORBIDDEN".
* @prop {string} name Same as MatrixError.errcode but with a default unknown string.
* @prop {string} message The Matrix 'error' value, e.g. "Missing token."
* @prop {Object} data The raw Matrix error JSON used to construct this object.
* @prop {integer} httpStatus The numeric HTTP status code given
*/
module.exports.MatrixError = function MatrixError(errorJson) {
this.errcode = errorJson.errcode;
this.name = errorJson.errcode || "Unknown error code";
this.message = errorJson.error || "Unknown message";
this.data = errorJson;
+7 -1
View File
@@ -278,7 +278,13 @@ function calculateRoomName(room, userId) {
if (memberList.length === 1) {
// we exist, but no one else... self-chat or invite.
if (memberList[0].membership === "invite") {
return "Room Invite";
if (memberList[0].events.member) {
// extract who invited us to the room
return "Invite from " + memberList[0].events.member.getSender();
}
else {
return "Room Invite";
}
}
else {
return userId;
+4
View File
@@ -129,6 +129,10 @@ MatrixScheduler.prototype.queueEvent = function(event) {
* @see module:scheduler~retryAlgorithm
*/
MatrixScheduler.RETRY_BACKOFF_RATELIMIT = function(event, attempts, err) {
if (err.httpStatus === 400 || err.httpStatus === 403 || err.httpStatus === 401) {
// client error; no amount of retrying with save you now.
return -1;
}
if (err.name === "M_LIMIT_EXCEEDED") {
var waitTime = err.data.retry_after_ms;
if (waitTime) {
+2 -1
View File
@@ -1,11 +1,12 @@
{
"name": "matrix-js-sdk",
"version": "0.2.0",
"version": "0.2.1",
"description": "Matrix Client-Server SDK for Javascript",
"main": "index.js",
"scripts": {
"test": "istanbul cover --report cobertura --config .istanbul.yml -i \"lib/**/*.js\" jasmine-node -- spec --verbose --junitreport --forceexit --captureExceptions",
"check": "jasmine-node spec --verbose --junitreport --forceexit --captureExceptions",
"gendoc": "jsdoc -r lib -P package.json -R README.md -d .jsdoc",
"build": "jshint -c .jshint lib/ && browserify browser-index.js -o dist/browser-matrix-dev.js --ignore-missing",
"watch": "watchify browser-index.js -o dist/browser-matrix-dev.js -v",
"lint": "jshint -c .jshint lib spec && gjslint --unix_mode --disable 0131,0211,0200,0222 --max_line_length 90 -r spec/ -r lib/",
@@ -280,11 +280,12 @@ describe("MatrixClient room timelines", function() {
client.scrollback(room, 1).done(function() {
expect(room.oldState.paginationToken).toEqual(sbEndTok);
done();
});
httpBackend.flush("/messages", 1);
httpBackend.flush("/events", 1);
httpBackend.flush("/events", 1).done(function() {
done();
});
});
httpBackend.flush("/initialSync", 1);
});