matrix-js-sdk 42.1.0 → 42.2.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/lib/@types/beacon.d.ts +1 -1
  2. package/lib/@types/beacon.js +1 -1
  3. package/lib/@types/beacon.js.map +1 -1
  4. package/lib/@types/extensible_events.d.ts.map +1 -1
  5. package/lib/@types/extensible_events.js.map +1 -1
  6. package/lib/autodiscovery.js.map +1 -1
  7. package/lib/browser-index.js.map +1 -1
  8. package/lib/client.d.ts +12 -5
  9. package/lib/client.d.ts.map +1 -1
  10. package/lib/client.js +23 -26
  11. package/lib/client.js.map +1 -1
  12. package/lib/common-crypto/key-passphrase.js +1 -1
  13. package/lib/common-crypto/key-passphrase.js.map +1 -1
  14. package/lib/crypto/store/indexeddb-crypto-store-backend.js +2 -1
  15. package/lib/crypto/store/indexeddb-crypto-store-backend.js.map +1 -1
  16. package/lib/crypto/store/indexeddb-crypto-store.d.ts.map +1 -1
  17. package/lib/crypto/store/indexeddb-crypto-store.js +1 -1
  18. package/lib/crypto/store/indexeddb-crypto-store.js.map +1 -1
  19. package/lib/crypto/store/memory-crypto-store.js.map +1 -1
  20. package/lib/embedded.d.ts +16 -0
  21. package/lib/embedded.d.ts.map +1 -1
  22. package/lib/embedded.js +19 -6
  23. package/lib/embedded.js.map +1 -1
  24. package/lib/matrixrtc/MatrixRTCSession.js.map +1 -1
  25. package/lib/matrixrtc/MembershipManager.js.map +1 -1
  26. package/lib/matrixrtc/MembershipManagerActionScheduler.js.map +1 -1
  27. package/lib/matrixrtc/RTCEncryptionManager.js.map +1 -1
  28. package/lib/matrixrtc/ToDeviceKeyTransport.js.map +1 -1
  29. package/lib/matrixrtc/membershipData/rtc.js.map +1 -1
  30. package/lib/matrixrtc/utils.d.ts +0 -1
  31. package/lib/matrixrtc/utils.d.ts.map +1 -1
  32. package/lib/matrixrtc/utils.js +0 -1
  33. package/lib/matrixrtc/utils.js.map +1 -1
  34. package/lib/models/event-timeline-set.js +3 -3
  35. package/lib/models/event-timeline-set.js.map +1 -1
  36. package/lib/models/event.d.ts.map +1 -1
  37. package/lib/models/event.js.map +1 -1
  38. package/lib/models/invites-ignorer.js.map +1 -1
  39. package/lib/models/poll.js.map +1 -1
  40. package/lib/models/read-receipt.js.map +1 -1
  41. package/lib/models/relations-container.d.ts +10 -0
  42. package/lib/models/relations-container.d.ts.map +1 -1
  43. package/lib/models/relations-container.js +39 -17
  44. package/lib/models/relations-container.js.map +1 -1
  45. package/lib/models/relations.js +1 -1
  46. package/lib/models/relations.js.map +1 -1
  47. package/lib/models/room.js +3 -3
  48. package/lib/models/room.js.map +1 -1
  49. package/lib/models/thread.d.ts +3 -0
  50. package/lib/models/thread.d.ts.map +1 -1
  51. package/lib/models/thread.js +36 -3
  52. package/lib/models/thread.js.map +1 -1
  53. package/lib/oauth/authorize.js +1 -1
  54. package/lib/oauth/authorize.js.map +1 -1
  55. package/lib/oauth/index.js +4 -2
  56. package/lib/oauth/index.js.map +1 -1
  57. package/lib/pollingCachedValue.d.ts +77 -0
  58. package/lib/pollingCachedValue.d.ts.map +1 -0
  59. package/lib/pollingCachedValue.js +160 -0
  60. package/lib/pollingCachedValue.js.map +1 -0
  61. package/lib/pushprocessor.js.map +1 -1
  62. package/lib/receipt-accumulator.d.ts.map +1 -1
  63. package/lib/receipt-accumulator.js.map +1 -1
  64. package/lib/rendezvous/MSC4108SignInWithQR.d.ts.map +1 -1
  65. package/lib/rendezvous/MSC4108SignInWithQR.js +2 -3
  66. package/lib/rendezvous/MSC4108SignInWithQR.js.map +1 -1
  67. package/lib/rtcTransportsCachedValue.d.ts +9 -0
  68. package/lib/rtcTransportsCachedValue.d.ts.map +1 -0
  69. package/lib/rtcTransportsCachedValue.js +38 -0
  70. package/lib/rtcTransportsCachedValue.js.map +1 -0
  71. package/lib/rust-crypto/PerSessionKeyBackupDownloader.js.map +1 -1
  72. package/lib/rust-crypto/backup.d.ts +2 -3
  73. package/lib/rust-crypto/backup.d.ts.map +1 -1
  74. package/lib/rust-crypto/backup.js.map +1 -1
  75. package/lib/rust-crypto/index.d.ts +10 -4
  76. package/lib/rust-crypto/index.d.ts.map +1 -1
  77. package/lib/rust-crypto/index.js +20 -3
  78. package/lib/rust-crypto/index.js.map +1 -1
  79. package/lib/rust-crypto/libolm_migration.js.map +1 -1
  80. package/lib/rust-crypto/rust-crypto.js.map +1 -1
  81. package/lib/sliding-sync-sdk.js.map +1 -1
  82. package/lib/sliding-sync.js.map +1 -1
  83. package/lib/store/indexeddb-local-backend.js +1 -1
  84. package/lib/store/indexeddb-local-backend.js.map +1 -1
  85. package/lib/store/indexeddb-store-worker.d.ts.map +1 -1
  86. package/lib/store/indexeddb-store-worker.js +1 -0
  87. package/lib/store/indexeddb-store-worker.js.map +1 -1
  88. package/lib/sync.d.ts.map +1 -1
  89. package/lib/sync.js.map +1 -1
  90. package/lib/utils.d.ts +1 -1
  91. package/lib/utils.d.ts.map +1 -1
  92. package/lib/utils.js +1 -0
  93. package/lib/utils.js.map +1 -1
  94. package/lib/webrtc/call.js.map +1 -1
  95. package/lib/webrtc/groupCall.js.map +1 -1
  96. package/lib/webrtc/mediaHandler.js.map +1 -1
  97. package/lib/webrtc/stats/callStatsReportGatherer.js.map +1 -1
  98. package/lib/webrtc/stats/transportStatsBuilder.js.map +1 -1
  99. package/lib/wellKnownCachedValue.d.ts +8 -0
  100. package/lib/wellKnownCachedValue.d.ts.map +1 -0
  101. package/lib/wellKnownCachedValue.js +34 -0
  102. package/lib/wellKnownCachedValue.js.map +1 -0
  103. package/package.json +4 -4
  104. package/src/@types/beacon.ts +1 -1
  105. package/src/@types/extensible_events.ts +3 -4
  106. package/src/autodiscovery.ts +2 -2
  107. package/src/browser-index.ts +1 -1
  108. package/src/client.ts +48 -40
  109. package/src/common-crypto/key-passphrase.ts +1 -1
  110. package/src/crypto/store/indexeddb-crypto-store-backend.ts +2 -1
  111. package/src/crypto/store/indexeddb-crypto-store.ts +1 -3
  112. package/src/crypto/store/memory-crypto-store.ts +1 -1
  113. package/src/embedded.ts +34 -11
  114. package/src/matrixrtc/MatrixRTCSession.ts +3 -3
  115. package/src/matrixrtc/MembershipManager.ts +1 -1
  116. package/src/matrixrtc/MembershipManagerActionScheduler.ts +1 -1
  117. package/src/matrixrtc/RTCEncryptionManager.ts +2 -2
  118. package/src/matrixrtc/ToDeviceKeyTransport.ts +3 -3
  119. package/src/matrixrtc/membershipData/rtc.ts +1 -1
  120. package/src/matrixrtc/utils.ts +0 -2
  121. package/src/models/event-timeline-set.ts +3 -3
  122. package/src/models/event.ts +7 -10
  123. package/src/models/invites-ignorer.ts +1 -1
  124. package/src/models/poll.ts +1 -1
  125. package/src/models/read-receipt.ts +1 -1
  126. package/src/models/relations-container.ts +55 -19
  127. package/src/models/relations.ts +1 -1
  128. package/src/models/room.ts +9 -9
  129. package/src/models/thread.ts +49 -4
  130. package/src/oauth/authorize.ts +1 -1
  131. package/src/oauth/index.ts +2 -2
  132. package/src/pollingCachedValue.ts +184 -0
  133. package/src/pushprocessor.ts +3 -3
  134. package/src/receipt-accumulator.ts +1 -2
  135. package/src/rendezvous/MSC4108SignInWithQR.ts +3 -4
  136. package/src/rtcTransportsCachedValue.ts +40 -0
  137. package/src/rust-crypto/PerSessionKeyBackupDownloader.ts +1 -1
  138. package/src/rust-crypto/backup.ts +1 -5
  139. package/src/rust-crypto/index.ts +23 -25
  140. package/src/rust-crypto/libolm_migration.ts +1 -1
  141. package/src/rust-crypto/rust-crypto.ts +3 -3
  142. package/src/sliding-sync-sdk.ts +1 -1
  143. package/src/sliding-sync.ts +1 -1
  144. package/src/store/indexeddb-local-backend.ts +1 -1
  145. package/src/store/indexeddb-store-worker.ts +1 -0
  146. package/src/sync.ts +4 -3
  147. package/src/utils.ts +3 -2
  148. package/src/webrtc/call.ts +6 -6
  149. package/src/webrtc/groupCall.ts +7 -7
  150. package/src/webrtc/mediaHandler.ts +1 -1
  151. package/src/webrtc/stats/callStatsReportGatherer.ts +2 -2
  152. package/src/webrtc/stats/transportStatsBuilder.ts +1 -1
  153. package/src/wellKnownCachedValue.ts +34 -0
