From 2f71c93b5316402e3f4566a1dec9268483348d58 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Fri, 5 Mar 2021 16:12:39 +0000 Subject: [PATCH 01/20] Add space summary suggested only param --- src/base-apis.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/base-apis.js b/src/base-apis.js index 37c3d76d6..5b2a70b81 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -2378,18 +2378,27 @@ MatrixBaseApis.prototype.reportEvent = function(roomId, eventId, score, reason) * Fetches or paginates a summary of a space as defined by MSC2946 * @param {string} roomId The ID of the space-room to use as the root of the summary. * @param {number?} maxRoomsPerSpace The maximum number of rooms to return per subspace. + * @param {boolean?} suggestedOnly Whether to only return rooms with suggested=true. * @param {boolean?} autoJoinOnly Whether to only return rooms with auto_join=true. * @param {number?} limit The maximum number of rooms to return in total. * @param {string?} batch The opaque token to paginate a previous summary request. * @returns {Promise} the response, with next_batch, rooms, events fields. */ -MatrixBaseApis.prototype.getSpaceSummary = function(roomId, maxRoomsPerSpace, autoJoinOnly, limit, batch) { +MatrixBaseApis.prototype.getSpaceSummary = function( + roomId, + maxRoomsPerSpace, + suggestedOnly, + autoJoinOnly, + limit, + batch, +) { const path = utils.encodeUri("/rooms/$roomId/spaces", { $roomId: roomId, }); return this._http.authedRequest(undefined, "POST", path, null, { max_rooms_per_space: maxRoomsPerSpace, + suggested_only: suggestedOnly, auto_join_only: autoJoinOnly, limit, batch, From ccf06f2216d8da578546ea9e0f7305b1bd637fe2 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Mon, 8 Mar 2021 04:58:55 +0000 Subject: [PATCH 02/20] don't cancel ourselves when selecting a self-verification partner --- src/crypto/verification/request/ToDeviceChannel.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/crypto/verification/request/ToDeviceChannel.js b/src/crypto/verification/request/ToDeviceChannel.js index d04a75853..9f3659389 100644 --- a/src/crypto/verification/request/ToDeviceChannel.js +++ b/src/crypto/verification/request/ToDeviceChannel.js @@ -179,7 +179,9 @@ export class ToDeviceChannel { const isAcceptingEvent = type === START_TYPE || type === READY_TYPE; // the request has picked a ready or start event, tell the other devices about it if (isAcceptingEvent && !wasStarted && isStarted && this._deviceId) { - const nonChosenDevices = this._devices.filter(d => d !== this._deviceId); + const nonChosenDevices = this._devices.filter( + d => d !== this._deviceId && d !== this._client.getDeviceId(), + ); if (nonChosenDevices.length) { const message = this.completeContent({ code: "m.accepted", From 844a2b457cdacfb12bbe995a567c5fdbf0551ad2 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Mon, 8 Mar 2021 04:59:19 +0000 Subject: [PATCH 03/20] expose getDehydratedDevice API --- src/client.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/client.js b/src/client.js index 5e224a5bf..03aba0c15 100644 --- a/src/client.js +++ b/src/client.js @@ -569,6 +569,27 @@ MatrixClient.prototype.rehydrateDevice = async function() { } }; +/** + * Get the current dehydrated device, if any + * @return {Promise} A promise of an object containing the dehydrated device + */ +MatrixClient.prototype.getDehydratedDevice = async function() { + try { + return await this._http.authedRequest( + undefined, + "GET", + "/dehydrated_device", + undefined, undefined, + { + prefix: "/_matrix/client/unstable/org.matrix.msc2697.v2", + }, + ); + } catch (e) { + logger.info("could not get dehydrated device", e.toString()); + return; + } +}; + /** * Set the dehydration key. This will also periodically dehydrate devices to * the server. From 1c4d0b5e990cf128277fcf9496b2a8f3ee121da3 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Mon, 8 Mar 2021 04:59:29 +0000 Subject: [PATCH 04/20] expose getDevice API --- src/base-apis.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/base-apis.js b/src/base-apis.js index 07694596b..9e5b078c7 100644 --- a/src/base-apis.js +++ b/src/base-apis.js @@ -1518,6 +1518,21 @@ MatrixBaseApis.prototype.getDevices = function() { ); }; +/** + * Gets specific device details for the logged-in user + * @param {string} device_id device to query + * @return {Promise} Resolves: result object + * @return {module:http-api.MatrixError} Rejects: with an error response. + */ +MatrixBaseApis.prototype.getDevice = function(device_id) { + const path = utils.encodeUri("/devices/$device_id", { + $device_id: device_id, + }); + return this._http.authedRequest( + undefined, 'GET', path, undefined, undefined, + ); +}; + /** * Update the given device * From 0bafe263d774451d8b898094a34422736b3e0ed9 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Mon, 8 Mar 2021 05:05:14 +0000 Subject: [PATCH 05/20] fix lint --- src/http-api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http-api.js b/src/http-api.js index cc86506ad..23006f35d 100644 --- a/src/http-api.js +++ b/src/http-api.js @@ -274,7 +274,7 @@ MatrixHttpApi.prototype = { switch (xhr.readyState) { case global.XMLHttpRequest.DONE: callbacks.clearTimeout(xhr.timeout_timer); - var resp; + let resp; try { if (xhr.status === 0) { throw new AbortError(); From 977682d37fc87b9fe09d9af6b418dc32ef30c1e9 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Mon, 8 Mar 2021 09:24:25 +0000 Subject: [PATCH 06/20] fix lint --- src/http-api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/http-api.js b/src/http-api.js index 23006f35d..26b3d5f5b 100644 --- a/src/http-api.js +++ b/src/http-api.js @@ -271,10 +271,10 @@ MatrixHttpApi.prototype = { xhr.timeout_timer = callbacks.setTimeout(timeout_fn, 30000); xhr.onreadystatechange = function() { + let resp; switch (xhr.readyState) { case global.XMLHttpRequest.DONE: callbacks.clearTimeout(xhr.timeout_timer); - let resp; try { if (xhr.status === 0) { throw new AbortError(); From 9fb2fbaeecff884d3d8d60584bcdf1e293aefa29 Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Tue, 9 Mar 2021 00:09:22 +0000 Subject: [PATCH 07/20] factor out getDehydratedDevice --- src/client.js | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/src/client.js b/src/client.js index fe2081fcb..532f24205 100644 --- a/src/client.js +++ b/src/client.js @@ -498,19 +498,8 @@ MatrixClient.prototype.rehydrateDevice = async function() { return; } - let getDeviceResult; - try { - getDeviceResult = await this._http.authedRequest( - undefined, - "GET", - "/dehydrated_device", - undefined, undefined, - { - prefix: "/_matrix/client/unstable/org.matrix.msc2697.v2", - }, - ); - } catch (e) { - logger.info("could not get dehydrated device", e.toString()); + const getDeviceResult = this.getDehydratedDevice(); + if (!getDeviceResult) { return; } From cd4abc4e9b207df9892701645acc280178728070 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 10 Mar 2021 11:05:17 +0000 Subject: [PATCH 08/20] Disable crypto transaction profiling --- .../store/indexeddb-crypto-store-backend.js | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/crypto/store/indexeddb-crypto-store-backend.js b/src/crypto/store/indexeddb-crypto-store-backend.js index 6ecffe7be..c3203240f 100644 --- a/src/crypto/store/indexeddb-crypto-store-backend.js +++ b/src/crypto/store/indexeddb-crypto-store-backend.js @@ -20,6 +20,7 @@ import {logger} from '../../logger'; import * as utils from "../../utils"; export const VERSION = 9; +const PROFILE_TRANSACTIONS = false; /** * Implementation of a CryptoStore which is backed by an existing @@ -759,20 +760,26 @@ export class Backend { } doTxn(mode, stores, func, log = logger) { - const txnId = this._nextTxnId++; - const startTime = Date.now(); - const description = `${mode} crypto store transaction ${txnId} in ${stores}`; - log.debug(`Starting ${description}`); + let startTime; + let description; + if (PROFILE_TRANSACTIONS) { + const txnId = this._nextTxnId++; + startTime = Date.now(); + description = `${mode} crypto store transaction ${txnId} in ${stores}`; + log.debug(`Starting ${description}`); + } const txn = this._db.transaction(stores, mode); const promise = promiseifyTxn(txn); const result = func(txn); - promise.then(() => { - const elapsedTime = Date.now() - startTime; - log.debug(`Finished ${description}, took ${elapsedTime} ms`); - }, () => { - const elapsedTime = Date.now() - startTime; - log.error(`Failed ${description}, took ${elapsedTime} ms`); - }); + if (PROFILE_TRANSACTIONS) { + promise.then(() => { + const elapsedTime = Date.now() - startTime; + log.debug(`Finished ${description}, took ${elapsedTime} ms`); + }, () => { + const elapsedTime = Date.now() - startTime; + log.error(`Failed ${description}, took ${elapsedTime} ms`); + }); + } return promise.then(() => { return result; }); From 60fd3b07864a5dab58bfa08cadb9eda59f983c3a Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 10 Mar 2021 11:25:44 +0000 Subject: [PATCH 09/20] Remove extra space in log message --- src/store/indexeddb-local-backend.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/store/indexeddb-local-backend.js b/src/store/indexeddb-local-backend.js index d538e88f0..3a0af28b1 100644 --- a/src/store/indexeddb-local-backend.js +++ b/src/store/indexeddb-local-backend.js @@ -435,7 +435,7 @@ LocalIndexedDBStoreBackend.prototype = { * @return {Promise} Resolves if the data was persisted. */ _persistSyncData: function(nextBatch, roomsData, groupsData) { - logger.log("Persisting sync data up to ", nextBatch); + logger.log("Persisting sync data up to", nextBatch); return utils.promiseTry(() => { const txn = this.db.transaction(["sync"], "readwrite"); const store = txn.objectStore("sync"); From 1bb8c2d1a531bf170947495d42219e9f45967d15 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 10 Mar 2021 12:26:55 +0000 Subject: [PATCH 10/20] Remove detailed Olm session logging Now that we understand the Olm session deadlock, we shouldn't need this detailed per-session logging. Fixes https://github.com/vector-im/element-web/issues/16647 --- src/crypto/olmlib.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/crypto/olmlib.js b/src/crypto/olmlib.js index eb0d8a4a9..949df8001 100644 --- a/src/crypto/olmlib.js +++ b/src/crypto/olmlib.js @@ -213,9 +213,8 @@ export async function ensureOlmSessionsForDevices( // synchronous operation, as otherwise it is possible to have deadlocks // where multiple tasks wait indefinitely on another task to update some set // of common devices. - for (const [userId, devices] of Object.entries(devicesByUser)) { + for (const [, devices] of Object.entries(devicesByUser)) { for (const deviceInfo of devices) { - const deviceId = deviceInfo.deviceId; const key = deviceInfo.getIdentityKey(); if (key === olmDevice.deviceCurve25519Key) { @@ -224,15 +223,12 @@ export async function ensureOlmSessionsForDevices( continue; } - const forWhom = `for ${key} (${userId}:${deviceId})`; if (!olmDevice._sessionsInProgress[key]) { // pre-emptively mark the session as in-progress to avoid race // conditions. If we find that we already have a session, then // we'll resolve - log.debug(`Marking Olm session in progress ${forWhom}`); olmDevice._sessionsInProgress[key] = new Promise(resolve => { resolveSession[key] = (...args) => { - log.debug(`Resolved Olm session in progress ${forWhom}`); delete olmDevice._sessionsInProgress[key]; resolve(...args); }; @@ -266,11 +262,9 @@ export async function ensureOlmSessionsForDevices( } const forWhom = `for ${key} (${userId}:${deviceId})`; - log.debug(`Ensuring Olm session ${forWhom}`); const sessionId = await olmDevice.getSessionIdForDevice( key, resolveSession[key], log, ); - log.debug(`Got Olm session ${sessionId} ${forWhom}`); if (sessionId !== null && resolveSession[key]) { // we found a session, but we had marked the session as // in-progress, so resolve it now, which will unmark it and From 683092140dae152c3e3036c2e1b50aca136bc2e2 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Wed, 10 Mar 2021 12:32:07 +0000 Subject: [PATCH 11/20] Remove OTK claim timeout logging --- src/crypto/olmlib.js | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/crypto/olmlib.js b/src/crypto/olmlib.js index 949df8001..f1e487e97 100644 --- a/src/crypto/olmlib.js +++ b/src/crypto/olmlib.js @@ -293,18 +293,6 @@ export async function ensureOlmSessionsForDevices( const oneTimeKeyAlgorithm = "signed_curve25519"; let res; let taskDetail = `one-time keys for ${devicesWithoutSession.length} devices`; - // If your homeserver takes a nap here and never replies, this process - // would hang indefinitely. While that's easily fixed by setting a - // timeout on this request, let's first log whether that's the root - // cause we're seeing in practice. - // See also https://github.com/vector-im/element-web/issues/16194 - let otkTimeoutLogger; - // XXX: Perhaps there should be a default timeout? - if (otkTimeout) { - otkTimeoutLogger = setTimeout(() => { - log.error(`Homeserver never replied while claiming ${taskDetail}`); - }, otkTimeout); - } try { log.debug(`Claiming ${taskDetail}`); res = await baseApis.claimOneTimeKeys( @@ -317,8 +305,6 @@ export async function ensureOlmSessionsForDevices( } log.log(`Failed to claim ${taskDetail}`, e, devicesWithoutSession); throw e; - } finally { - clearTimeout(otkTimeoutLogger); } if (failedServers && "failures" in res) { From 13b6db8eb4a7860b14d71e556afcd80d7b0314af Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Wed, 10 Mar 2021 17:21:49 +0000 Subject: [PATCH 12/20] Prepare changelog for v9.9.0-rc.1 --- CHANGELOG.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b88da3c3d..3f5e840c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,52 @@ +Changes in [9.9.0-rc.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v9.9.0-rc.1) (2021-03-10) +========================================================================================================== +[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v9.8.0...v9.9.0-rc.1) + + * Remove detailed Olm session logging + [\#1638](https://github.com/matrix-org/matrix-js-sdk/pull/1638) + * Add space summary suggested only param + [\#1637](https://github.com/matrix-org/matrix-js-sdk/pull/1637) + * Check TURN servers periodically, and at start of calls + [\#1634](https://github.com/matrix-org/matrix-js-sdk/pull/1634) + * Support sending invite reasons + [\#1624](https://github.com/matrix-org/matrix-js-sdk/pull/1624) + * Bump elliptic from 6.5.3 to 6.5.4 + [\#1636](https://github.com/matrix-org/matrix-js-sdk/pull/1636) + * Add a function to get a room's MXC URI + [\#1635](https://github.com/matrix-org/matrix-js-sdk/pull/1635) + * Stop streams if the call has ended + [\#1633](https://github.com/matrix-org/matrix-js-sdk/pull/1633) + * Remove export keyword from global.d.ts + [\#1631](https://github.com/matrix-org/matrix-js-sdk/pull/1631) + * Fix IndexedDB store creation example + [\#1445](https://github.com/matrix-org/matrix-js-sdk/pull/1445) + * An attempt to cleanup how constraints are handled in calls + [\#1613](https://github.com/matrix-org/matrix-js-sdk/pull/1613) + * Extract display name patterns to constants + [\#1628](https://github.com/matrix-org/matrix-js-sdk/pull/1628) + * Bump pug-code-gen from 2.0.2 to 2.0.3 + [\#1630](https://github.com/matrix-org/matrix-js-sdk/pull/1630) + * Avoid deadlocks when ensuring Olm sessions for devices + [\#1627](https://github.com/matrix-org/matrix-js-sdk/pull/1627) + * Filter out edits from other senders in history + [\#1626](https://github.com/matrix-org/matrix-js-sdk/pull/1626) + * Fix ContentHelpers export + [\#1618](https://github.com/matrix-org/matrix-js-sdk/pull/1618) + * Add logging to in progress Olm sessions + [\#1621](https://github.com/matrix-org/matrix-js-sdk/pull/1621) + * Don't ignore ICE candidates received before offer/answer + [\#1623](https://github.com/matrix-org/matrix-js-sdk/pull/1623) + * Better handling of send failures on VoIP events + [\#1622](https://github.com/matrix-org/matrix-js-sdk/pull/1622) + * Log when turn creds expire + [\#1620](https://github.com/matrix-org/matrix-js-sdk/pull/1620) + * Initial Spaces [MSC1772] support + [\#1563](https://github.com/matrix-org/matrix-js-sdk/pull/1563) + * Add logging to crypto store transactions + [\#1617](https://github.com/matrix-org/matrix-js-sdk/pull/1617) + * Room helper for getting type and checking if it is a space room + [\#1610](https://github.com/matrix-org/matrix-js-sdk/pull/1610) + Changes in [9.8.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v9.8.0) (2021-03-01) ================================================================================================ [Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v9.8.0-rc.1...v9.8.0) From 0ffdf7c0f1063b867e205c6c446c736c49c6a4e3 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Wed, 10 Mar 2021 17:21:50 +0000 Subject: [PATCH 13/20] v9.9.0-rc.1 --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f9fafb132..c2201ac6c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-js-sdk", - "version": "9.8.0", + "version": "9.9.0-rc.1", "description": "Matrix Client-Server SDK for Javascript", "scripts": { "prepublishOnly": "yarn build", @@ -27,7 +27,7 @@ "keywords": [ "matrix-org" ], - "main": "./src/index.ts", + "main": "./lib/index.js", "browser": "./lib/browser-index.js", "matrix_src_main": "./src/index.ts", "matrix_src_browser": "./src/browser-index.js", @@ -95,5 +95,6 @@ }, "jest": { "testEnvironment": "node" - } + }, + "typings": "./lib/index.d.ts" } From 56ea4b8741e640f15e8dd04b8192ae1b4709d28e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Sat, 13 Mar 2021 15:03:36 +0100 Subject: [PATCH 14/20] Make selectDesktopCapturerSource param optional MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- src/webrtc/call.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index a9c8799cd..371b3036b 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -372,7 +372,7 @@ export class MatrixCall extends EventEmitter { async placeScreenSharingCall( remoteVideoElement: HTMLVideoElement, localVideoElement: HTMLVideoElement, - selectDesktopCapturerSource: () => Promise, + selectDesktopCapturerSource?: () => Promise, ) { logger.debug("placeScreenSharingCall"); this.checkForErrorListener(); From 9559b26310ae02e35112e166e6ccbcac85bdcf62 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Mon, 15 Mar 2021 14:31:57 +0000 Subject: [PATCH 15/20] Prepare changelog for v9.9.0 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f5e840c5..bdfc2363a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Changes in [9.9.0](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v9.9.0) (2021-03-15) +================================================================================================ +[Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v9.9.0-rc.1...v9.9.0) + + * No changes since rc.1 + Changes in [9.9.0-rc.1](https://github.com/matrix-org/matrix-js-sdk/releases/tag/v9.9.0-rc.1) (2021-03-10) ========================================================================================================== [Full Changelog](https://github.com/matrix-org/matrix-js-sdk/compare/v9.8.0...v9.9.0-rc.1) From 3ff517e76e62d8751acc4fc98e8e9a75953aca35 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Mon, 15 Mar 2021 14:31:58 +0000 Subject: [PATCH 16/20] v9.9.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c2201ac6c..5f96d8395 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-js-sdk", - "version": "9.9.0-rc.1", + "version": "9.9.0", "description": "Matrix Client-Server SDK for Javascript", "scripts": { "prepublishOnly": "yarn build", From cd38fb9b4c349eb31feac14e806e710bf6431b72 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Mon, 15 Mar 2021 14:34:56 +0000 Subject: [PATCH 17/20] Resetting package fields for development --- package.json | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 5f96d8395..c4b9e4047 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "keywords": [ "matrix-org" ], - "main": "./lib/index.js", + "main": "./src/index.ts", "browser": "./lib/browser-index.js", "matrix_src_main": "./src/index.ts", "matrix_src_browser": "./src/browser-index.js", @@ -95,6 +95,5 @@ }, "jest": { "testEnvironment": "node" - }, - "typings": "./lib/index.d.ts" + } } From 702e16e3df4d6a390836e2e5593e0e0981caabeb Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 16 Mar 2021 19:13:03 +0000 Subject: [PATCH 18/20] More VoIP connectivity fixes * Don't ignore other candidates when we see a null one (continue rather than return) * await on addICECandidate() * Don't add ice candidates until we've set a remote description * More & better logging --- src/webrtc/call.ts | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 371b3036b..5e06c7a81 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -541,6 +541,7 @@ export class MatrixCall extends EventEmitter { this.chooseOpponent(event); try { await this.peerConn.setRemoteDescription(invite.offer); + await this.addBufferedIceCandidates(); } catch (e) { logger.debug("Failed to set remote description", e); this.terminate(CallParty.Local, CallErrorCode.SetRemoteDescription, false); @@ -985,7 +986,7 @@ export class MatrixCall extends EventEmitter { private gotLocalIceCandidate = (event: RTCPeerConnectionIceEvent) => { if (event.candidate) { logger.debug( - "Got local ICE " + event.candidate.sdpMid + " candidate: " + + "Call " + this.callId + " got local ICE " + event.candidate.sdpMid + " candidate: " + event.candidate.candidate, ); @@ -1019,7 +1020,7 @@ export class MatrixCall extends EventEmitter { } }; - onRemoteIceCandidatesReceived(ev: MatrixEvent) { + async onRemoteIceCandidatesReceived(ev: MatrixEvent) { if (this.callHasEnded()) { //debuglog("Ignoring remote ICE candidate because call has ended"); return; @@ -1051,7 +1052,7 @@ export class MatrixCall extends EventEmitter { return; } - this.addIceCandidates(cands); + await this.addIceCandidates(cands); } /** @@ -1059,7 +1060,10 @@ export class MatrixCall extends EventEmitter { * @param {Object} msg */ async onAnswerReceived(event: MatrixEvent) { + logger.debug(`Got answer for call ID ${this.callId} from party ID ${event.getContent().party_id}`); + if (this.callHasEnded()) { + logger.debug(`Ignoring answer because call ID ${this.callId} has ended`); return; } @@ -1072,6 +1076,7 @@ export class MatrixCall extends EventEmitter { } this.chooseOpponent(event); + await this.addBufferedIceCandidates(); this.setState(CallState.Connecting); @@ -1520,7 +1525,10 @@ export class MatrixCall extends EventEmitter { } } - async transfer(targetUserId: string, targetRoomId?: string) { + /* + * Transfers this call to another user + */ + async transfer(targetUserId: string) { // Fetch the target user's global profile info: their room avatar / displayname // could be different in whatever room we shae with them. const profileInfo = await this.client.getProfileInfo(targetUserId); @@ -1537,11 +1545,16 @@ export class MatrixCall extends EventEmitter { create_call: replacementId, } as MCallReplacesEvent; - if (targetRoomId) body.target_room = targetRoomId; - return this.sendVoipEvent(EventType.CallReplaces, body); } + /* + * Transfers this call to the target call, effectively 'joining' the + * two calls (so the remote parties on each call are connected together). + */ + async transferToCall(transferTargetCall?: MatrixCall) { + } + private async terminate(hangupParty: CallParty, hangupReason: CallErrorCode, shouldEmit: boolean) { if (this.callHasEnded()) return; @@ -1722,6 +1735,8 @@ export class MatrixCall extends EventEmitter { // I choo-choo-choose you const msg = ev.getContent(); + logger.debug(`Choosing party ID ${msg.party_id} for call ID ${this.callId}`); + this.opponentVersion = msg.version; if (this.opponentVersion === 0) { // set to null to indicate that we've chosen an opponent, but because @@ -1735,30 +1750,32 @@ export class MatrixCall extends EventEmitter { } this.opponentCaps = msg.capabilities || {}; this.opponentMember = ev.sender; + } + private async addBufferedIceCandidates() { const bufferedCands = this.remoteCandidateBuffer.get(this.opponentPartyId); if (bufferedCands) { logger.info(`Adding ${bufferedCands.length} buffered candidates for opponent ${this.opponentPartyId}`); - this.addIceCandidates(bufferedCands); + await this.addIceCandidates(bufferedCands); } this.remoteCandidateBuffer = null; } - private addIceCandidates(cands: RTCIceCandidate[]) { + private async addIceCandidates(cands: RTCIceCandidate[]) { for (const cand of cands) { if ( (cand.sdpMid === null || cand.sdpMid === undefined) && (cand.sdpMLineIndex === null || cand.sdpMLineIndex === undefined) ) { logger.debug("Ignoring remote ICE candidate with no sdpMid or sdpMLineIndex"); - return; + continue; } - logger.debug("Got remote ICE " + cand.sdpMid + " candidate: " + cand.candidate); + logger.debug("Call " + this.callId + " got remote ICE " + cand.sdpMid + " candidate: " + cand.candidate); try { - this.peerConn.addIceCandidate(cand); + await this.peerConn.addIceCandidate(cand); } catch (err) { if (!this.ignoreOffer) { - logger.info("Failed to add remore ICE candidate", err); + logger.info("Failed to add remote ICE candidate", err); } } } From d208a7fc5f04c9aa93a9031c58961737347cd397 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 16 Mar 2021 19:17:04 +0000 Subject: [PATCH 19/20] Remove unintentionally committed stuff --- src/webrtc/call.ts | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 5e06c7a81..94a325d8a 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -1528,7 +1528,7 @@ export class MatrixCall extends EventEmitter { /* * Transfers this call to another user */ - async transfer(targetUserId: string) { + async transfer(targetUserId: string, targetRoomId?: string) { // Fetch the target user's global profile info: their room avatar / displayname // could be different in whatever room we shae with them. const profileInfo = await this.client.getProfileInfo(targetUserId); @@ -1545,14 +1545,9 @@ export class MatrixCall extends EventEmitter { create_call: replacementId, } as MCallReplacesEvent; - return this.sendVoipEvent(EventType.CallReplaces, body); - } + if (targetRoomId) body.target_room = targetRoomId; - /* - * Transfers this call to the target call, effectively 'joining' the - * two calls (so the remote parties on each call are connected together). - */ - async transferToCall(transferTargetCall?: MatrixCall) { + return this.sendVoipEvent(EventType.CallReplaces, body); } private async terminate(hangupParty: CallParty, hangupReason: CallErrorCode, shouldEmit: boolean) { From 27d75a269fbd974da8efc9bb11cbeabf530ee27c Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 16 Mar 2021 19:18:45 +0000 Subject: [PATCH 20/20] unintentional comment --- src/webrtc/call.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/webrtc/call.ts b/src/webrtc/call.ts index 94a325d8a..68d42cfa2 100644 --- a/src/webrtc/call.ts +++ b/src/webrtc/call.ts @@ -1525,9 +1525,6 @@ export class MatrixCall extends EventEmitter { } } - /* - * Transfers this call to another user - */ async transfer(targetUserId: string, targetRoomId?: string) { // Fetch the target user's global profile info: their room avatar / displayname // could be different in whatever room we shae with them.