1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

Merge branch 'develop' into room_key_sharing

This commit is contained in:
Richard van der Hoff
2017-06-19 17:38:35 +01:00
11 changed files with 144 additions and 24 deletions

View File

@@ -1,3 +1,35 @@
Changes in [0.7.12](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.7.12) (2017-06-19)
==================================================================================================
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.7.12-rc.1...v0.7.12)
* No changes
Changes in [0.7.12-rc.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.7.12-rc.1) (2017-06-15)
============================================================================================================
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.7.11...v0.7.12-rc.1)
* allow setting iceTransportPolicy to relay through forceTURN option
[\#462](https://github.com/matrix-org/matrix-js-sdk/pull/462)
Changes in [0.7.11](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.7.11) (2017-06-12)
==================================================================================================
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.7.11-rc.1...v0.7.11)
* Add a bunch of logging around sending messages
[\#460](https://github.com/matrix-org/matrix-js-sdk/pull/460)
Changes in [0.7.11-rc.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.7.11-rc.1) (2017-06-09)
============================================================================================================
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.7.10...v0.7.11-rc.1)
* Make TimelineWindow.load resolve quicker if we have the events
[\#458](https://github.com/matrix-org/matrix-js-sdk/pull/458)
* Stop peeking when a matrix client is stopped
[\#451](https://github.com/matrix-org/matrix-js-sdk/pull/451)
* Update README: Clarify how to install libolm
[\#450](https://github.com/matrix-org/matrix-js-sdk/pull/450)
Changes in [0.7.10](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.7.10) (2017-06-02) Changes in [0.7.10](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v0.7.10) (2017-06-02)
================================================================================================== ==================================================================================================
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.7.9...v0.7.10) [Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v0.7.9...v0.7.10)

View File

@@ -1,6 +1,6 @@
{ {
"name": "matrix-js-sdk", "name": "matrix-js-sdk",
"version": "0.7.10", "version": "0.7.12",
"description": "Matrix Client-Server SDK for Javascript", "description": "Matrix Client-Server SDK for Javascript",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@@ -678,6 +678,31 @@ MatrixBaseApis.prototype.setRoomDirectoryVisibilityAppService =
); );
}; };
// User Directory Operations
// =========================
/**
* Query the user directory with a term matching user IDs, display names and domains.
* @param {object} opts options
* @param {string} opts.term the term with which to search.
* @param {number} opts.limit the maximum number of results to return. The server will
* apply a limit if unspecified.
* @return {module:client.Promise} Resolves: an array of results.
*/
MatrixBaseApis.prototype.searchUserDirectory = function(opts) {
const body = {
search_term: opts.term,
};
if (opts.limit !== undefined) {
body.limit = opts.limit;
}
return this._http.authedRequest(
undefined, "POST", "/user_directory/search", undefined, body,
);
};
// Media operations // Media operations
// ================ // ================

View File