package/lib/client.js CHANGED
@@ -33,7 +33,6 @@ import * as utils from "./utils.js";
33
33
  import { deepCompare, noUnsafeEventProps, replaceParam, safeSet, sleep } from "./utils.js";
34
34
  import { Direction, EventTimeline } from "./models/event-timeline.js";
35
35
  import { PushProcessor } from "./pushprocessor.js";
36
- import { AutoDiscovery } from "./autodiscovery.js";
37
36
  import { encodeUnpaddedBase64Url } from "./base64.js";
38
37
  import { TypedReEmitter } from "./ReEmitter.js";
39
38
  import { logger } from "./logger.js";
@@ -76,6 +75,8 @@ import { sha256 } from "./digest.js";
76
75
  import { OAuth2Error, isValidAuthMetadata } from "./oauth/index.js";
77
76
  import { UnsupportedDelayedEventsEndpointError, UnsupportedStickyEventsEndpointError } from "./errors.js";
78
77
  import { RetentionPolicyService } from "./retentionPolicy.js";
78
+ import { createRtcTransportsCachedValue } from "./rtcTransportsCachedValue.js";
79
+ import { createWellKnownCachedValue } from "./wellKnownCachedValue.js";
79
80
  const SCROLLBACK_DELAY_MS = 3000;
