Skip to content

Commit c6c59dc

Browse files
committed
Merge branch 'develop' of github.com:matrix-org/matrix-js-sdk into t3chguy/spaces
2 parents 16d1982 + 371ca00 commit c6c59dc

File tree

16 files changed

+391
-105
lines changed

16 files changed

+391
-105
lines changed

CHANGELOG.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,70 @@
1+
Changes in [9.7.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v9.7.0) (2021-02-16)
2+
================================================================================================
3+
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v9.7.0-rc.1...v9.7.0)
4+
5+
* No changes since rc.1
6+
7+
Changes in [9.7.0-rc.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v9.7.0-rc.1) (2021-02-10)
8+
==========================================================================================================
9+
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v9.6.0...v9.7.0-rc.1)
10+
11+
* Handle undefined peerconn
12+
[\#1600](https://github.com/matrix-org/matrix-js-sdk/pull/1600)
13+
* ReEmitter: Don't throw if no error handler is attached
14+
[\#1599](https://github.com/matrix-org/matrix-js-sdk/pull/1599)
15+
* Convert ReEmitter to TS
16+
[\#1598](https://github.com/matrix-org/matrix-js-sdk/pull/1598)
17+
* Fix typo in main readme
18+
[\#1597](https://github.com/matrix-org/matrix-js-sdk/pull/1597)
19+
* Remove rogue plus character
20+
[\#1596](https://github.com/matrix-org/matrix-js-sdk/pull/1596)
21+
* Fix call ID NaN
22+
[\#1595](https://github.com/matrix-org/matrix-js-sdk/pull/1595)
23+
* Fix Electron type merging
24+
[\#1594](https://github.com/matrix-org/matrix-js-sdk/pull/1594)
25+
* Fix browser screen share
26+
[\#1593](https://github.com/matrix-org/matrix-js-sdk/pull/1593)
27+
* Fix desktop Matrix screen sharing
28+
[\#1570](https://github.com/matrix-org/matrix-js-sdk/pull/1570)
29+
* Guard against confused server retry times
30+
[\#1591](https://github.com/matrix-org/matrix-js-sdk/pull/1591)
31+
* Decrypt redaction events
32+
[\#1589](https://github.com/matrix-org/matrix-js-sdk/pull/1589)
33+
* Fix edge cases with peeking where a room is re-peeked
34+
[\#1587](https://github.com/matrix-org/matrix-js-sdk/pull/1587)
35+
36+
Changes in [9.6.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v9.6.0) (2021-02-03)
37+
================================================================================================
38+
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v9.6.0-rc.1...v9.6.0)
39+
40+
* [Release] Fix edge cases with peeking where a room is re-peeked
41+
[\#1588](https://github.com/matrix-org/matrix-js-sdk/pull/1588)
42+
43+
Changes in [9.6.0-rc.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v9.6.0-rc.1) (2021-01-29)
44+
==========================================================================================================
45+
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v9.5.1...v9.6.0-rc.1)
46+
47+
* Add support for getting call stats
48+
[\#1584](https://github.com/matrix-org/matrix-js-sdk/pull/1584)
49+
* Fix compatibility with v0 calls
50+
[\#1583](https://github.com/matrix-org/matrix-js-sdk/pull/1583)
51+
* Upgrade deps 2021-01
52+
[\#1582](https://github.com/matrix-org/matrix-js-sdk/pull/1582)
53+
* Log the call ID when logging that we've received VoIP events
54+
[\#1581](https://github.com/matrix-org/matrix-js-sdk/pull/1581)
55+
* Fix extra negotiate message in Firefox
56+
[\#1579](https://github.com/matrix-org/matrix-js-sdk/pull/1579)
57+
* Add debug logs to encryption prep
58+
[\#1580](https://github.com/matrix-org/matrix-js-sdk/pull/1580)
59+
* Expose getPresence endpoint
60+
[\#1578](https://github.com/matrix-org/matrix-js-sdk/pull/1578)
61+
* Queue keys for backup even if backup isn't enabled yet
62+
[\#1577](https://github.com/matrix-org/matrix-js-sdk/pull/1577)
63+
* Stop retrying TURN access when forbidden
64+
[\#1576](https://github.com/matrix-org/matrix-js-sdk/pull/1576)
65+
* Add DTMF sending support
66+
[\#1573](https://github.com/matrix-org/matrix-js-sdk/pull/1573)
67+
168
Changes in [9.5.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v9.5.1) (2021-01-26)
269
================================================================================================
370
[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v9.5.0...v9.5.1)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ The SDK supports end-to-end encryption via the Olm and Megolm protocols, using
307307
[libolm](https://gitlab.matrix.org/matrix-org/olm). It is left up to the
308308
application to make libolm available, via the ``Olm`` global.
309309

310-
It is also necessry to call ``matrixClient.initCrypto()`` after creating a new
310+
It is also necessary to call ``matrixClient.initCrypto()`` after creating a new
311311
``MatrixClient`` (but **before** calling ``matrixClient.startClient()``) to
312312
initialise the crypto layer.
313313

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "matrix-js-sdk",
3-
"version": "9.5.1",
3+
"version": "9.7.0",
44
"description": "Matrix Client-Server SDK for Javascript",
55
"scripts": {
66
"prepublishOnly": "yarn build",

spec/unit/ReEmitter.spec.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
Copyright 2021 The Matrix.org Foundation C.I.C.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { EventEmitter } from "events";
18+
import { ReEmitter } from "../../src/ReEmitter";
19+
20+
const EVENTNAME = "UnknownEntry";
21+
22+
class EventSource extends EventEmitter {
23+
doTheThing() {
24+
this.emit(EVENTNAME, "foo", "bar");
25+
}
26+
27+
doAnError() {
28+
this.emit('error');
29+
}
30+
}
31+
32+
class EventTarget extends EventEmitter {
33+
34+
}
35+
36+
describe("ReEmitter", function() {
37+
it("Re-Emits events with the same args", function() {
38+
const src = new EventSource();
39+
const tgt = new EventTarget();
40+
41+
const handler = jest.fn();
42+
tgt.on(EVENTNAME, handler);
43+
44+
const reEmitter = new ReEmitter(tgt);
45+
reEmitter.reEmit(src, [EVENTNAME]);
46+
47+
src.doTheThing();
48+
49+
// Args should be the args passed to 'emit' after the event name, and
50+
// also the source object of the event which re-emitter adds
51+
expect(handler).toHaveBeenCalledWith("foo", "bar", src);
52+
});
53+
54+
it("Doesn't throw if no handler for 'error' event", function() {
55+
const src = new EventSource();
56+
const tgt = new EventTarget();
57+
58+
const reEmitter = new ReEmitter(tgt);
59+
reEmitter.reEmit(src, ['error']);
60+
61+
// without the workaround in ReEmitter, this would throw
62+
src.doAnError();
63+
64+
const handler = jest.fn();
65+
tgt.on('error', handler);
66+
67+
src.doAnError();
68+
69+
// Now we've attached an error handler, it should be called
70+
expect(handler).toHaveBeenCalled();
71+
});
72+
});

src/@types/global.d.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,49 @@ declare global {
2626
}
2727
}
2828

29+
interface Window {
30+
electron?: Electron;
31+
}
32+
33+
interface Electron {
34+
getDesktopCapturerSources(options: GetSourcesOptions): Promise<Array<DesktopCapturerSource>>;
35+
}
36+
2937
interface MediaDevices {
3038
// This is experimental and types don't know about it yet
3139
// https://github.com/microsoft/TypeScript/issues/33232
32-
getDisplayMedia(constraints: MediaStreamConstraints): Promise<MediaStream>;
40+
getDisplayMedia(constraints: MediaStreamConstraints | DesktopCapturerConstraints): Promise<MediaStream>;
41+
getUserMedia(constraints: MediaStreamConstraints | DesktopCapturerConstraints): Promise<MediaStream>;
42+
}
43+
44+
export interface DesktopCapturerConstraints {
45+
audio: boolean | {
46+
mandatory: {
47+
chromeMediaSource: string;
48+
chromeMediaSourceId: string;
49+
};
50+
};
51+
video: boolean | {
52+
mandatory: {
53+
chromeMediaSource: string;
54+
chromeMediaSourceId: string;
55+
};
56+
};
57+
}
58+
59+
export interface DesktopCapturerSource {
60+
id: string;
61+
name: string;
62+
thumbnailURL: string;
63+
}
64+
65+
interface GetSourcesOptions {
66+
types: Array<string>;
67+
thumbnailSize?: {
68+
height: number;
69+
width: number;
70+
};
71+
fetchWindowIcons?: boolean;
3372
}
3473

3574
interface HTMLAudioElement {

src/ReEmitter.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

src/ReEmitter.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2015, 2016 OpenMarket Ltd
3+
Copyright 2017 Vector Creations Ltd
4+
Copyright 2017 New Vector Ltd
5+
6+
Licensed under the Apache License, Version 2.0 (the "License");
7+
you may not use this file except in compliance with the License.
8+
You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
*/
18+
19+
import { EventEmitter } from "events";
20+
21+
export class ReEmitter {
22+
private target: EventEmitter;
23+
24+
constructor(target: EventEmitter) {
25+
this.target = target;
26+
}
27+
28+
reEmit(source: EventEmitter, eventNames: string[]) {
29+
for (const eventName of eventNames) {
30+
// We include the source as the last argument for event handlers which may need it,
31+
// such as read receipt listeners on the client class which won't have the context
32+
// of the room.
33+
const forSource = (...args) => {
34+
// EventEmitter special cases 'error' to make the emit function throw if no
35+
// handler is attached, which sort of makes sense for making sure that something
36+
// handles an error, but for re-emitting, there could be a listener on the original
37+
// source object so the test doesn't really work. We *could* try to replicate the
38+
// same logic and throw if there is no listener on either the source or the target,
39+
// but this behaviour is fairly undesireable for us anyway: the main place we throw
40+
// 'error' events is for calls, where error events are usually emitted some time
41+
// later by a different part of the code where 'emit' throwing because the app hasn't
42+
// added an error handler isn't terribly helpful. (A better fix in retrospect may
43+
// have been to just avoid using the event name 'error', but backwards compat...)
44+
if (eventName === 'error' && this.target.listenerCount('error') === 0) return;
45+
this.target.emit(eventName, ...args, source);
46+
};
47+
source.on(eventName, forSource);
48+
}
49+
}
50+
}

src/client.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,11 @@ function keyFromRecoverySession(session, decryptionKey) {
180180
* @param {boolean} [opts.forceTURN]
181181
* Optional. Whether relaying calls through a TURN server should be forced.
182182
*
183+
* * @param {boolean} [opts.iceCandidatePoolSize]
184+
* Optional. Up to this many ICE candidates will be gathered when an incoming call arrives.
185+
* Gathering does not send data to the caller, but will communicate with the configured TURN
186+
* server. Default 0.
187+
*
183188
* @param {boolean} [opts.supportsCallTransfer]
184189
* Optional. True to advertise support for call transfers to other parties on Matrix calls.
185190
*
@@ -367,6 +372,7 @@ export function MatrixClient(opts) {
367372
this._cryptoCallbacks = opts.cryptoCallbacks || {};
368373

369374
this._forceTURN = opts.forceTURN || false;
375+
this._iceCandidatePoolSize = opts.iceCandidatePoolSize === undefined ? 0 : opts.iceCandidatePoolSize;
370376
this._supportsCallTransfer = opts.supportsCallTransfer || false;
371377
this._fallbackICEServerAllowed = opts.fallbackICEServerAllowed || false;
372378

src/crypto/algorithms/megolm.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -743,16 +743,17 @@ MegolmEncryption.prototype._shareKeyWithOlmSessions = async function(
743743
const userDeviceMaps = this._splitDevices(devicemap);
744744

745745
for (let i = 0; i < userDeviceMaps.length; i++) {
746+
const taskDetail =
747+
`megolm keys for ${session.sessionId} ` +
748+
`in ${this._roomId} (slice ${i + 1}/${userDeviceMaps.length})`;
746749
try {
750+
logger.debug(`Sharing ${taskDetail}`);
747751
await this._encryptAndSendKeysToDevices(
748752
session, key.chain_index, userDeviceMaps[i], payload,
749753
);
750-
logger.log(`Completed megolm keyshare for ${session.sessionId} `
751-
+ `in ${this._roomId} (slice ${i + 1}/${userDeviceMaps.length})`);
754+
logger.debug(`Shared ${taskDetail}`);
752755
} catch (e) {
753-
logger.log(`megolm keyshare for ${session.sessionId} in ${this._roomId} `
754-
+ `(slice ${i + 1}/${userDeviceMaps.length}) failed`);
755-
756+
logger.error(`Failed to share ${taskDetail}`);
756757
throw e;
757758
}
758759
}

src/crypto/index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {IllegalMethod} from "./verification/IllegalMethod";
5757
import {KeySignatureUploadError} from "../errors";
5858
import {decryptAES, encryptAES} from './aes';
5959
import {DehydrationManager} from './dehydration';
60+
import { MatrixEvent } from "../models/event";
6061

6162
const DeviceVerification = DeviceInfo.DeviceVerification;
6263

@@ -3028,19 +3029,26 @@ Crypto.prototype.encryptEvent = async function(event, room) {
30283029
* finished decrypting. Rejects with an `algorithms.DecryptionError` if there
30293030
* is a problem decrypting the event.
30303031
*/
3031-
Crypto.prototype.decryptEvent = function(event) {
3032+
Crypto.prototype.decryptEvent = async function(event) {
30323033
if (event.isRedacted()) {
3033-
return Promise.resolve({
3034+
const redactionEvent = new MatrixEvent(event.getUnsigned().redacted_because);
3035+
const decryptedEvent = await this.decryptEvent(redactionEvent);
3036+
3037+
return {
30343038
clearEvent: {
30353039
room_id: event.getRoomId(),
30363040
type: "m.room.message",
30373041
content: {},
3042+
unsigned: {
3043+
redacted_because: decryptedEvent.clearEvent,
3044+
},
30383045
},
3039-
});
3046+
};
3047+
} else {
3048+
const content = event.getWireContent();
3049+
const alg = this._getRoomDecryptor(event.getRoomId(), content.algorithm);
3050+
return await alg.decryptEvent(event);
30403051
}
3041-
const content = event.getWireContent();
3042-
const alg = this._getRoomDecryptor(event.getRoomId(), content.algorithm);
3043-
return alg.decryptEvent(event);
30443052
};
30453053

30463054
/**

0 commit comments

Comments
 (0)