@@ -947,6 +947,8 @@ MatrixClient.prototype.sendEvent = function(roomId, eventType, content, txnId,
txnId = this.makeTxnId(); txnId = this.makeTxnId();
} }
console.log(`sendEvent of type ${eventType} in ${roomId} with txnId ${txnId}`);
// we always construct a MatrixEvent when sending because the store and // we always construct a MatrixEvent when sending because the store and
// scheduler use them. We'll extract the params back out if it turns out // scheduler use them. We'll extract the params back out if it turns out
// the client has no scheduler or store. // the client has no scheduler or store.
@@ -1071,7 +1073,12 @@ function _sendEventHttpRequest(client, event) {
return client._http.authedRequest( return client._http.authedRequest(
undefined, "PUT", path, undefined, event.getWireContent(), undefined, "PUT", path, undefined, event.getWireContent(),
); ).then((res) => {
console.log(
`Event sent to ${event.getRoomId()} with event id ${res.event_id}`,
);
return res;
});
} }
/** /**

View File

@@ -76,6 +76,10 @@ export default class DeviceList {
if (this._keyDownloadsInProgressByUser[u]) { if (this._keyDownloadsInProgressByUser[u]) {
// already a key download in progress/queued for this user; its results // already a key download in progress/queued for this user; its results
// will be good enough for us. // will be good enough for us.
console.log(
`downloadKeys: already have a download in progress for ` +
`${u}: awaiting its result`,
);
promises.push(this._keyDownloadsInProgressByUser[u]); promises.push(this._keyDownloadsInProgressByUser[u]);
} else if (forceDownload || trackingStatus != TRACKING_STATUS_UP_TO_DATE) { } else if (forceDownload || trackingStatus != TRACKING_STATUS_UP_TO_DATE) {
usersToDownload.push(u); usersToDownload.push(u);
@@ -88,6 +92,10 @@ export default class DeviceList {
promises.push(downloadPromise); promises.push(downloadPromise);
} }
if (promises.length === 0) {
console.log("downloadKeys: already have all necessary keys");
}
return q.all(promises).then(() => { return q.all(promises).then(() => {
return this._getDevicesFromStore(userIds); return this._getDevicesFromStore(userIds);
}); });

View File

@@ -183,6 +183,7 @@ MegolmEncryption.prototype._ensureOutboundSession = function(devicesInRoom) {
} }
if (!session) { if (!session) {
console.log(`Starting new megolm session for room ${self._roomId}`);
session = self._prepareNewSession(); session = self._prepareNewSession();
} }
@@ -353,6 +354,8 @@ MegolmEncryption.prototype._shareKeyWithDevices = function(session, devicesByUse
// TODO: retries // TODO: retries
return self._baseApis.sendToDevice("m.room.encrypted", contentMap); return self._baseApis.sendToDevice("m.room.encrypted", contentMap);
}).then(function() { }).then(function() {
console.log(`Completed megolm keyshare in ${self._roomId}`);
// Add the devices we have shared with to session.sharedWithDevices. // Add the devices we have shared with to session.sharedWithDevices.
// //
// we deliberately iterate over devicesByUser (ie, the devices we // we deliberately iterate over devicesByUser (ie, the devices we
@@ -387,6 +390,8 @@ MegolmEncryption.prototype._shareKeyWithDevices = function(session, devicesByUse
*/ */
MegolmEncryption.prototype.encryptMessage = function(room, eventType, content) { MegolmEncryption.prototype.encryptMessage = function(room, eventType, content) {
const self = this; const self = this;
console.log(`Starting to encrypt event for ${this._roomId}`);
return this._getDevicesInRoom(room).then(function(devicesInRoom) { return this._getDevicesInRoom(room).then(function(devicesInRoom) {
// check if any of these devices are not yet known to the user. // check if any of these devices are not yet known to the user.
// if so, warn the user so they can verify or ignore. // if so, warn the user so they can verify or ignore.

View File

@@ -752,6 +752,8 @@ ALLOWED_TRANSITIONS[EventStatus.CANCELLED] =
* @fires module:client~MatrixClient#event:"Room.localEchoUpdated" * @fires module:client~MatrixClient#event:"Room.localEchoUpdated"
*/ */
Room.prototype.updatePendingEvent = function(event, newStatus, newEventId) { Room.prototype.updatePendingEvent = function(event, newStatus, newEventId) {
console.log(`setting pendingEvent status to ${newStatus} in ${event.getRoomId()}`);
// if the message was sent, we expect an event id // if the message was sent, we expect an event id
if (newStatus == EventStatus.SENT && !newEventId) { if (newStatus == EventStatus.SENT && !newEventId) {
throw new Error("updatePendingEvent called with status=SENT, " + throw new Error("updatePendingEvent called with status=SENT, " +

View File

@@ -163,8 +163,27 @@ LocalIndexedDBStoreBackend.prototype = {
* @return {Promise} Resolved when the database is cleared. * @return {Promise} Resolved when the database is cleared.
*/ */
clearDatabase: function() { clearDatabase: function() {
console.log("Removing indexeddb instance: ", this._dbName); return new q.Promise((resolve, reject) => {
return promiseifyRequest(this.indexedDB.deleteDatabase(this._dbName)); console.log(`Removing indexeddb instance: ${this._dbName}`);
const req = this.indexedDB.deleteDatabase(this._dbName);
req.onblocked = () => {
reject(new Error(
"unable to delete indexeddb because it is open elsewhere",
));
};
req.onerror = (ev) => {
reject(new Error(
"unable to delete indexeddb: " + ev.target.error,
));
};
req.onsuccess = () => {
console.log(`Removed indexeddb instance: ${this._dbName}`);
resolve();
};
});
}, },
/** /**

View File

@@ -150,7 +150,7 @@ IndexedDBStore.prototype.deleteAllData = function() {
return this.backend.clearDatabase().then(() => { return this.backend.clearDatabase().then(() => {
console.log("Deleted indexeddb data."); console.log("Deleted indexeddb data.");
}, (err) => { }, (err) => {
console.error("Failed to delete indexeddb data: ", err); console.error(`Failed to delete indexeddb data: ${err}`);
throw err; throw err;
}); });
}; };

View File

@@ -95,10 +95,30 @@ TimelineWindow.prototype.load = function(initialEventId, initialWindowSize) {
const self = this; const self = this;
initialWindowSize = initialWindowSize || 20; initialWindowSize = initialWindowSize || 20;
// given an EventTimeline, and an event index within it, initialise our // given an EventTimeline, find the event we were looking for, and initialise our
// fields so that the event in question is in the middle of the window. // fields so that the event in question is in the middle of the window.
const initFields = function(timeline, eventIndex) { const initFields = function(timeline) {
const endIndex = Math.min(timeline.getEvents().length, let eventIndex;
const events = timeline.getEvents();
if (!initialEventId) {
// we were looking for the live timeline: initialise to the end
eventIndex = events.length;
} else {
for (let i = 0; i < events.length; i++) {
if (events[i].getId() == initialEventId) {
eventIndex = i;
break;
}
}
if (eventIndex === undefined) {
throw new Error("getEventTimeline result didn't include requested event");
}
}
const endIndex = Math.min(events.length,
eventIndex + Math.ceil(initialWindowSize / 2)); eventIndex + Math.ceil(initialWindowSize / 2));
const startIndex = Math.max(0, endIndex - initialWindowSize); const startIndex = Math.max(0, endIndex - initialWindowSize);
self._start = new TimelineIndex(timeline, startIndex - timeline.getBaseIndex()); self._start = new TimelineIndex(timeline, startIndex - timeline.getBaseIndex());
@@ -110,24 +130,19 @@ TimelineWindow.prototype.load = function(initialEventId, initialWindowSize) {
// we already have the data we need, which is important to keep room-switching // we already have the data we need, which is important to keep room-switching
// feeling snappy. // feeling snappy.
// //
// TODO: ideally we'd spot getEventTimeline returning a resolved promise and
// skip straight to the find-event loop.
if (initialEventId) { if (initialEventId) {
return this._client.getEventTimeline(this._timelineSet, initialEventId) const prom = this._client.getEventTimeline(this._timelineSet, initialEventId);
.then(function(tl) {
// make sure that our window includes the event const promState = prom.inspect();
for (let i = 0; i < tl.getEvents().length; i++) { if (promState.state == 'fulfilled') {
if (tl.getEvents()[i].getId() == initialEventId) { initFields(promState.value);
initFields(tl, i); return q();
return; } else {
} return prom.then(initFields);
} }
throw new Error("getEventTimeline result didn't include requested event");
});
} else { } else {
// start with the most recent events
const tl = this._timelineSet.getLiveTimeline(); const tl = this._timelineSet.getLiveTimeline();
initFields(tl, tl.getEvents().length); initFields(tl);
return q(); return q();
} }
}; };

View File

@@ -71,6 +71,7 @@ const DEBUG = true; // set true to enable console logging.
* @param {Object} opts Config options. * @param {Object} opts Config options.
* @param {string} opts.roomId The room ID for this call. * @param {string} opts.roomId The room ID for this call.
* @param {Object} opts.webRtc The WebRTC globals from the browser. * @param {Object} opts.webRtc The WebRTC globals from the browser.
* @param {boolean} opts.forceTURN whether relay through TURN should be forced.
* @param {Object} opts.URL The URL global. * @param {Object} opts.URL The URL global.
* @param {Array<Object>} opts.turnServers Optional. A list of TURN servers. * @param {Array<Object>} opts.turnServers Optional. A list of TURN servers.
* @param {MatrixClient} opts.client The Matrix Client instance to send events to. * @param {MatrixClient} opts.client The Matrix Client instance to send events to.
@@ -79,6 +80,7 @@ function MatrixCall(opts) {
this.roomId = opts.roomId; this.roomId = opts.roomId;
this.client = opts.client; this.client = opts.client;
this.webRtc = opts.webRtc; this.webRtc = opts.webRtc;
this.forceTURN = opts.forceTURN;
this.URL = opts.URL; this.URL = opts.URL;
// Array of Objects with urls, username, credential keys // Array of Objects with urls, username, credential keys
this.turnServers = opts.turnServers || []; this.turnServers = opts.turnServers || [];
@@ -1184,6 +1186,7 @@ const _createPeerConnection = function(self) {
} }
const pc = new self.webRtc.RtcPeerConnection({ const pc = new self.webRtc.RtcPeerConnection({
iceTransportPolicy: self.forceTURN ? 'relay' : undefined,
iceServers: servers, iceServers: servers,
}); });
pc.oniceconnectionstatechange = hookCallback(self, self._onIceConnectionStateChanged); pc.oniceconnectionstatechange = hookCallback(self, self._onIceConnectionStateChanged);
@@ -1293,9 +1296,11 @@ module.exports.setVideoInput = function(deviceId) { videoInput = deviceId; };
* Create a new Matrix call for the browser. * Create a new Matrix call for the browser.
* @param {MatrixClient} client The client instance to use. * @param {MatrixClient} client The client instance to use.
* @param {string} roomId The room the call is in. * @param {string} roomId The room the call is in.
* @param {Object?} options optional options map.
* @param {boolean} options.forceTURN whether relay through TURN should be forced.
* @return {MatrixCall} the call or null if the browser doesn't support calling. * @return {MatrixCall} the call or null if the browser doesn't support calling.
*/ */
module.exports.createNewMatrixCall = function(client, roomId) { module.exports.createNewMatrixCall = function(client, roomId, options) {
const w = global.window; const w = global.window;
const doc = global.document; const doc = global.document;
if (!w || !doc) { if (!w || !doc) {
@@ -1351,6 +1356,8 @@ module.exports.createNewMatrixCall = function(client, roomId) {
URL: w.URL, URL: w.URL,
roomId: roomId, roomId: roomId,
turnServers: client.getTurnServers(), turnServers: client.getTurnServers(),
// call level options
forceTURN: options ? options.forceTURN : false,
}; };
return new MatrixCall(opts); return new MatrixCall(opts);
}; };