80
81
  const TURN_CHECK_INTERVAL = 10 * 60 * 1000; // poll for turn credentials every 10 minutes
81
82
 
@@ -307,6 +308,7 @@ export let ClientEvent = /*#__PURE__*/function (ClientEvent) {
307
308
  ClientEvent["TurnServers"] = "turnServers";
308
309
  ClientEvent["TurnServersError"] = "turnServers.error";
309
310
  ClientEvent["UserProfileUpdate"] = "userProfileUpdate";
311
+ ClientEvent["RtcTransportsUpdated"] = "rtcTransportsUpdated";
310
312
  return ClientEvent;
311
313
  }({});
312
314
  const SSO_ACTION_PARAM = new UnstableValue("action", "org.matrix.msc3824.action");
@@ -400,7 +402,6 @@ export class MatrixClient extends TypedEventEmitter {
400
402
  _defineProperty(this, "syncLeftRoomsPromise", void 0);
401
403
  _defineProperty(this, "syncedLeftRooms", false);
402
404
  _defineProperty(this, "clientOpts", void 0);
403
- _defineProperty(this, "clientWellKnownIntervalID", void 0);
404
405
  _defineProperty(this, "canResetTimelineCallback", void 0);
405
406
  _defineProperty(this, "canSupport", new Map());
406
407
  // The pushprocessor caches useful things, so keep one and re-use it
@@ -408,8 +409,6 @@ export class MatrixClient extends TypedEventEmitter {
408
409
  // Promise to a response of the server's /versions response
409
410
  // TODO: This should expire: https://github.com/matrix-org/matrix-js-sdk/issues/1020
410
411
  _defineProperty(this, "serverVersionsPromise", void 0);
411
- _defineProperty(this, "clientWellKnown", void 0);
412
- _defineProperty(this, "clientWellKnownPromise", void 0);
413
412
  _defineProperty(this, "turnServers", []);
414
413
  _defineProperty(this, "turnServersExpiry", 0);
415
414
  _defineProperty(this, "checkTurnServersIntervalID", void 0);
@@ -432,6 +431,8 @@ export class MatrixClient extends TypedEventEmitter {
432
431
  _defineProperty(this, "serverCapabilitiesService", void 0);
433
432
  _defineProperty(this, "retentionPolicyService", void 0);
434
433
  _defineProperty(this, "_unstable_shouldApplyMessageRetention", void 0);
434
+ _defineProperty(this, "cachedRtcTransports", void 0);
435
+ _defineProperty(this, "cachedWellKnown", void 0);
435
436
  _defineProperty(this, "startCallEventHandler", () => {
436
437
  if (this.isInitialSyncComplete()) {
437
438
  if (supportsMatrixCall()) {
@@ -562,6 +563,8 @@ export class MatrixClient extends TypedEventEmitter {
562
563
 
563
564
  // having lots of event listeners is not unusual. 0 means "unlimited".
564
565
  this.setMaxListeners(0);
566
+ this.cachedRtcTransports = createRtcTransportsCachedValue(this, this.logger);
567
+ this.cachedWellKnown = createWellKnownCachedValue(this, this.logger);
565
568
  }
566
569
  set store(newStore) {
567
570
  this._store = newStore;
@@ -628,17 +631,13 @@ export class MatrixClient extends TypedEventEmitter {
628
631
  this.syncApi = new SyncApi(this, this.clientOpts, this.buildSyncApiOptions());
629
632
  }
630
633
  this.syncApi.sync().catch(e => this.logger.info("Sync startup aborted with an error:", e));
631
- if (this.clientOpts.clientWellKnownPollPeriod !== undefined) {
632
- this.clientWellKnownIntervalID = setInterval(() => {
633
- void this.fetchClientWellKnown();
634
- }, 1000 * this.clientOpts.clientWellKnownPollPeriod);
635
- void this.fetchClientWellKnown();
636
- }
634
+ this.cachedWellKnown.start(this.clientOpts.clientWellKnownPollPeriod !== undefined ? 1000 * this.clientOpts.clientWellKnownPollPeriod : undefined);
637
635
  this.toDeviceMessageQueue.start();
638
636
  this.serverCapabilitiesService.start();
639
637
  if (this._unstable_shouldApplyMessageRetention) {
640
638
  this.retentionPolicyService?.start();
641
639
  }
640
+ this.cachedRtcTransports.start();
642
641
  }
643
642
 
644
643
  /**
@@ -678,12 +677,11 @@ export class MatrixClient extends TypedEventEmitter {
678
677
  this.groupCallEventHandler = undefined;
679
678
  globalThis.clearInterval(this.checkTurnServersIntervalID);
680
679
  this.checkTurnServersIntervalID = undefined;
681
- if (this.clientWellKnownIntervalID !== undefined) {
682
- globalThis.clearInterval(this.clientWellKnownIntervalID);
683
- }
684
680
  this.toDeviceMessageQueue.stop();
685
681
  this.matrixRTC.stop();
686
682
  this.serverCapabilitiesService.stop();
683
+ this.cachedRtcTransports.stop();
684
+ this.cachedWellKnown.stop();
687
685
  }
688
686
 
689
687
  /**
@@ -1044,6 +1042,11 @@ export class MatrixClient extends TypedEventEmitter {
1044
1042
  * @param args.storagePassword - An alternative to `storageKey`. A password which will be used to derive a key to
1045
1043
  * encrypt the store with. Deriving a key from a password is (deliberately) a slow operation, so prefer
1046
1044
  * to pass a `storageKey` directly where possible.
1045
+ * @param args.caCertsPem - Optional PEM-formatted string that provides CA certificates. These will be used to check
1046
+ * X.509 signatures on user identities. Any user identity that has a valid signature according to the supplied
1047
+ * CAs will be considered verified, without any manual verification taking place.
1048
+ *
1049
+ * NOTE: this is an unspecified extension to Matrix. Applications should exercise caution when using it.
1047
1050
  *
1048
1051
  * @returns a Promise which will resolve when the crypto layer has been
1049
1052
  * successfully initialised.
@@ -1081,7 +1084,8 @@ export class MatrixClient extends TypedEventEmitter {
1081
1084
  legacyMigrationProgressListener: (progress, total) => {
1082
1085
  this.emit(CryptoEvent.LegacyCryptoStoreMigrationProgress, progress, total);
1083
1086
  },
1084
- enableEncryptedStateEvents: this.enableEncryptedStateEvents
1087
+ enableEncryptedStateEvents: this.enableEncryptedStateEvents,
1088
+ caCertsPem: args.caCertsPem
1085
1089
  });
1086
1090
  rustCrypto.setSupportedVerificationMethods(this.verificationMethods);
1087
1091
  this.cryptoBackend = rustCrypto;
@@ -4398,21 +4402,15 @@ export class MatrixClient extends TypedEventEmitter {
4398
4402
  prefix: ""
4399
4403
  });
4400
4404
  }
4401
- async fetchClientWellKnown() {
4402
- // `getRawClientConfig` does not throw or reject on network errors, instead
4403
- // it absorbs errors and returns `{}`.
4404
- this.clientWellKnownPromise = AutoDiscovery.getRawClientConfig(this.getDomain() ?? undefined);
4405
- this.clientWellKnown = await this.clientWellKnownPromise;
4406
- this.emit(ClientEvent.ClientWellKnown, this.clientWellKnown);
4407
- }
4408
4405
  getClientWellKnown() {
4409
- return this.clientWellKnown;
4406
+ return this.cachedWellKnown.get();
4410
4407
  }
4411
- waitForClientWellKnown() {
4408
+ async waitForClientWellKnown() {
4412
4409
  if (!this.clientRunning) {
4413
4410
  throw new Error("Client is not running");
4414
4411
  }
4415
- return this.clientWellKnownPromise;
4412
+ const wellKnown = await this.cachedWellKnown.wait();
4413
+ return wellKnown;
4416
4414
  }
4417
4415
 
4418
4416
  /**
@@ -5239,8 +5237,7 @@ export class MatrixClient extends TypedEventEmitter {
5239
5237
  room_id: roomId,
5240
5238
  type: eventType,
5241
5239
  state_key: stateKey,
5242
- // Cast safety: StateEvents[K] is a stronger bound than IContent, which has [key: string]: any
5243
- content: content
5240
+ content
5244
5241
  });
5245
5242
  await this.encryptStateEventIfNeeded(event, room ?? undefined);
5246
5243
  const pathParams = {