@textrp/briij-js-sdk 41.0.1 → 43.0.0
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.
- package/CHANGELOG.md +14 -1
- package/LICENSE +177 -177
- package/README.md +85 -3
- package/lib/@types/AESEncryptedSecretStoragePayload.js.map +1 -1
- package/lib/@types/IIdentityServerProvider.js.map +1 -1
- package/lib/@types/PushRules.js +14 -14
- package/lib/@types/PushRules.js.map +1 -1
- package/lib/@types/another-json.d.js.map +1 -1
- package/lib/@types/auth.d.ts +72 -1
- package/lib/@types/auth.d.ts.map +1 -1
- package/lib/@types/auth.js +57 -54
- package/lib/@types/auth.js.map +1 -1
- package/lib/@types/beacon.js +100 -100
- package/lib/@types/beacon.js.map +1 -1
- package/lib/@types/common.js.map +1 -1
- package/lib/@types/crypto.js.map +1 -1
- package/lib/@types/event.d.ts +59 -0
- package/lib/@types/event.d.ts.map +1 -1
- package/lib/@types/event.js +105 -102
- package/lib/@types/event.js.map +1 -1
- package/lib/@types/events.js.map +1 -1
- package/lib/@types/extensible_events.js +53 -53
- package/lib/@types/extensible_events.js.map +1 -1
- package/lib/@types/local_notifications.js.map +1 -1
- package/lib/@types/location.js +41 -41
- package/lib/@types/location.js.map +1 -1
- package/lib/@types/matrix-sdk-crypto-wasm.d.js.map +1 -1
- package/lib/@types/media.js.map +1 -1
- package/lib/@types/membership.js +39 -39
- package/lib/@types/membership.js.map +1 -1
- package/lib/@types/partials.js +25 -25
- package/lib/@types/partials.js.map +1 -1
- package/lib/@types/polls.js +46 -46
- package/lib/@types/polls.js.map +1 -1
- package/lib/@types/read_receipts.js +14 -14
- package/lib/@types/read_receipts.js.map +1 -1
- package/lib/@types/registration.js.map +1 -1
- package/lib/@types/search.js +14 -14
- package/lib/@types/search.js.map +1 -1
- package/lib/@types/signed.js.map +1 -1
- package/lib/@types/spaces.js.map +1 -1
- package/lib/@types/state_events.js.map +1 -1
- package/lib/@types/synapse.js.map +1 -1
- package/lib/@types/sync.js +18 -18
- package/lib/@types/sync.js.map +1 -1
- package/lib/@types/threepids.js +14 -14
- package/lib/@types/threepids.js.map +1 -1
- package/lib/@types/topic.js +47 -47
- package/lib/@types/topic.js.map +1 -1
- package/lib/@types/uia.js.map +1 -1
- package/lib/NamespacedValue.js +20 -20
- package/lib/NamespacedValue.js.map +1 -1
- package/lib/ReEmitter.js +16 -16
- package/lib/ReEmitter.js.map +1 -1
- package/lib/base64.js +32 -32
- package/lib/base64.js.map +1 -1
- package/lib/briij.d.ts +4 -0
- package/lib/briij.d.ts.map +1 -1
- package/lib/briij.js +4 -0
- package/lib/briij.js.map +1 -1
- package/lib/client.d.ts +48 -1
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +262 -108
- package/lib/client.js.map +1 -1
- package/lib/common-crypto/key-passphrase.js +19 -19
- package/lib/common-crypto/key-passphrase.js.map +1 -1
- package/lib/content-helpers.js +57 -57
- package/lib/content-helpers.js.map +1 -1
- package/lib/content-repo.js +36 -36
- package/lib/content-repo.js.map +1 -1
- package/lib/crypto/store/base.js +69 -69
- package/lib/crypto/store/base.js.map +1 -1
- package/lib/crypto/store/indexeddb-crypto-store-backend.js +58 -58
- package/lib/crypto/store/indexeddb-crypto-store-backend.js.map +1 -1
- package/lib/crypto/store/indexeddb-crypto-store.js +193 -193
- package/lib/crypto/store/indexeddb-crypto-store.js.map +1 -1
- package/lib/crypto/store/localStorage-crypto-store.js +72 -72
- package/lib/crypto/store/localStorage-crypto-store.js.map +1 -1
- package/lib/crypto/store/memory-crypto-store.js +74 -74
- package/lib/crypto/store/memory-crypto-store.js.map +1 -1
- package/lib/crypto-api/CryptoEventHandlerMap.js.map +1 -1
- package/lib/crypto-api/key-passphrase.js +22 -22
- package/lib/crypto-api/key-passphrase.js.map +1 -1
- package/lib/crypto-api/keybackup.js.map +1 -1
- package/lib/crypto-api/recovery-key.js +20 -20
- package/lib/crypto-api/recovery-key.js.map +1 -1
- package/lib/digest.js +21 -21
- package/lib/digest.js.map +1 -1
- package/lib/extensible_events_v1/ExtensibleEvent.js +39 -39
- package/lib/extensible_events_v1/ExtensibleEvent.js.map +1 -1
- package/lib/extensible_events_v1/InvalidEventError.js +16 -16
- package/lib/extensible_events_v1/InvalidEventError.js.map +1 -1
- package/lib/extensible_events_v1/MessageEvent.js +39 -39
- package/lib/extensible_events_v1/MessageEvent.js.map +1 -1
- package/lib/extensible_events_v1/PollEndEvent.js +29 -29
- package/lib/extensible_events_v1/PollEndEvent.js.map +1 -1
- package/lib/extensible_events_v1/PollResponseEvent.js +39 -39
- package/lib/extensible_events_v1/PollResponseEvent.js.map +1 -1
- package/lib/extensible_events_v1/PollStartEvent.js +52 -52
- package/lib/extensible_events_v1/PollStartEvent.js.map +1 -1
- package/lib/extensible_events_v1/utilities.js +22 -22
- package/lib/extensible_events_v1/utilities.js.map +1 -1
- package/lib/feature.js +16 -16
- package/lib/feature.js.map +1 -1
- package/lib/http-api/method.js +14 -14
- package/lib/http-api/method.js.map +1 -1
- package/lib/http-api/prefix.js +26 -26
- package/lib/http-api/prefix.js.map +1 -1
- package/lib/indexeddb-helpers.js +21 -21
- package/lib/indexeddb-helpers.js.map +1 -1
- package/lib/indexeddb-worker.js +18 -18
- package/lib/indexeddb-worker.js.map +1 -1
- package/lib/matrixrtc/IKeyTransport.js +17 -17
- package/lib/matrixrtc/IKeyTransport.js.map +1 -1
- package/lib/matrixrtc/IMembershipManager.js +27 -27
- package/lib/matrixrtc/IMembershipManager.js.map +1 -1
- package/lib/matrixrtc/LivekitTransport.js +19 -19
- package/lib/matrixrtc/LivekitTransport.js.map +1 -1
- package/lib/matrixrtc/index.js +14 -14
- package/lib/matrixrtc/index.js.map +1 -1
- package/lib/matrixrtc/utils.js +27 -27
- package/lib/matrixrtc/utils.js.map +1 -1
- package/lib/models/ToDeviceMessage.js.map +1 -1
- package/lib/models/device.js +24 -24
- package/lib/models/device.js.map +1 -1
- package/lib/models/event-status.js +17 -17
- package/lib/models/event-status.js.map +1 -1
- package/lib/models/invites-ignorer-types.js +25 -25
- package/lib/models/invites-ignorer-types.js.map +1 -1
- package/lib/models/profile-keys.js +26 -26
- package/lib/models/profile-keys.js.map +1 -1
- package/lib/models/room-summary.js +26 -26
- package/lib/models/room-summary.js.map +1 -1
- package/lib/models/search-result.js +22 -22
- package/lib/models/search-result.js.map +1 -1
- package/lib/models/typed-event-emitter.js +122 -122
- package/lib/models/typed-event-emitter.js.map +1 -1
- package/lib/oidc/authorize.js +76 -76
- package/lib/oidc/authorize.js.map +1 -1
- package/lib/oidc/error.js +17 -17
- package/lib/oidc/error.js.map +1 -1
- package/lib/oidc/index.js +17 -17
- package/lib/oidc/index.js.map +1 -1
- package/lib/oidc/register.js +41 -41
- package/lib/oidc/register.js.map +1 -1
- package/lib/oidc/tokenRefresher.js +51 -51
- package/lib/oidc/tokenRefresher.js.map +1 -1
- package/lib/oidc/validate.js +59 -59
- package/lib/oidc/validate.js.map +1 -1
- package/lib/randomstring.js +35 -35
- package/lib/randomstring.js.map +1 -1
- package/lib/realtime-callbacks.js +39 -39
- package/lib/realtime-callbacks.js.map +1 -1
- package/lib/receipt-accumulator.js +44 -44
- package/lib/receipt-accumulator.js.map +1 -1
- package/lib/rendezvous/RendezvousChannel.js.map +1 -1
- package/lib/rendezvous/RendezvousCode.js.map +1 -1
- package/lib/rendezvous/RendezvousError.js +14 -14
- package/lib/rendezvous/RendezvousError.js.map +1 -1
- package/lib/rendezvous/RendezvousFailureReason.js +14 -14
- package/lib/rendezvous/RendezvousFailureReason.js.map +1 -1
- package/lib/rendezvous/RendezvousIntent.js +14 -14
- package/lib/rendezvous/RendezvousIntent.js.map +1 -1
- package/lib/rendezvous/RendezvousTransport.js.map +1 -1
- package/lib/rendezvous/channels/MSC4108SecureChannel.js +63 -63
- package/lib/rendezvous/channels/MSC4108SecureChannel.js.map +1 -1
- package/lib/rendezvous/channels/index.js +14 -14
- package/lib/rendezvous/channels/index.js.map +1 -1
- package/lib/rendezvous/index.js +14 -14
- package/lib/rendezvous/index.js.map +1 -1
- package/lib/rendezvous/transports/index.js +14 -14
- package/lib/rendezvous/transports/index.js.map +1 -1
- package/lib/rust-crypto/CrossSigningIdentity.js +29 -29
- package/lib/rust-crypto/CrossSigningIdentity.js.map +1 -1
- package/lib/rust-crypto/OutgoingRequestsManager.js +37 -37
- package/lib/rust-crypto/OutgoingRequestsManager.js.map +1 -1
- package/lib/rust-crypto/device-converter.js +30 -30
- package/lib/rust-crypto/device-converter.js.map +1 -1
- package/lib/rust-crypto/secret-storage.js +30 -30
- package/lib/rust-crypto/secret-storage.js.map +1 -1
- package/lib/service-types.js +14 -14
- package/lib/service-types.js.map +1 -1
- package/lib/store/local-storage-events-emitter.js +21 -21
- package/lib/store/local-storage-events-emitter.js.map +1 -1
- package/lib/sync-accumulator.js +50 -50
- package/lib/sync-accumulator.js.map +1 -1
- package/lib/thread-utils.js +20 -20
- package/lib/thread-utils.js.map +1 -1
- package/lib/types.js +34 -34
- package/lib/types.js.map +1 -1
- package/lib/utils/decryptAESSecretStorageItem.js +22 -22
- package/lib/utils/decryptAESSecretStorageItem.js.map +1 -1
- package/lib/utils/encryptAESSecretStorageItem.js +26 -26
- package/lib/utils/encryptAESSecretStorageItem.js.map +1 -1
- package/lib/utils/internal/deriveKeys.js +21 -21
- package/lib/utils/internal/deriveKeys.js.map +1 -1
- package/lib/utils/roomVersion.js +26 -26
- package/lib/utils/roomVersion.js.map +1 -1
- package/lib/version-support.js +26 -26
- package/lib/version-support.js.map +1 -1
- package/lib/wallet-recovery.d.ts +24 -0
- package/lib/wallet-recovery.d.ts.map +1 -0
- package/lib/wallet-recovery.js +232 -0
- package/lib/wallet-recovery.js.map +1 -0
- package/lib/webrtc/audioContext.js +24 -24
- package/lib/webrtc/audioContext.js.map +1 -1
- package/lib/webrtc/callEventTypes.js.map +1 -1
- package/lib/webrtc/stats/callFeedStatsReporter.js +14 -14
- package/lib/webrtc/stats/callFeedStatsReporter.js.map +1 -1
- package/lib/webrtc/stats/callStatsReportGatherer.js +14 -14
- package/lib/webrtc/stats/callStatsReportGatherer.js.map +1 -1
- package/lib/webrtc/stats/callStatsReportSummary.js.map +1 -1
- package/lib/webrtc/stats/connectionStats.js +14 -14
- package/lib/webrtc/stats/connectionStats.js.map +1 -1
- package/lib/webrtc/stats/connectionStatsBuilder.js +14 -14
- package/lib/webrtc/stats/connectionStatsBuilder.js.map +1 -1
- package/lib/webrtc/stats/connectionStatsReportBuilder.js +14 -14
- package/lib/webrtc/stats/connectionStatsReportBuilder.js.map +1 -1
- package/lib/webrtc/stats/groupCallStats.js +14 -14
- package/lib/webrtc/stats/groupCallStats.js.map +1 -1
- package/lib/webrtc/stats/media/mediaSsrcHandler.js +14 -14
- package/lib/webrtc/stats/media/mediaSsrcHandler.js.map +1 -1
- package/lib/webrtc/stats/media/mediaTrackHandler.js +14 -14
- package/lib/webrtc/stats/media/mediaTrackHandler.js.map +1 -1
- package/lib/webrtc/stats/media/mediaTrackStats.js +27 -27
- package/lib/webrtc/stats/media/mediaTrackStats.js.map +1 -1
- package/lib/webrtc/stats/media/mediaTrackStatsHandler.js +20 -20
- package/lib/webrtc/stats/media/mediaTrackStatsHandler.js.map +1 -1
- package/lib/webrtc/stats/statsReport.js +14 -14
- package/lib/webrtc/stats/statsReport.js.map +1 -1
- package/lib/webrtc/stats/statsReportEmitter.js +14 -14
- package/lib/webrtc/stats/statsReportEmitter.js.map +1 -1
- package/lib/webrtc/stats/trackStatsBuilder.js +4 -4
- package/lib/webrtc/stats/trackStatsBuilder.js.map +1 -1
- package/lib/webrtc/stats/transportStats.js.map +1 -1
- package/lib/webrtc/stats/transportStatsBuilder.js.map +1 -1
- package/lib/webrtc/stats/valueFormatter.js +11 -11
- package/lib/webrtc/stats/valueFormatter.js.map +1 -1
- package/lib/xrpl/identity.d.ts +28 -0
- package/lib/xrpl/identity.d.ts.map +1 -0
- package/lib/xrpl/identity.js +213 -0
- package/lib/xrpl/identity.js.map +1 -0
- package/lib/xrpl/trust.d.ts +8 -0
- package/lib/xrpl/trust.d.ts.map +1 -0
- package/lib/xrpl/trust.js +61 -0
- package/lib/xrpl/trust.js.map +1 -0
- package/lib/xrpl/verification.d.ts +26 -0
- package/lib/xrpl/verification.d.ts.map +1 -0
- package/lib/xrpl/verification.js +295 -0
- package/lib/xrpl/verification.js.map +1 -0
- package/package.json +130 -129
- package/src/@types/AESEncryptedSecretStoragePayload.ts +29 -29
- package/src/@types/IIdentityServerProvider.ts +24 -24
- package/src/@types/PushRules.ts +208 -208
- package/src/@types/another-json.d.ts +19 -19
- package/src/@types/auth.ts +340 -258
- package/src/@types/beacon.ts +140 -140
- package/src/@types/common.ts +24 -24
- package/src/@types/crypto.ts +71 -71
- package/src/@types/event.ts +508 -449
- package/src/@types/events.ts +119 -119
- package/src/@types/extensible_events.ts +147 -147
- package/src/@types/local_notifications.ts +19 -19
- package/src/@types/location.ts +92 -92
- package/src/@types/matrix-sdk-crypto-wasm.d.ts +39 -39
- package/src/@types/media.ts +245 -245
- package/src/@types/membership.ts +57 -57
- package/src/@types/partials.ts +103 -103
- package/src/@types/polls.ts +120 -120
- package/src/@types/read_receipts.ts +61 -61
- package/src/@types/registration.ts +102 -102
- package/src/@types/search.ts +119 -119
- package/src/@types/signed.ts +25 -25
- package/src/@types/spaces.ts +37 -37
- package/src/@types/state_events.ts +153 -153
- package/src/@types/synapse.ts +40 -40
- package/src/@types/sync.ts +27 -27
- package/src/@types/threepids.ts +29 -29
- package/src/@types/topic.ts +69 -69
- package/src/@types/uia.ts +24 -24
- package/src/NamespacedValue.ts +121 -121
- package/src/ReEmitter.ts +93 -93
- package/src/base64.ts +86 -86
- package/src/briij.ts +4 -0
- package/src/client.ts +183 -10
- package/src/common-crypto/README.md +4 -4
- package/src/common-crypto/key-passphrase.ts +43 -43
- package/src/content-helpers.ts +298 -298
- package/src/content-repo.ts +122 -122
- package/src/crypto/store/base.ts +388 -388
- package/src/crypto/store/indexeddb-crypto-store-backend.ts +655 -655
- package/src/crypto/store/indexeddb-crypto-store.ts +555 -555
- package/src/crypto/store/localStorage-crypto-store.ts +409 -409
- package/src/crypto/store/memory-crypto-store.ts +326 -326
- package/src/crypto-api/CryptoEventHandlerMap.ts +42 -42
- package/src/crypto-api/key-passphrase.ts +58 -58
- package/src/crypto-api/keybackup.ts +114 -114
- package/src/crypto-api/recovery-key.ts +69 -69
- package/src/digest.ts +34 -34
- package/src/extensible_events_v1/ExtensibleEvent.ts +58 -58
- package/src/extensible_events_v1/InvalidEventError.ts +24 -24
- package/src/extensible_events_v1/MessageEvent.ts +143 -143
- package/src/extensible_events_v1/PollEndEvent.ts +97 -97
- package/src/extensible_events_v1/PollResponseEvent.ts +148 -148
- package/src/extensible_events_v1/PollStartEvent.ts +207 -207
- package/src/extensible_events_v1/utilities.ts +35 -35
- package/src/feature.ts +88 -88
- package/src/http-api/method.ts +25 -25
- package/src/http-api/prefix.ts +48 -48
- package/src/indexeddb-helpers.ts +50 -50
- package/src/indexeddb-worker.ts +24 -24
- package/src/matrixrtc/IKeyTransport.ts +63 -63
- package/src/matrixrtc/IMembershipManager.ts +120 -120
- package/src/matrixrtc/LivekitTransport.ts +46 -46
- package/src/matrixrtc/index.ts +24 -24
- package/src/matrixrtc/utils.ts +71 -71
- package/src/models/ToDeviceMessage.ts +38 -38
- package/src/models/device.ts +85 -85
- package/src/models/event-status.ts +39 -39
- package/src/models/invites-ignorer-types.ts +58 -58
- package/src/models/profile-keys.ts +33 -33
- package/src/models/room-summary.ts +78 -78
- package/src/models/search-result.ts +57 -57
- package/src/models/typed-event-emitter.ts +246 -246
- package/src/oidc/authorize.ts +279 -279
- package/src/oidc/error.ts +33 -33
- package/src/oidc/index.ts +33 -33
- package/src/oidc/register.ts +163 -163
- package/src/oidc/tokenRefresher.ts +184 -184
- package/src/oidc/validate.ts +265 -265
- package/src/randomstring.ts +103 -103
- package/src/realtime-callbacks.ts +191 -191
- package/src/receipt-accumulator.ts +189 -189
- package/src/rendezvous/RendezvousChannel.ts +48 -48
- package/src/rendezvous/RendezvousCode.ts +25 -25
- package/src/rendezvous/RendezvousError.ts +26 -26
- package/src/rendezvous/RendezvousFailureReason.ts +49 -49
- package/src/rendezvous/RendezvousIntent.ts +20 -20
- package/src/rendezvous/RendezvousTransport.ts +58 -58
- package/src/rendezvous/channels/MSC4108SecureChannel.ts +270 -270
- package/src/rendezvous/channels/index.ts +17 -17
- package/src/rendezvous/index.ts +25 -25
- package/src/rendezvous/transports/index.ts +17 -17
- package/src/rust-crypto/CrossSigningIdentity.ts +195 -195
- package/src/rust-crypto/OutgoingRequestsManager.ts +170 -170
- package/src/rust-crypto/device-converter.ts +128 -128
- package/src/rust-crypto/secret-storage.ts +60 -60
- package/src/service-types.ts +20 -20
- package/src/store/local-storage-events-emitter.ts +46 -46
- package/src/sync-accumulator.ts +779 -779
- package/src/thread-utils.ts +31 -31
- package/src/types.ts +59 -59
- package/src/utils/decryptAESSecretStorageItem.ts +54 -54
- package/src/utils/encryptAESSecretStorageItem.ts +73 -73
- package/src/utils/internal/deriveKeys.ts +63 -63
- package/src/utils/roomVersion.ts +35 -35
- package/src/version-support.ts +50 -50
- package/src/wallet-recovery.ts +252 -0
- package/src/webrtc/audioContext.ts +44 -44
- package/src/webrtc/callEventTypes.ts +101 -101
- package/src/webrtc/stats/callFeedStatsReporter.ts +91 -91
- package/src/webrtc/stats/callStatsReportGatherer.ts +219 -219
- package/src/webrtc/stats/callStatsReportSummary.ts +30 -30
- package/src/webrtc/stats/connectionStats.ts +47 -47
- package/src/webrtc/stats/connectionStatsBuilder.ts +28 -28
- package/src/webrtc/stats/connectionStatsReportBuilder.ts +140 -140
- package/src/webrtc/stats/groupCallStats.ts +93 -93
- package/src/webrtc/stats/media/mediaSsrcHandler.ts +57 -57
- package/src/webrtc/stats/media/mediaTrackHandler.ts +70 -70
- package/src/webrtc/stats/media/mediaTrackStats.ts +176 -176
- package/src/webrtc/stats/media/mediaTrackStatsHandler.ts +90 -90
- package/src/webrtc/stats/statsReport.ts +133 -133
- package/src/webrtc/stats/statsReportEmitter.ts +49 -49
- package/src/webrtc/stats/trackStatsBuilder.ts +207 -207
- package/src/webrtc/stats/transportStats.ts +26 -26
- package/src/webrtc/stats/transportStatsBuilder.ts +48 -48
- package/src/webrtc/stats/valueFormatter.ts +27 -27
- package/src/xrpl/identity.ts +245 -0
- package/src/xrpl/trust.ts +64 -0
- package/src/xrpl/verification.ts +284 -0
package/lib/randomstring.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"randomstring.js","names":["encodeUnpaddedBase64Url","LOWERCASE","UPPERCASE","DIGITS","secureRandomBase64Url","len","key","Uint8Array","globalThis","crypto","getRandomValues","secureRandomString","secureRandomStringFrom","chars","length","Error","randomValueCutoff","entropyBuffer","Math","floor","entropyBufferPos","result","randomByte","push","join"],"sources":["../src/randomstring.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"file":"randomstring.js","names":["encodeUnpaddedBase64Url","LOWERCASE","UPPERCASE","DIGITS","secureRandomBase64Url","len","key","Uint8Array","globalThis","crypto","getRandomValues","secureRandomString","secureRandomStringFrom","chars","length","Error","randomValueCutoff","entropyBuffer","Math","floor","entropyBufferPos","result","randomByte","push","join"],"sources":["../src/randomstring.ts"],"sourcesContent":["/*\nCopyright 2018 New Vector Ltd\nCopyright 2019 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { encodeUnpaddedBase64Url } from \"./base64.ts\";\n\n/**\n * String representing the lowercase latin alphabet for use in {@link secureRandomStringFrom}\n * (can be combined with other such exports or other characters by appending strings)\n */\nexport const LOWERCASE = \"abcdefghijklmnopqrstuvwxyz\";\n\n/**\n * String representing the uppercase latin alphabet for use in secureRandomStringFrom\n * (can be combined with other such exports or other characters by appending strings)\n */\nexport const UPPERCASE = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\";\n\n/**\n * String representing the arabic numerals for use in secureRandomStringFrom\n * (can be combined with other such exports or other characters by appending strings)\n */\nexport const DIGITS = \"0123456789\";\n\nexport function secureRandomBase64Url(len: number): string {\n const key = new Uint8Array(len);\n globalThis.crypto.getRandomValues(key);\n\n return encodeUnpaddedBase64Url(key);\n}\n\n/**\n * Generates a random string of uppercase and lowercase letters plus digits using a\n * cryptographically secure random number generator.\n * @param len The length of the string to generate\n * @returns Random string of uppercase and lowercase letters plus digits of length `len`\n */\nexport function secureRandomString(len: number): string {\n return secureRandomStringFrom(len, UPPERCASE + LOWERCASE + DIGITS);\n}\n\n/**\n * Generate a cryptographically secure random string using characters given.\n *\n * @param len - The length of the string to generate (must be positive and less than 32768).\n * @param chars - The characters to use in the random string (between 2 and 256 characters long).\n * @returns Random string of characters of length `len`.\n */\nexport function secureRandomStringFrom(len: number, chars: string): string {\n // This is intended for latin strings so 256 possibilities should be more than enough and\n // means we can use random bytes, minimising the amount of entropy we need to ask for.\n if (chars.length < 2 || chars.length > 256) {\n throw new Error(\"Character set must be between 2 and 256 characters long\");\n }\n\n if (len < 1 || len > 32768) {\n throw new Error(\"Requested random string length must be between 1 and 32768\");\n }\n\n // We'll generate random unsigned bytes, so get the largest number less than 256 that is a multiple\n // of the length of the character set: We'll need to discard any random values that are larger than\n // this as we can't possibly map them onto the character set while keeping each character equally\n // likely to be chosen (minus 1 to convert to indices in a string). (Essentially, we're using a d8\n // to choose between 7 possibilities and re-rolling on an 8, keeping all 7 outcomes equally likely.)\n // Our random values must be strictly less than this\n const randomValueCutoff = 256 - (256 % chars.length);\n\n // Grab 30% more entropy than we need. This should be enough that we can discard the values that are\n // too high without having to go back and grab more unless we're super unlucky.\n const entropyBuffer = new Uint8Array(Math.floor(len * 1.3));\n // Mark all of this buffer as used to start with (we haven't populated it with entropy yet) so it will\n // be filled on the first iteration.\n let entropyBufferPos = entropyBuffer.length;\n\n const result = [];\n while (result.length < len) {\n if (entropyBufferPos === entropyBuffer.length) {\n globalThis.crypto.getRandomValues(entropyBuffer);\n entropyBufferPos = 0;\n }\n\n const randomByte = entropyBuffer[entropyBufferPos++];\n\n if (randomByte < randomValueCutoff) {\n result.push(chars[randomByte % chars.length]);\n }\n }\n\n return result.join(\"\");\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,uBAAuB,QAAQ,aAAa;;AAErD;AACA;AACA;AACA;AACA,OAAO,IAAMC,SAAS,GAAG,4BAA4B;;AAErD;AACA;AACA;AACA;AACA,OAAO,IAAMC,SAAS,GAAG,4BAA4B;;AAErD;AACA;AACA;AACA;AACA,OAAO,IAAMC,MAAM,GAAG,YAAY;AAElC,OAAO,SAASC,qBAAqBA,CAACC,GAAW,EAAU;EACvD,IAAMC,GAAG,GAAG,IAAIC,UAAU,CAACF,GAAG,CAAC;EAC/BG,UAAU,CAACC,MAAM,CAACC,eAAe,CAACJ,GAAG,CAAC;EAEtC,OAAON,uBAAuB,CAACM,GAAG,CAAC;AACvC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASK,kBAAkBA,CAACN,GAAW,EAAU;EACpD,OAAOO,sBAAsB,CAACP,GAAG,EAAEH,SAAS,GAAGD,SAAS,GAAGE,MAAM,CAAC;AACtE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASS,sBAAsBA,CAACP,GAAW,EAAEQ,KAAa,EAAU;EACvE;EACA;EACA,IAAIA,KAAK,CAACC,MAAM,GAAG,CAAC,IAAID,KAAK,CAACC,MAAM,GAAG,GAAG,EAAE;IACxC,MAAM,IAAIC,KAAK,CAAC,yDAAyD,CAAC;EAC9E;EAEA,IAAIV,GAAG,GAAG,CAAC,IAAIA,GAAG,GAAG,KAAK,EAAE;IACxB,MAAM,IAAIU,KAAK,CAAC,4DAA4D,CAAC;EACjF;;EAEA;EACA;EACA;EACA;EACA;EACA;EACA,IAAMC,iBAAiB,GAAG,GAAG,GAAI,GAAG,GAAGH,KAAK,CAACC,MAAO;;EAEpD;EACA;EACA,IAAMG,aAAa,GAAG,IAAIV,UAAU,CAACW,IAAI,CAACC,KAAK,CAACd,GAAG,GAAG,GAAG,CAAC,CAAC;EAC3D;EACA;EACA,IAAIe,gBAAgB,GAAGH,aAAa,CAACH,MAAM;EAE3C,IAAMO,MAAM,GAAG,EAAE;EACjB,OAAOA,MAAM,CAACP,MAAM,GAAGT,GAAG,EAAE;IACxB,IAAIe,gBAAgB,KAAKH,aAAa,CAACH,MAAM,EAAE;MAC3CN,UAAU,CAACC,MAAM,CAACC,eAAe,CAACO,aAAa,CAAC;MAChDG,gBAAgB,GAAG,CAAC;IACxB;IAEA,IAAME,UAAU,GAAGL,aAAa,CAACG,gBAAgB,EAAE,CAAC;IAEpD,IAAIE,UAAU,GAAGN,iBAAiB,EAAE;MAChCK,MAAM,CAACE,IAAI,CAACV,KAAK,CAACS,UAAU,GAAGT,KAAK,CAACC,MAAM,CAAC,CAAC;IACjD;EACJ;EAEA,OAAOO,MAAM,CAACG,IAAI,CAAC,EAAE,CAAC;AAC1B","ignoreList":[]}
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2016 OpenMarket Ltd
|
|
3
|
-
Copyright 2019 The Matrix.org Foundation C.I.C.
|
|
4
|
-
|
|
5
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
you may not use this file except in compliance with the License.
|
|
7
|
-
You may obtain a copy of the License at
|
|
8
|
-
|
|
9
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
|
|
11
|
-
Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
See the License for the specific language governing permissions and
|
|
15
|
-
limitations under the License.
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2016 OpenMarket Ltd
|
|
3
|
+
Copyright 2019 The Matrix.org Foundation C.I.C.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
/* A re-implementation of the javascript callback functions (setTimeout,
|
|
19
|
-
* clearTimeout; setInterval and clearInterval are not yet implemented) which
|
|
20
|
-
* try to improve handling of large clock jumps (as seen when
|
|
21
|
-
* suspending/resuming the system).
|
|
22
|
-
*
|
|
23
|
-
* In particular, if a timeout would have fired while the system was suspended,
|
|
24
|
-
* it will instead fire as soon as possible after resume.
|
|
18
|
+
/* A re-implementation of the javascript callback functions (setTimeout,
|
|
19
|
+
* clearTimeout; setInterval and clearInterval are not yet implemented) which
|
|
20
|
+
* try to improve handling of large clock jumps (as seen when
|
|
21
|
+
* suspending/resuming the system).
|
|
22
|
+
*
|
|
23
|
+
* In particular, if a timeout would have fired while the system was suspended,
|
|
24
|
+
* it will instead fire as soon as possible after resume.
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
27
|
import { logger } from "./logger.js";
|
|
@@ -43,15 +43,15 @@ var callbackList = [];
|
|
|
43
43
|
/* istanbul ignore next */
|
|
44
44
|
var debuglog = function debuglog() {};
|
|
45
45
|
|
|
46
|
-
/**
|
|
47
|
-
* reimplementation of window.setTimeout, which will call the callback if
|
|
48
|
-
* the wallclock time goes past the deadline.
|
|
49
|
-
*
|
|
50
|
-
* @param func - callback to be called after a delay
|
|
51
|
-
* @param delayMs - number of milliseconds to delay by
|
|
52
|
-
*
|
|
53
|
-
* @returns an identifier for this callback, which may be passed into
|
|
54
|
-
* clearTimeout later.
|
|
46
|
+
/**
|
|
47
|
+
* reimplementation of window.setTimeout, which will call the callback if
|
|
48
|
+
* the wallclock time goes past the deadline.
|
|
49
|
+
*
|
|
50
|
+
* @param func - callback to be called after a delay
|
|
51
|
+
* @param delayMs - number of milliseconds to delay by
|
|
52
|
+
*
|
|
53
|
+
* @returns an identifier for this callback, which may be passed into
|
|
54
|
+
* clearTimeout later.
|
|
55
55
|
*/
|
|
56
56
|
export function setTimeout(func, delayMs) {
|
|
57
57
|
for (var _len = arguments.length, params = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
@@ -80,10 +80,10 @@ export function setTimeout(func, delayMs) {
|
|
|
80
80
|
return key;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
/**
|
|
84
|
-
* reimplementation of window.clearTimeout, which mirrors setTimeout
|
|
85
|
-
*
|
|
86
|
-
* @param key - result from an earlier setTimeout call
|
|
83
|
+
/**
|
|
84
|
+
* reimplementation of window.clearTimeout, which mirrors setTimeout
|
|
85
|
+
*
|
|
86
|
+
* @param key - result from an earlier setTimeout call
|
|
87
87
|
*/
|
|
88
88
|
export function clearTimeout(key) {
|
|
89
89
|
if (callbackList.length === 0) {
|
|
@@ -151,10 +151,10 @@ function runCallbacks() {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
-
/* search in a sorted array.
|
|
155
|
-
*
|
|
156
|
-
* returns the index of the last element for which func returns
|
|
157
|
-
* greater than zero, or array.length if no such element exists.
|
|
154
|
+
/* search in a sorted array.
|
|
155
|
+
*
|
|
156
|
+
* returns the index of the last element for which func returns
|
|
157
|
+
* greater than zero, or array.length if no such element exists.
|
|
158
158
|
*/
|
|
159
159
|
function binarySearch(array, func) {
|
|
160
160
|
// min is inclusive, max exclusive.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"realtime-callbacks.js","names":["logger","TIMER_CHECK_PERIOD_MS","count","realCallbackKey","callbackList","debuglog","setTimeout","func","delayMs","_len","arguments","length","params","Array","_key","runAt","Date","now","key","data","idx","binarySearch","el","splice","scheduleRealCallback","clearTimeout","i","cb","globalThis","first","timestamp","Math","min","runCallbacks","callbacksToRun","shift","push","apply","e","error","array","max","mid","res"],"sources":["../src/realtime-callbacks.ts"],"sourcesContent":["/*\r\nCopyright 2016 OpenMarket Ltd\r\nCopyright 2019 The Matrix.org Foundation C.I.C.\r\n\r\nLicensed under the Apache License, Version 2.0 (the \"License\");\r\nyou may not use this file except in compliance with the License.\r\nYou may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nUnless required by applicable law or agreed to in writing, software\r\ndistributed under the License is distributed on an \"AS IS\" BASIS,\r\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\nSee the License for the specific language governing permissions and\r\nlimitations under the License.\r\n*/\r\n\r\n/* A re-implementation of the javascript callback functions (setTimeout,\r\n * clearTimeout; setInterval and clearInterval are not yet implemented) which\r\n * try to improve handling of large clock jumps (as seen when\r\n * suspending/resuming the system).\r\n *\r\n * In particular, if a timeout would have fired while the system was suspended,\r\n * it will instead fire as soon as possible after resume.\r\n */\r\n\r\nimport { logger } from \"./logger.ts\";\r\n\r\n// we schedule a callback at least this often, to check if we've missed out on\r\n// some wall-clock time due to being suspended.\r\nconst TIMER_CHECK_PERIOD_MS = 1000;\r\n\r\n// counter, for making up ids to return from setTimeout\r\nlet count = 0;\r\n\r\n// the key for our callback with the real globalThis.setTimeout\r\nlet realCallbackKey: NodeJS.Timeout | number;\r\n\r\ntype Callback = {\r\n runAt: number;\r\n func: (...params: any[]) => void;\r\n params: any[];\r\n key: number;\r\n};\r\n\r\n// a sorted list of the callbacks to be run.\r\n// each is an object with keys [runAt, func, params, key].\r\nconst callbackList: Callback[] = [];\r\n\r\n// var debuglog = logger.log.bind(logger);\r\n/* istanbul ignore next */\r\nconst debuglog = function (...params: any[]): void {};\r\n\r\n/**\r\n * reimplementation of window.setTimeout, which will call the callback if\r\n * the wallclock time goes past the deadline.\r\n *\r\n * @param func - callback to be called after a delay\r\n * @param delayMs - number of milliseconds to delay by\r\n *\r\n * @returns an identifier for this callback, which may be passed into\r\n * clearTimeout later.\r\n */\r\nexport function setTimeout(func: (...params: any[]) => void, delayMs: number, ...params: any[]): number {\r\n delayMs = delayMs || 0;\r\n if (delayMs < 0) {\r\n delayMs = 0;\r\n }\r\n\r\n const runAt = Date.now() + delayMs;\r\n const key = count++;\r\n debuglog(\"setTimeout: scheduling cb\", key, \"at\", runAt, \"(delay\", delayMs, \")\");\r\n const data = {\r\n runAt: runAt,\r\n func: func,\r\n params: params,\r\n key: key,\r\n };\r\n\r\n // figure out where it goes in the list\r\n const idx = binarySearch(callbackList, function (el) {\r\n return el.runAt - runAt;\r\n });\r\n\r\n callbackList.splice(idx, 0, data);\r\n scheduleRealCallback();\r\n\r\n return key;\r\n}\r\n\r\n/**\r\n * reimplementation of window.clearTimeout, which mirrors setTimeout\r\n *\r\n * @param key - result from an earlier setTimeout call\r\n */\r\nexport function clearTimeout(key: number): void {\r\n if (callbackList.length === 0) {\r\n return;\r\n }\r\n\r\n // remove the element from the list\r\n let i: number;\r\n for (i = 0; i < callbackList.length; i++) {\r\n const cb = callbackList[i];\r\n if (cb.key == key) {\r\n callbackList.splice(i, 1);\r\n break;\r\n }\r\n }\r\n\r\n // iff it was the first one in the list, reschedule our callback.\r\n if (i === 0) {\r\n scheduleRealCallback();\r\n }\r\n}\r\n\r\n// use the real globalThis.setTimeout to schedule a callback to runCallbacks.\r\nfunction scheduleRealCallback(): void {\r\n if (realCallbackKey) {\r\n globalThis.clearTimeout(realCallbackKey as NodeJS.Timeout);\r\n }\r\n\r\n const first = callbackList[0];\r\n\r\n if (!first) {\r\n debuglog(\"scheduleRealCallback: no more callbacks, not rescheduling\");\r\n return;\r\n }\r\n\r\n const timestamp = Date.now();\r\n const delayMs = Math.min(first.runAt - timestamp, TIMER_CHECK_PERIOD_MS);\r\n\r\n debuglog(\"scheduleRealCallback: now:\", timestamp, \"delay:\", delayMs);\r\n realCallbackKey = globalThis.setTimeout(runCallbacks, delayMs);\r\n}\r\n\r\nfunction runCallbacks(): void {\r\n const timestamp = Date.now();\r\n debuglog(\"runCallbacks: now:\", timestamp);\r\n\r\n // get the list of things to call\r\n const callbacksToRun: Callback[] = [];\r\n // eslint-disable-next-line\r\n while (true) {\r\n const first = callbackList[0];\r\n if (!first || first.runAt > timestamp) {\r\n break;\r\n }\r\n const cb = callbackList.shift()!;\r\n debuglog(\"runCallbacks: popping\", cb.key);\r\n callbacksToRun.push(cb);\r\n }\r\n\r\n // reschedule the real callback before running our functions, to\r\n // keep the codepaths the same whether or not our functions\r\n // register their own setTimeouts.\r\n scheduleRealCallback();\r\n\r\n for (const cb of callbacksToRun) {\r\n try {\r\n cb.func.apply(globalThis, cb.params);\r\n } catch (e) {\r\n logger.error(\"Uncaught exception in callback function\", e);\r\n }\r\n }\r\n}\r\n\r\n/* search in a sorted array.\r\n *\r\n * returns the index of the last element for which func returns\r\n * greater than zero, or array.length if no such element exists.\r\n */\r\nfunction binarySearch<T>(array: T[], func: (v: T) => number): number {\r\n // min is inclusive, max exclusive.\r\n let min = 0;\r\n let max = array.length;\r\n\r\n while (min < max) {\r\n const mid = (min + max) >> 1;\r\n const res = func(array[mid]);\r\n if (res > 0) {\r\n // the element at 'mid' is too big; set it as the new max.\r\n max = mid;\r\n } else {\r\n // the element at 'mid' is too small. 'min' is inclusive, so +1.\r\n min = mid + 1;\r\n }\r\n }\r\n // presumably, min==max now.\r\n return min;\r\n}\r\n"],"mappings":"AAAA;AACA;AACA;AACA;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GAAGC,GAAG;IACb,CAAC,MAAM;MACH;MACAV,GAAG,GAAGU,GAAG,GAAG,CAAC;IACjB;EACJ;EACA;EACA,OAAOV,GAAG;AACd","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"realtime-callbacks.js","names":["logger","TIMER_CHECK_PERIOD_MS","count","realCallbackKey","callbackList","debuglog","setTimeout","func","delayMs","_len","arguments","length","params","Array","_key","runAt","Date","now","key","data","idx","binarySearch","el","splice","scheduleRealCallback","clearTimeout","i","cb","globalThis","first","timestamp","Math","min","runCallbacks","callbacksToRun","shift","push","apply","e","error","array","max","mid","res"],"sources":["../src/realtime-callbacks.ts"],"sourcesContent":["/*\nCopyright 2016 OpenMarket Ltd\nCopyright 2019 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\n/* A re-implementation of the javascript callback functions (setTimeout,\n * clearTimeout; setInterval and clearInterval are not yet implemented) which\n * try to improve handling of large clock jumps (as seen when\n * suspending/resuming the system).\n *\n * In particular, if a timeout would have fired while the system was suspended,\n * it will instead fire as soon as possible after resume.\n */\n\nimport { logger } from \"./logger.ts\";\n\n// we schedule a callback at least this often, to check if we've missed out on\n// some wall-clock time due to being suspended.\nconst TIMER_CHECK_PERIOD_MS = 1000;\n\n// counter, for making up ids to return from setTimeout\nlet count = 0;\n\n// the key for our callback with the real globalThis.setTimeout\nlet realCallbackKey: NodeJS.Timeout | number;\n\ntype Callback = {\n runAt: number;\n func: (...params: any[]) => void;\n params: any[];\n key: number;\n};\n\n// a sorted list of the callbacks to be run.\n// each is an object with keys [runAt, func, params, key].\nconst callbackList: Callback[] = [];\n\n// var debuglog = logger.log.bind(logger);\n/* istanbul ignore next */\nconst debuglog = function (...params: any[]): void {};\n\n/**\n * reimplementation of window.setTimeout, which will call the callback if\n * the wallclock time goes past the deadline.\n *\n * @param func - callback to be called after a delay\n * @param delayMs - number of milliseconds to delay by\n *\n * @returns an identifier for this callback, which may be passed into\n * clearTimeout later.\n */\nexport function setTimeout(func: (...params: any[]) => void, delayMs: number, ...params: any[]): number {\n delayMs = delayMs || 0;\n if (delayMs < 0) {\n delayMs = 0;\n }\n\n const runAt = Date.now() + delayMs;\n const key = count++;\n debuglog(\"setTimeout: scheduling cb\", key, \"at\", runAt, \"(delay\", delayMs, \")\");\n const data = {\n runAt: runAt,\n func: func,\n params: params,\n key: key,\n };\n\n // figure out where it goes in the list\n const idx = binarySearch(callbackList, function (el) {\n return el.runAt - runAt;\n });\n\n callbackList.splice(idx, 0, data);\n scheduleRealCallback();\n\n return key;\n}\n\n/**\n * reimplementation of window.clearTimeout, which mirrors setTimeout\n *\n * @param key - result from an earlier setTimeout call\n */\nexport function clearTimeout(key: number): void {\n if (callbackList.length === 0) {\n return;\n }\n\n // remove the element from the list\n let i: number;\n for (i = 0; i < callbackList.length; i++) {\n const cb = callbackList[i];\n if (cb.key == key) {\n callbackList.splice(i, 1);\n break;\n }\n }\n\n // iff it was the first one in the list, reschedule our callback.\n if (i === 0) {\n scheduleRealCallback();\n }\n}\n\n// use the real globalThis.setTimeout to schedule a callback to runCallbacks.\nfunction scheduleRealCallback(): void {\n if (realCallbackKey) {\n globalThis.clearTimeout(realCallbackKey as NodeJS.Timeout);\n }\n\n const first = callbackList[0];\n\n if (!first) {\n debuglog(\"scheduleRealCallback: no more callbacks, not rescheduling\");\n return;\n }\n\n const timestamp = Date.now();\n const delayMs = Math.min(first.runAt - timestamp, TIMER_CHECK_PERIOD_MS);\n\n debuglog(\"scheduleRealCallback: now:\", timestamp, \"delay:\", delayMs);\n realCallbackKey = globalThis.setTimeout(runCallbacks, delayMs);\n}\n\nfunction runCallbacks(): void {\n const timestamp = Date.now();\n debuglog(\"runCallbacks: now:\", timestamp);\n\n // get the list of things to call\n const callbacksToRun: Callback[] = [];\n // eslint-disable-next-line\n while (true) {\n const first = callbackList[0];\n if (!first || first.runAt > timestamp) {\n break;\n }\n const cb = callbackList.shift()!;\n debuglog(\"runCallbacks: popping\", cb.key);\n callbacksToRun.push(cb);\n }\n\n // reschedule the real callback before running our functions, to\n // keep the codepaths the same whether or not our functions\n // register their own setTimeouts.\n scheduleRealCallback();\n\n for (const cb of callbacksToRun) {\n try {\n cb.func.apply(globalThis, cb.params);\n } catch (e) {\n logger.error(\"Uncaught exception in callback function\", e);\n }\n }\n}\n\n/* search in a sorted array.\n *\n * returns the index of the last element for which func returns\n * greater than zero, or array.length if no such element exists.\n */\nfunction binarySearch<T>(array: T[], func: (v: T) => number): number {\n // min is inclusive, max exclusive.\n let min = 0;\n let max = array.length;\n\n while (min < max) {\n const mid = (min + max) >> 1;\n const res = func(array[mid]);\n if (res > 0) {\n // the element at 'mid' is too big; set it as the new max.\n max = mid;\n } else {\n // the element at 'mid' is too small. 'min' is inclusive, so +1.\n min = mid + 1;\n }\n }\n // presumably, min==max now.\n return min;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,MAAM,QAAQ,aAAa;;AAEpC;AACA;AACA,IAAMC,qBAAqB,GAAG,IAAI;;AAElC;AACA,IAAIC,KAAK,GAAG,CAAC;;AAEb;AACA,IAAIC,eAAwC;AAS5C;AACA;AACA,IAAMC,YAAwB,GAAG,EAAE;;AAEnC;AACA;AACA,IAAMC,QAAQ,GAAG,SAAXA,QAAQA,CAAA,EAAqC,CAAC,CAAC;;AAErD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,UAAUA,CAACC,IAAgC,EAAEC,OAAe,EAA4B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AAE,CAACT,GAAG,CAAC;IACzCgB,cAAc,CAACE,IAAI,CAACT,EAAE,CAAC;EAC3B;;EAEA;EACA;EACA;EACAH,oBAAoB,CAAC,CAAC;EAEtB,KAAK,IAAMG,GAAE,IAAIO,cAAc,EAAE;IAC7B,IAAI;MACAP,GAAE,CAACpB,IAAI,CAAC8B,KAAK,CAACT,UAAU,EAAED,GAAE,CAACf,MAAM,CAAC;IACxC,CAAC,CAAC,OAAO0B,CAAC,EAAE;MACRtC,MAAM,CAACuC,KAAK,CAAC,yCAAyC,EAAED,CAAC,CAAC;IAC9D;EACJ;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASjB,YAAYA,CAAImB,KAAU,EAAEjC,IAAsB,EAAU;EACjE;EACA,IAAIyB,GAAG,GAAG,CAAC;EACX,IAAIS,GAAG,GAAGD,KAAK,CAAC7B,MAAM;EAEtB,OAAOqB,GAAG,GAAGS,GAAG,EAAE;IACd,IAAMC,GAAG,GAAIV,GAAG,GAAGS,GAAG,IAAK,CAAC;IAC5B,IAAME,GAAG,GAAGpC,IAAI,CAACiC,KAAK,CAACE,GAAG,CAAC,CAAC;IAC5B,IAAIC,GAAG,GAAG,CAAC,EAAE;MACT;MACAF,GAAG,GAAGC,GAAG;IACb,CAAC,MAAM;MACH;MACAV,GAAG,GAAGU,GAAG,GAAG,CAAC;IACjB;EACJ;EACA;EACA,OAAOV,GAAG;AACd","ignoreList":[]}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
/*
|
|
3
|
-
Copyright 2023 The Matrix.org Foundation C.I.C.
|
|
4
|
-
|
|
5
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
you may not use this file except in compliance with the License.
|
|
7
|
-
You may obtain a copy of the License at
|
|
8
|
-
|
|
9
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
|
|
11
|
-
Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
See the License for the specific language governing permissions and
|
|
15
|
-
limitations under the License.
|
|
2
|
+
/*
|
|
3
|
+
Copyright 2023 The Matrix.org Foundation C.I.C.
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
See the License for the specific language governing permissions and
|
|
15
|
+
limitations under the License.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import { EventType } from "./@types/event.js";
|
|
19
19
|
import { isSupportedReceiptType, MapWithDefault, recursiveMapToObject } from "./utils.js";
|
|
20
|
-
/**
|
|
21
|
-
* Summarises the read receipts within a room. Used by the sync accumulator.
|
|
22
|
-
*
|
|
23
|
-
* Given receipts for users, picks the most recently-received one and provides
|
|
24
|
-
* the results in a new fake receipt event returned from
|
|
25
|
-
* buildAccumulatedReceiptEvent().
|
|
26
|
-
*
|
|
27
|
-
* Handles unthreaded receipts and receipts in each thread separately, so the
|
|
28
|
-
* returned event contains the most recently received unthreaded receipt, and
|
|
29
|
-
* the most recently received receipt in each thread.
|
|
20
|
+
/**
|
|
21
|
+
* Summarises the read receipts within a room. Used by the sync accumulator.
|
|
22
|
+
*
|
|
23
|
+
* Given receipts for users, picks the most recently-received one and provides
|
|
24
|
+
* the results in a new fake receipt event returned from
|
|
25
|
+
* buildAccumulatedReceiptEvent().
|
|
26
|
+
*
|
|
27
|
+
* Handles unthreaded receipts and receipts in each thread separately, so the
|
|
28
|
+
* returned event contains the most recently received unthreaded receipt, and
|
|
29
|
+
* the most recently received receipt in each thread.
|
|
30
30
|
*/
|
|
31
31
|
export class ReceiptAccumulator {
|
|
32
32
|
constructor() {
|
|
@@ -35,34 +35,34 @@ export class ReceiptAccumulator {
|
|
|
35
35
|
/** thread_id -\> user_id -\> most-recently-received receipt for this thread */
|
|
36
36
|
_defineProperty(this, "threadedReadReceipts", new MapWithDefault(() => new Map()));
|
|
37
37
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Provide an unthreaded receipt for this user. Overwrites any other
|
|
40
|
-
* unthreaded receipt we have for this user.
|
|
38
|
+
/**
|
|
39
|
+
* Provide an unthreaded receipt for this user. Overwrites any other
|
|
40
|
+
* unthreaded receipt we have for this user.
|
|
41
41
|
*/
|
|
42
42
|
setUnthreaded(userId, receipt) {
|
|
43
43
|
this.unthreadedReadReceipts.set(userId, receipt);
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
/**
|
|
47
|
-
* Provide a receipt for this user in this thread. Overwrites any other
|
|
48
|
-
* receipt we have for this user in this thread.
|
|
46
|
+
/**
|
|
47
|
+
* Provide a receipt for this user in this thread. Overwrites any other
|
|
48
|
+
* receipt we have for this user in this thread.
|
|
49
49
|
*/
|
|
50
50
|
setThreaded(threadId, userId, receipt) {
|
|
51
51
|
this.threadedReadReceipts.getOrCreate(threadId).set(userId, receipt);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
/**
|
|
55
|
-
* @returns an iterator of pairs of [userId, AccumulatedReceipt] - all the
|
|
56
|
-
* most recently-received unthreaded receipts for each user.
|
|
54
|
+
/**
|
|
55
|
+
* @returns an iterator of pairs of [userId, AccumulatedReceipt] - all the
|
|
56
|
+
* most recently-received unthreaded receipts for each user.
|
|
57
57
|
*/
|
|
58
58
|
allUnthreaded() {
|
|
59
59
|
return this.unthreadedReadReceipts.entries();
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
/**
|
|
63
|
-
* @returns an iterator of pairs of [userId, AccumulatedReceipt] - all the
|
|
64
|
-
* most recently-received threaded receipts for each user, in all
|
|
65
|
-
* threads.
|
|
62
|
+
/**
|
|
63
|
+
* @returns an iterator of pairs of [userId, AccumulatedReceipt] - all the
|
|
64
|
+
* most recently-received threaded receipts for each user, in all
|
|
65
|
+
* threads.
|
|
66
66
|
*/
|
|
67
67
|
*allThreaded() {
|
|
68
68
|
for (var receiptsForThread of this.threadedReadReceipts.values()) {
|
|
@@ -72,9 +72,9 @@ export class ReceiptAccumulator {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
/**
|
|
76
|
-
* Given a list of ephemeral events, find the receipts and store the
|
|
77
|
-
* relevant ones to be returned later from buildAccumulatedReceiptEvent().
|
|
75
|
+
/**
|
|
76
|
+
* Given a list of ephemeral events, find the receipts and store the
|
|
77
|
+
* relevant ones to be returned later from buildAccumulatedReceiptEvent().
|
|
78
78
|
*/
|
|
79
79
|
consumeEphemeralEvents(events) {
|
|
80
80
|
events === null || events === void 0 || events.forEach(e => {
|
|
@@ -137,10 +137,10 @@ export class ReceiptAccumulator {
|
|
|
137
137
|
});
|
|
138
138
|
}
|
|
139
139
|
|
|
140
|
-
/**
|
|
141
|
-
* Build a receipt event that contains all relevant information for this
|
|
142
|
-
* room, taking the most recently received receipt for each user in an
|
|
143
|
-
* unthreaded context, and in each thread.
|
|
140
|
+
/**
|
|
141
|
+
* Build a receipt event that contains all relevant information for this
|
|
142
|
+
* room, taking the most recently received receipt for each user in an
|
|
143
|
+
* unthreaded context, and in each thread.
|
|
144
144
|
*/
|
|
145
145
|
buildAccumulatedReceiptEvent(roomId) {
|
|
146
146
|
var receiptEvent = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"receipt-accumulator.js","names":["EventType","isSupportedReceiptType","MapWithDefault","recursiveMapToObject","ReceiptAccumulator","constructor","_defineProperty","Map","setUnthreaded","userId","receipt","unthreadedReadReceipts","set","setThreaded","threadId","threadedReadReceipts","getOrCreate","allUnthreaded","entries","allThreaded","receiptsForThread","values","e","consumeEphemeralEvents","events","forEach","type","Receipt","content","Object","keys","eventId","_ref","key","value","data","thread_id","buildAccumulatedReceiptEvent","roomId","receiptEvent","room_id","receiptEventContent","receiptData","size"],"sources":["../src/receipt-accumulator.ts"],"sourcesContent":["/*\r\nCopyright 2023 The Matrix.org Foundation C.I.C.\r\n\r\nLicensed under the Apache License, Version 2.0 (the \"License\");\r\nyou may not use this file except in compliance with the License.\r\nYou may obtain a copy of the License at\r\n\r\n http://www.apache.org/licenses/LICENSE-2.0\r\n\r\nUnless required by applicable law or agreed to in writing, software\r\ndistributed under the License is distributed on an \"AS IS\" BASIS,\r\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r\nSee the License for the specific language governing permissions and\r\nlimitations under the License.\r\n*/\r\n\r\nimport { type IMinimalEvent } from \"./sync-accumulator.ts\";\r\nimport { EventType } from \"./@types/event.ts\";\r\nimport { isSupportedReceiptType, MapWithDefault, recursiveMapToObject } from \"./utils.ts\";\r\nimport { type IContent } from \"./models/event.ts\";\r\nimport { type ReceiptContent, type ReceiptType } from \"./@types/read_receipts.ts\";\r\n\r\ninterface AccumulatedReceipt {\r\n data: IMinimalEvent;\r\n type: ReceiptType;\r\n eventId: string;\r\n}\r\n\r\n/**\r\n * Summarises the read receipts within a room. Used by the sync accumulator.\r\n *\r\n * Given receipts for users, picks the most recently-received one and provides\r\n * the results in a new fake receipt event returned from\r\n * buildAccumulatedReceiptEvent().\r\n *\r\n * Handles unthreaded receipts and receipts in each thread separately, so the\r\n * returned event contains the most recently received unthreaded receipt, and\r\n * the most recently received receipt in each thread.\r\n */\r\nexport class ReceiptAccumulator {\r\n /** user_id -\\> most-recently-received unthreaded receipt */\r\n private unthreadedReadReceipts: Map<string, AccumulatedReceipt> = new Map();\r\n\r\n /** thread_id -\\> user_id -\\> most-recently-received receipt for this thread */\r\n private threadedReadReceipts: MapWithDefault<string, Map<string, AccumulatedReceipt>> = new MapWithDefault(\r\n () => new Map(),\r\n );\r\n\r\n /**\r\n * Provide an unthreaded receipt for this user. Overwrites any other\r\n * unthreaded receipt we have for this user.\r\n */\r\n private setUnthreaded(userId: string, receipt: AccumulatedReceipt): void {\r\n this.unthreadedReadReceipts.set(userId, receipt);\r\n }\r\n\r\n /**\r\n * Provide a receipt for this user in this thread. Overwrites any other\r\n * receipt we have for this user in this thread.\r\n */\r\n private setThreaded(threadId: string, userId: string, receipt: AccumulatedReceipt): void {\r\n this.threadedReadReceipts.getOrCreate(threadId).set(userId, receipt);\r\n }\r\n\r\n /**\r\n * @returns an iterator of pairs of [userId, AccumulatedReceipt] - all the\r\n * most recently-received unthreaded receipts for each user.\r\n */\r\n private allUnthreaded(): IterableIterator<[string, AccumulatedReceipt]> {\r\n return this.unthreadedReadReceipts.entries();\r\n }\r\n\r\n /**\r\n * @returns an iterator of pairs of [userId, AccumulatedReceipt] - all the\r\n * most recently-received threaded receipts for each user, in all\r\n * threads.\r\n */\r\n private *allThreaded(): IterableIterator<[string, AccumulatedReceipt]> {\r\n for (const receiptsForThread of this.threadedReadReceipts.values()) {\r\n for (const e of receiptsForThread.entries()) {\r\n yield e;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Given a list of ephemeral events, find the receipts and store the\r\n * relevant ones to be returned later from buildAccumulatedReceiptEvent().\r\n */\r\n public consumeEphemeralEvents(events: IMinimalEvent[] | undefined): void {\r\n events?.forEach((e) => {\r\n if (e.type !== EventType.Receipt || !e.content) {\r\n // This means we'll drop unknown ephemeral events but that\r\n // seems okay.\r\n return;\r\n }\r\n\r\n // Handle m.receipt events. They clobber based on:\r\n // (user_id, receipt_type)\r\n // but they are keyed in the event as:\r\n // content:{ $event_id: { $receipt_type: { $user_id: {json} }}}\r\n // so store them in the former so we can accumulate receipt deltas\r\n // quickly and efficiently (we expect a lot of them). Fold the\r\n // receipt type into the key name since we only have 1 at the\r\n // moment (m.read) and nested JSON objects are slower and more\r\n // of a hassle to work with. We'll inflate this back out when\r\n // getJSON() is called.\r\n Object.keys(e.content).forEach((eventId) => {\r\n Object.entries<ReceiptContent>(e.content[eventId]).forEach(([key, value]) => {\r\n if (!isSupportedReceiptType(key)) return;\r\n\r\n for (const userId of Object.keys(value)) {\r\n const data = e.content[eventId][key][userId];\r\n\r\n const receipt = {\r\n data: e.content[eventId][key][userId],\r\n type: key as ReceiptType,\r\n eventId,\r\n };\r\n\r\n // In a world that supports threads, read receipts normally have\r\n // a `thread_id` which is either the thread they belong in or\r\n // `MAIN_ROOM_TIMELINE`, so we normally use `setThreaded(...)`\r\n // here. The `MAIN_ROOM_TIMELINE` is just treated as another\r\n // thread.\r\n //\r\n // We still encounter read receipts that are \"unthreaded\"\r\n // (missing the `thread_id` property). These come from clients\r\n // that don't support threads, and from threaded clients that\r\n // are doing a \"Mark room as read\" operation. Unthreaded\r\n // receipts mark everything \"before\" them as read, in all\r\n // threads, where \"before\" means in Sync Order i.e. the order\r\n // the events were received from the homeserver in a sync.\r\n // [Note: we have some bugs where we use timestamp order instead\r\n // of Sync Order, because we don't correctly remember the Sync\r\n // Order. See #3325.]\r\n //\r\n // Calling the wrong method will cause incorrect behavior like\r\n // messages re-appearing as \"new\" when you already read them\r\n // previously.\r\n if (!data.thread_id) {\r\n this.setUnthreaded(userId, receipt);\r\n } else {\r\n this.setThreaded(data.thread_id, userId, receipt);\r\n }\r\n }\r\n });\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * Build a receipt event that contains all relevant information for this\r\n * room, taking the most recently received receipt for each user in an\r\n * unthreaded context, and in each thread.\r\n */\r\n public buildAccumulatedReceiptEvent(roomId: string): IMinimalEvent | null {\r\n const receiptEvent: IMinimalEvent = {\r\n type: EventType.Receipt,\r\n room_id: roomId,\r\n content: {\r\n // $event_id: { \"m.read\": { $user_id: $json } }\r\n } as IContent,\r\n };\r\n\r\n const receiptEventContent: MapWithDefault<\r\n string,\r\n MapWithDefault<ReceiptType, Map<string, object>>\r\n > = new MapWithDefault(() => new MapWithDefault(() => new Map()));\r\n\r\n for (const [userId, receiptData] of this.allUnthreaded()) {\r\n receiptEventContent\r\n .getOrCreate(receiptData.eventId)\r\n .getOrCreate(receiptData.type)\r\n .set(userId, receiptData.data);\r\n }\r\n\r\n for (const [userId, receiptData] of this.allThreaded()) {\r\n receiptEventContent\r\n .getOrCreate(receiptData.eventId)\r\n .getOrCreate(receiptData.type)\r\n .set(userId, receiptData.data);\r\n }\r\n\r\n receiptEvent.content = recursiveMapToObject(receiptEventContent);\r\n\r\n return receiptEventContent.size > 0 ? receiptEvent : null;\r\n }\r\n}\r\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,SAAS,QAAQ,mBAAmB;AAC7C,SAASC,sBAAsB,EAAEC,cAAc,EAAEC,oBAAoB,QAAQ,YAAY;AAUzF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,CAAC;EAAAC,YAAA;IAC5B;IAAAC,eAAA,iCACkE,IAAIC,GAAG,CAAC,CAAC;IAE3E;IAAAD,eAAA,+BACwF,IAAIJ,cAAc,CACtG,MAAM,IAAIK,GAAG,CAAC,CAClB,CAAC;EAAA;EAED;AACJ;AACA;AACA;EACYC,aAAaA,CAACC,MAAc,EAAEC,OAA2B,EAAQ;IACrE,IAAI,CAACC,sBAAsB,CAACC,GAAG,CAACH,MAAM,EAAEC,OAAO,CAAC;EACpD;;EAEA;AACJ;AACA;AACA;EACYG,WAAWA,CAACC,QAAgB,EAAEL,MAAc,EAAEC,OAA2B,EAAQ;IACrF,IAAI,CAACK,oBAAoB,CAACC,WAAW,CAACF,QAAQ,CAAC,CAACF,GAAG,CAACH,MAAM,EAAEC,OAAO,CAAC;EACxE;;EAEA;AACJ;AACA;AACA;EACYO,aAAaA,CAAA,EAAmD;IACpE,OAAO,IAAI,CAACN,sBAAsB,CAACO,OAAO,CAAC,C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BAAoB,CAACsC,mBAAmB,CAAC;IAEhE,OAAOA,mBAAmB,CAACE,IAAI,GAAG,CAAC,GAAGJ,YAAY,GAAG,IAAI;EAC7D;AACJ","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"receipt-accumulator.js","names":["EventType","isSupportedReceiptType","MapWithDefault","recursiveMapToObject","ReceiptAccumulator","constructor","_defineProperty","Map","setUnthreaded","userId","receipt","unthreadedReadReceipts","set","setThreaded","threadId","threadedReadReceipts","getOrCreate","allUnthreaded","entries","allThreaded","receiptsForThread","values","e","consumeEphemeralEvents","events","forEach","type","Receipt","content","Object","keys","eventId","_ref","key","value","data","thread_id","buildAccumulatedReceiptEvent","roomId","receiptEvent","room_id","receiptEventContent","receiptData","size"],"sources":["../src/receipt-accumulator.ts"],"sourcesContent":["/*\nCopyright 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type IMinimalEvent } from \"./sync-accumulator.ts\";\nimport { EventType } from \"./@types/event.ts\";\nimport { isSupportedReceiptType, MapWithDefault, recursiveMapToObject } from \"./utils.ts\";\nimport { type IContent } from \"./models/event.ts\";\nimport { type ReceiptContent, type ReceiptType } from \"./@types/read_receipts.ts\";\n\ninterface AccumulatedReceipt {\n data: IMinimalEvent;\n type: ReceiptType;\n eventId: string;\n}\n\n/**\n * Summarises the read receipts within a room. Used by the sync accumulator.\n *\n * Given receipts for users, picks the most recently-received one and provides\n * the results in a new fake receipt event returned from\n * buildAccumulatedReceiptEvent().\n *\n * Handles unthreaded receipts and receipts in each thread separately, so the\n * returned event contains the most recently received unthreaded receipt, and\n * the most recently received receipt in each thread.\n */\nexport class ReceiptAccumulator {\n /** user_id -\\> most-recently-received unthreaded receipt */\n private unthreadedReadReceipts: Map<string, AccumulatedReceipt> = new Map();\n\n /** thread_id -\\> user_id -\\> most-recently-received receipt for this thread */\n private threadedReadReceipts: MapWithDefault<string, Map<string, AccumulatedReceipt>> = new MapWithDefault(\n () => new Map(),\n );\n\n /**\n * Provide an unthreaded receipt for this user. Overwrites any other\n * unthreaded receipt we have for this user.\n */\n private setUnthreaded(userId: string, receipt: AccumulatedReceipt): void {\n this.unthreadedReadReceipts.set(userId, receipt);\n }\n\n /**\n * Provide a receipt for this user in this thread. Overwrites any other\n * receipt we have for this user in this thread.\n */\n private setThreaded(threadId: string, userId: string, receipt: AccumulatedReceipt): void {\n this.threadedReadReceipts.getOrCreate(threadId).set(userId, receipt);\n }\n\n /**\n * @returns an iterator of pairs of [userId, AccumulatedReceipt] - all the\n * most recently-received unthreaded receipts for each user.\n */\n private allUnthreaded(): IterableIterator<[string, AccumulatedReceipt]> {\n return this.unthreadedReadReceipts.entries();\n }\n\n /**\n * @returns an iterator of pairs of [userId, AccumulatedReceipt] - all the\n * most recently-received threaded receipts for each user, in all\n * threads.\n */\n private *allThreaded(): IterableIterator<[string, AccumulatedReceipt]> {\n for (const receiptsForThread of this.threadedReadReceipts.values()) {\n for (const e of receiptsForThread.entries()) {\n yield e;\n }\n }\n }\n\n /**\n * Given a list of ephemeral events, find the receipts and store the\n * relevant ones to be returned later from buildAccumulatedReceiptEvent().\n */\n public consumeEphemeralEvents(events: IMinimalEvent[] | undefined): void {\n events?.forEach((e) => {\n if (e.type !== EventType.Receipt || !e.content) {\n // This means we'll drop unknown ephemeral events but that\n // seems okay.\n return;\n }\n\n // Handle m.receipt events. They clobber based on:\n // (user_id, receipt_type)\n // but they are keyed in the event as:\n // content:{ $event_id: { $receipt_type: { $user_id: {json} }}}\n // so store them in the former so we can accumulate receipt deltas\n // quickly and efficiently (we expect a lot of them). Fold the\n // receipt type into the key name since we only have 1 at the\n // moment (m.read) and nested JSON objects are slower and more\n // of a hassle to work with. We'll inflate this back out when\n // getJSON() is called.\n Object.keys(e.content).forEach((eventId) => {\n Object.entries<ReceiptContent>(e.content[eventId]).forEach(([key, value]) => {\n if (!isSupportedReceiptType(key)) return;\n\n for (const userId of Object.keys(value)) {\n const data = e.content[eventId][key][userId];\n\n const receipt = {\n data: e.content[eventId][key][userId],\n type: key as ReceiptType,\n eventId,\n };\n\n // In a world that supports threads, read receipts normally have\n // a `thread_id` which is either the thread they belong in or\n // `MAIN_ROOM_TIMELINE`, so we normally use `setThreaded(...)`\n // here. The `MAIN_ROOM_TIMELINE` is just treated as another\n // thread.\n //\n // We still encounter read receipts that are \"unthreaded\"\n // (missing the `thread_id` property). These come from clients\n // that don't support threads, and from threaded clients that\n // are doing a \"Mark room as read\" operation. Unthreaded\n // receipts mark everything \"before\" them as read, in all\n // threads, where \"before\" means in Sync Order i.e. the order\n // the events were received from the homeserver in a sync.\n // [Note: we have some bugs where we use timestamp order instead\n // of Sync Order, because we don't correctly remember the Sync\n // Order. See #3325.]\n //\n // Calling the wrong method will cause incorrect behavior like\n // messages re-appearing as \"new\" when you already read them\n // previously.\n if (!data.thread_id) {\n this.setUnthreaded(userId, receipt);\n } else {\n this.setThreaded(data.thread_id, userId, receipt);\n }\n }\n });\n });\n });\n }\n\n /**\n * Build a receipt event that contains all relevant information for this\n * room, taking the most recently received receipt for each user in an\n * unthreaded context, and in each thread.\n */\n public buildAccumulatedReceiptEvent(roomId: string): IMinimalEvent | null {\n const receiptEvent: IMinimalEvent = {\n type: EventType.Receipt,\n room_id: roomId,\n content: {\n // $event_id: { \"m.read\": { $user_id: $json } }\n } as IContent,\n };\n\n const receiptEventContent: MapWithDefault<\n string,\n MapWithDefault<ReceiptType, Map<string, object>>\n > = new MapWithDefault(() => new MapWithDefault(() => new Map()));\n\n for (const [userId, receiptData] of this.allUnthreaded()) {\n receiptEventContent\n .getOrCreate(receiptData.eventId)\n .getOrCreate(receiptData.type)\n .set(userId, receiptData.data);\n }\n\n for (const [userId, receiptData] of this.allThreaded()) {\n receiptEventContent\n .getOrCreate(receiptData.eventId)\n .getOrCreate(receiptData.type)\n .set(userId, receiptData.data);\n }\n\n receiptEvent.content = recursiveMapToObject(receiptEventContent);\n\n return receiptEventContent.size > 0 ? receiptEvent : null;\n }\n}\n"],"mappings":";AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,SAASA,SAAS,QAAQ,mBAAmB;AAC7C,SAASC,sBAAsB,EAAEC,cAAc,EAAEC,oBAAoB,QAAQ,YAAY;AAUzF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,kBAAkB,CAAC;EAAAC,YAAA;IAC5B;IAAAC,eAAA,iCACkE,IAAIC,GAAG,CAAC,CAAC;IAE3E;IAAAD,eAAA,+BACwF,IAAIJ,cAAc,CACtG,MAAM,IAAIK,GAAG,CAAC,CAClB,CAAC;EAAA;EAED;AACJ;AACA;AACA;EACYC,aAAaA,CAACC,MAAc,EAAEC,OAA2B,EAAQ;IACrE,IAAI,CAACC,sBAAsB,CAACC,GAAG,CAACH,MAAM,EAAEC,OAAO,CAAC;EACpD;;EAEA;AACJ;AACA;AACA;EACYG,WAAWA,CAACC,QAAgB,EAAEL,MAAc,EAAEC,OAA2B,EAAQ;IACrF,IAAI,CAACK,oBAAoB,CAACC,WAAW,CAACF,QAAQ,CAAC,CAACF,GAAG,CAACH,MAAM,EAAEC,OAAO,CAAC;EACxE;;EAEA;AACJ;AACA;AACA;EACYO,aAAaA,CAAA,EAAmD;IACpE,OAAO,IAAI,CAACN,sBAAsB,CAACO,OAAO,CAAC,CAAC;EAChD;;EAEA;AACJ;AACA;AACA;AACA;EACI,CAASC,WAAWA,CAAA,EAAmD;IACnE,KAAK,IAAMC,iBAAiB,IAAI,IAAI,CAACL,oBAAoB,CAACM,MAAM,CAAC,CAAC,EAAE;MAChE,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
{"version":3,"file":"RendezvousChannel.js","names":[],"sources":["../../src/rendezvous/RendezvousChannel.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"file":"RendezvousChannel.js","names":[],"sources":["../../src/rendezvous/RendezvousChannel.ts"],"sourcesContent":["/*\nCopyright 2022 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type RendezvousCode, type RendezvousIntent, type RendezvousFailureReason } from \"./index.ts\";\n\nexport interface RendezvousChannel<T> {\n /**\n * @returns the checksum/confirmation digits to be shown to the user\n */\n connect(): Promise<string>;\n\n /**\n * Send a payload via the channel.\n * @param data - payload to send\n */\n send(data: T): Promise<void>;\n\n /**\n * Receive a payload from the channel.\n * @returns the received payload\n */\n receive(): Promise<Partial<T> | undefined>;\n\n /**\n * Close the channel and clear up any resources.\n */\n close(): Promise<void>;\n\n /**\n * @returns a representation of the channel that can be encoded in a QR or similar\n */\n generateCode(intent: RendezvousIntent): Promise<RendezvousCode>;\n\n cancel(reason: RendezvousFailureReason): Promise<void>;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RendezvousCode.js","names":[],"sources":["../../src/rendezvous/RendezvousCode.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"file":"RendezvousCode.js","names":[],"sources":["../../src/rendezvous/RendezvousCode.ts"],"sourcesContent":["/*\nCopyright 2022 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type RendezvousTransportDetails, type RendezvousIntent } from \"./index.ts\";\n\nexport interface RendezvousCode {\n intent: RendezvousIntent;\n rendezvous?: {\n transport: RendezvousTransportDetails;\n algorithm: string;\n };\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2022 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.
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 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
15
|
*/
|
|
16
16
|
|
|
17
17
|
export class RendezvousError extends Error {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RendezvousError.js","names":["RendezvousError","Error","constructor","message","code"],"sources":["../../src/rendezvous/RendezvousError.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"file":"RendezvousError.js","names":["RendezvousError","Error","constructor","message","code"],"sources":["../../src/rendezvous/RendezvousError.ts"],"sourcesContent":["/*\nCopyright 2022 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type RendezvousFailureReason } from \"./index.ts\";\n\nexport class RendezvousError extends Error {\n public constructor(\n message: string,\n public readonly code: RendezvousFailureReason,\n ) {\n super(message);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,OAAO,MAAMA,eAAe,SAASC,KAAK,CAAC;EAChCC,WAAWA,CACdC,OAAe,EACCC,IAA6B,EAC/C;IACE,KAAK,CAACD,OAAO,CAAC;IAAC,KAFCC,IAA6B,GAA7BA,IAA6B;EAGjD;AACJ","ignoreList":[]}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2022 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.
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 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
15
|
*/
|
|
16
16
|
|
|
17
17
|
export var MSC4108FailureReason = /*#__PURE__*/function (MSC4108FailureReason) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RendezvousFailureReason.js","names":["MSC4108FailureReason","ClientRendezvousFailureReason"],"sources":["../../src/rendezvous/RendezvousFailureReason.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"file":"RendezvousFailureReason.js","names":["MSC4108FailureReason","ClientRendezvousFailureReason"],"sources":["../../src/rendezvous/RendezvousFailureReason.ts"],"sourcesContent":["/*\nCopyright 2022 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport type RendezvousFailureListener = (reason: RendezvousFailureReason) => void;\n\nexport type RendezvousFailureReason = MSC4108FailureReason | ClientRendezvousFailureReason;\n\nexport enum MSC4108FailureReason {\n AuthorizationExpired = \"authorization_expired\",\n DeviceAlreadyExists = \"device_already_exists\",\n DeviceNotFound = \"device_not_found\",\n UnexpectedMessageReceived = \"unexpected_message_received\",\n UnsupportedProtocol = \"unsupported_protocol\",\n UserCancelled = \"user_cancelled\",\n}\n\nexport enum ClientRendezvousFailureReason {\n /** The sign in request has expired */\n Expired = \"expired\",\n /** The homeserver is lacking support for the required features */\n HomeserverLacksSupport = \"homeserver_lacks_support\",\n /** The secure channel verification failed meaning that it might be compromised */\n InsecureChannelDetected = \"insecure_channel_detected\",\n /** An invalid/incompatible QR code was scanned */\n InvalidCode = \"invalid_code\",\n /** The other device is not signed in */\n OtherDeviceNotSignedIn = \"other_device_not_signed_in\",\n /** The other device is already signed in */\n OtherDeviceAlreadySignedIn = \"other_device_already_signed_in\",\n /** Other */\n Unknown = \"unknown\",\n /** The user declined the sign in request */\n UserDeclined = \"user_declined\",\n /** The rendezvous request is missing an ETag header */\n ETagMissing = \"etag_missing\",\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA,WAAYA,oBAAoB,0BAApBA,oBAAoB;EAApBA,oBAAoB;EAApBA,oBAAoB;EAApBA,oBAAoB;EAApBA,oBAAoB;EAApBA,oBAAoB;EAApBA,oBAAoB;EAAA,OAApBA,oBAAoB;AAAA;AAShC,WAAYC,6BAA6B,0BAA7BA,6BAA6B;EACrC;EADQA,6BAA6B;EAGrC;EAHQA,6BAA6B;EAKrC;EALQA,6BAA6B;EAOrC;EAPQA,6BAA6B;EASrC;EATQA,6BAA6B;EAWrC;EAXQA,6BAA6B;EAarC;EAbQA,6BAA6B;EAerC;EAfQA,6BAA6B;EAiBrC;EAjBQA,6BAA6B;EAAA,OAA7BA,6BAA6B;AAAA","ignoreList":[]}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2022 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.
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2022 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
15
|
*/
|
|
16
16
|
|
|
17
17
|
export var RendezvousIntent = /*#__PURE__*/function (RendezvousIntent) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RendezvousIntent.js","names":["RendezvousIntent"],"sources":["../../src/rendezvous/RendezvousIntent.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"file":"RendezvousIntent.js","names":["RendezvousIntent"],"sources":["../../src/rendezvous/RendezvousIntent.ts"],"sourcesContent":["/*\nCopyright 2022 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nexport enum RendezvousIntent {\n LOGIN_ON_NEW_DEVICE = \"login.start\",\n RECIPROCATE_LOGIN_ON_EXISTING_DEVICE = \"login.reciprocate\",\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,WAAYA,gBAAgB,0BAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAhBA,gBAAgB;EAAA,OAAhBA,gBAAgB;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RendezvousTransport.js","names":[],"sources":["../../src/rendezvous/RendezvousTransport.ts"],"sourcesContent":["/*\
|
|
1
|
+
{"version":3,"file":"RendezvousTransport.js","names":[],"sources":["../../src/rendezvous/RendezvousTransport.ts"],"sourcesContent":["/*\nCopyright 2022 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type RendezvousFailureListener, type RendezvousFailureReason } from \"./index.ts\";\n\nexport interface RendezvousTransportDetails {\n type: string;\n}\n\n/**\n * Interface representing a generic rendezvous transport.\n */\nexport interface RendezvousTransport<T> {\n /**\n * Ready state of the transport. This is set to true when the transport is ready to be used.\n */\n readonly ready: boolean;\n\n /**\n * Listener for cancellation events. This is called when the rendezvous is cancelled or fails.\n */\n onFailure?: RendezvousFailureListener;\n\n /**\n * @returns the transport details that can be encoded in a QR or similar\n */\n details(): Promise<RendezvousTransportDetails>;\n\n /**\n * Send data via the transport.\n * @param data - the data itself\n */\n send(data: T): Promise<void>;\n\n /**\n * Receive data from the transport.\n */\n receive(): Promise<Partial<T> | undefined>;\n\n /**\n * Cancel the rendezvous. This will call `onCancelled()` if it is set.\n * @param reason - the reason for the cancellation/failure\n */\n cancel(reason: RendezvousFailureReason): Promise<void>;\n}\n"],"mappings":"","ignoreList":[]}
|