* Implement Sticky Events MSC
* Renames
* lint
* some review work
* Update for support for 4-ples
* fix lint
* pull through method
* Fix the mistake
* More tests to appease SC
* Cleaner code
* Review cleanup
* Refactors based on review.
* lint
* Add sticky event support to the js-sdk
Signed-off-by: Timo K <toger5@hotmail.de>
* use sticky events for matrixRTC
Signed-off-by: Timo K <toger5@hotmail.de>
* make sticky events a non breaking change (default to state events. use joinConfig to use sticky events)
Signed-off-by: Timo K <toger5@hotmail.de>
* review
- fix types (`msc4354_sticky:number` -> `msc4354_sticky?: { duration_ms: number };`)
- add `MultiKeyMap`
Signed-off-by: Timo K <toger5@hotmail.de>
* Refactor all of this away to it's own accumulator and class.
* Add tests
* tidyup
* more test cleaning
* lint
* Updates and tests
* fix filter
* fix filter with lint
* Add timer tests
* Add tests for MatrixRTCSessionManager
* Listen for sticky events on MatrixRTCSessionManager
* fix logic on filtering out state events
* lint
* more lint
* tweaks
* Add logging in areas
* more debugging
* much more logging
* remove more logging
* Finish supporting new MSC
* a line
* reconnect the bits to RTC
* fixup more bits
* fixup testrs
* Ensure consistent order
* lint
* fix log line
* remove extra bit of code
* revert changes to room-sticky-events.ts
* fixup mocks again
* lint
* fix
* cleanup
* fix paths
* tweak test
* fixup
* Add more tests for coverage
* Small improvements
Signed-off-by: Timo K <toger5@hotmail.de>
* review
Signed-off-by: Timo K <toger5@hotmail.de>
* Document better
* fix sticky event type
Signed-off-by: Timo K <toger5@hotmail.de>
* fix demo
Signed-off-by: Timo K <toger5@hotmail.de>
* fix tests
Signed-off-by: Timo K <toger5@hotmail.de>
* Update src/matrixrtc/CallMembership.ts
Co-authored-by: Robin <robin@robin.town>
* cleanup
* lint
* fix ci
Signed-off-by: Timo K <toger5@hotmail.de>
---------
Signed-off-by: Timo K <toger5@hotmail.de>
Co-authored-by: Half-Shot <will@half-shot.uk>
Co-authored-by: Robin <robin@robin.town>
* WIP
* temp
Signed-off-by: Timo K <toger5@hotmail.de>
* Fix imports
* Fix checkSessionsMembershipData thinking foci_preferred is required
* incorporate CallMembership changes
- rename Focus -> Transport
- add RtcMembershipData (next to `sessionMembershipData`)
- make `new CallMembership` initializable with both
- move oldest member calculation into CallMembership
Signed-off-by: Timo K <toger5@hotmail.de>
* use correct event type
Signed-off-by: Timo K <toger5@hotmail.de>
* fix sonar cube conerns
Signed-off-by: Timo K <toger5@hotmail.de>
* callMembership tests
Signed-off-by: Timo K <toger5@hotmail.de>
* make test correct
Signed-off-by: Timo K <toger5@hotmail.de>
* make sonar cube happy (it does not know about the type constraints...)
Signed-off-by: Timo K <toger5@hotmail.de>
* remove created_ts from RtcMembership
Signed-off-by: Timo K <toger5@hotmail.de>
* fix imports
Signed-off-by: Timo K <toger5@hotmail.de>
* Update src/matrixrtc/IMembershipManager.ts
Co-authored-by: Robin <robin@robin.town>
* rename LivekitFocus.ts -> LivekitTransport.ts
Signed-off-by: Timo K <toger5@hotmail.de>
* add details to `getTransport`
Signed-off-by: Timo K <toger5@hotmail.de>
* review
Signed-off-by: Timo K <toger5@hotmail.de>
* use DEFAULT_EXPIRE_DURATION in tests
Signed-off-by: Timo K <toger5@hotmail.de>
* fix test `does not provide focus if the selection method is unknown`
Signed-off-by: Timo K <toger5@hotmail.de>
* Update src/matrixrtc/CallMembership.ts
Co-authored-by: Robin <robin@robin.town>
* Move `m.call.intent` into the `application` section for rtc member events.
Signed-off-by: Timo K <toger5@hotmail.de>
* review on rtc object validation code.
Signed-off-by: Timo K <toger5@hotmail.de>
* user id check
Signed-off-by: Timo K <toger5@hotmail.de>
* review: Refactor RTC membership handling and improve error handling
Signed-off-by: Timo K <toger5@hotmail.de>
* docstring updates
Signed-off-by: Timo K <toger5@hotmail.de>
* add back deprecated `getFocusInUse` & `getActiveFocus`
Signed-off-by: Timo K <toger5@hotmail.de>
* ci
Signed-off-by: Timo K <toger5@hotmail.de>
* Update src/matrixrtc/CallMembership.ts
Co-authored-by: Robin <robin@robin.town>
* lint
Signed-off-by: Timo K <toger5@hotmail.de>
* make test less strict for ew tests
Signed-off-by: Timo K <toger5@hotmail.de>
* Typescript downstream test adjustments
Signed-off-by: Timo K <toger5@hotmail.de>
* err
Signed-off-by: Timo K <toger5@hotmail.de>
---------
Signed-off-by: Timo K <toger5@hotmail.de>
Co-authored-by: Robin <robin@robin.town>
* Add media hint specifier
* Refactor to use m.call.intent and to apply to membership
* lint
* Add a mechanism to get the consensus of a call.
* Update tests
* Expose option to update the call intent.
* Better docs
* Add tests
* lint
* Expose the StatusChanged event through the RTCSession
Signed-off-by: Timo K <toger5@hotmail.de>
* add membershipManagerStatus public get field
Signed-off-by: Timo K <toger5@hotmail.de>
* add probably left as a getter
Signed-off-by: Timo K <toger5@hotmail.de>
* add tests for coverage
Signed-off-by: Timo K <toger5@hotmail.de>
---------
Signed-off-by: Timo K <toger5@hotmail.de>
* Introduce sessionDescription
Signed-off-by: Timo K <toger5@hotmail.de>
* Make sessionDescription part of a MatrixRTCSession
Signed-off-by: Timo K <toger5@hotmail.de>
* Make session manager only menage session for one sessionDescription
Signed-off-by: Timo K <toger5@hotmail.de>
* make membership manager aware about session (application + id)
Before this was just hardcoded to a call session
Signed-off-by: Timo K <toger5@hotmail.de>
* update tests
Signed-off-by: Timo K <toger5@hotmail.de>
* fix doc comments
Signed-off-by: Timo K <toger5@hotmail.de>
* Make fields private, improve comments, improve whitespace, don't use deprecated fields
Signed-off-by: Timo K <toger5@hotmail.de>
* add test for other application end event
Signed-off-by: Timo K <toger5@hotmail.de>
* rename call -> session
Signed-off-by: Timo K <toger5@hotmail.de>
* fix tests
Signed-off-by: Timo K <toger5@hotmail.de>
* remove id check since its already part of `deepCompare(membership.sessionDescription, sessionDescription)`
Signed-off-by: Timo K <toger5@hotmail.de>
* remove scope related tests. The id should be the only thing that scopes sessions. everything else is application (session type) specific
Signed-off-by: Timo K <toger5@hotmail.de>
* review
Signed-off-by: Timo K <toger5@hotmail.de>
* add test for custom sessionDescription
Signed-off-by: Timo K <toger5@hotmail.de>
* callMembershipsForRoom to default to call
Signed-off-by: Timo K <toger5@hotmail.de>
* roomSessionForRoom backwards compatible (And deprecate the call specific method)
Signed-off-by: Timo K <toger5@hotmail.de>
---------
Signed-off-by: Timo K <toger5@hotmail.de>
* Make it easier to mock call memberships for specific user IDs
* Allow sending notification events when starting a call
* rename notify -> notification
* replace `joining` concept with `ownMembership`
* introduce new `m.rtc.notification` event alongside `m.call.notify`
* send new notification event alongside the deprecated one
* Test for new notification event type
* update relation string to match msc
* review
* fix doc errors
* fix tests + format
* remove anything decline related
---------
Co-authored-by: Timo <toger5@hotmail.de>
* refactor: New encryption manager BasicEncryptionManager for todevice
fixup: bad do not commit
* fix: ToDevice transport not setting the sent_ts
* test: BasicEncryptionManager add statistics tests
* code review
* feat: Encryption manager just reshare on new joiner
* refactor: Rename BasicEncryptionManger to RTCEncryptionManager
* fixup: RTC experimental todevice should use new encryption mgr
* fixup: use proper logger hierarchy
* fixup: RTC rollout first key asap even if no members to send to
* fixup: RTC add test for first key use
* fixup! emitting outbound key before anyone registered
* fix: quick patch for transport switch, need test
* test: RTC encryption manager, add test for transport switch
* post rebase fix
* Remove bad corepack commit
* review: cleaning, renaming
* review: cleaning and renaming
* stop using root logger in favor of a parent logger
* post merge fix broken test
* remove corepack again
* fix reverted changes after a merge
* review: Properly deprecate getEncryptionKeys
* review: rename ensureMediaKeyDistribution to ensureKeyDistribution
* review: use OutdatedKeyFilter instead of KeyBuffer
* Remove `LegacyMemberhsipManager`
* remove tests from rtc session
Those tests were only run with the legacy membership manager and are redundant with the memberhsip manager test spec.
* fix tests
* dont use non existing TestManager anymore
* remove fails for legacy
* fix another test
* Remove redundant sendDelayedEventAction
We do already have the state `hasMemberEvent` that allows to distinguish the two cases. No need to create two dedicated actions.
* fix missing return
* Make membership manager an event emitter to inform about status updates.
- deprecate isJoined (replaced by isActivated)
- move Interface types to types.ts
* add tests for status updates.
* lint
* test "reschedules delayed leave event" in case the delayed event gets canceled
* review
* fix types
* prettier
* fix legacy membership manager
* remove deprecated jitter.
* use non deprecated config fields (keep deprecated fields as fallback)
* update tests to test non deprecated names
* make local NewMembershipManager variable names consistent with config
* make LegacyMembershipManger local variables consistent with config
* comments and rename `networkErrorLocalRetryMs` -> `networkErrorRetryMs`
* review
* MatrixRTC: ToDevice distribution for media stream keys
* test: Add RTC to device transport test
* lint
* fix key indexing
* fix indexing take two
- use correct value for: `onEncryptionKeysChanged`
- only update `latestGeneratedKeyIndex` for "this user" key
* test: add test for join config `useExperimentalToDeviceTransport`
* update test to fail without the fixed encryption key index
* review
* review (dave)
---------
Co-authored-by: Timo <toger5@hotmail.de>
* refactor: extract RoomKeyTransport class for key distribution
* refact: Call key transport, pass the target recipients to sendKey
* update IKeyTransport interface to event emitter.
* fix not subscribing to KeyTransportEvents in the EncryptionManager + cleanup
* fix one test and broken bits needed for the test (mostly statistics wrangling)
* fix tests
* add back decryptEventIfNeeded
* move and fix room transport tests
* dedupe isMyMembership
* move type declarations around to be at more reasonable places
* remove deprecated `onMembershipUpdate`
* fix imports
* only start keytransport when session is joined
* use makeKey to reduce test loc
* fix todo comment -> note comment
---------
Co-authored-by: Timo <toger5@hotmail.de>
* WIP doodles on MembershipManager test cases
* .
* initial membership manager test setup.
* Updates from discussion
* revert renaming comments
* remove unused import
* fix leave delayed event resend test.
It was missing a flush.
* comment out and remove unused variables
* es lint
* use jsdom instead of node test environment
* remove unused variables
* remove unused export
* temp
* review
* fixup tests
* more review
* remove wait for expect dependency
* flatten tests and add comments
* add more leave test cases
* use defer
* remove @jest/environment dependency
* Cleanup awaits and Make mock types more correct.
Make every mock return a Promise if the real implementation does return a pormise.
* remove flush promise dependency
* add linting to matrixrtc tests
* Add fix async lints and use matrix rtc logger for test environment.
* prettier
* change to MatrixRTCSession logger
* make accessing the full room deprecated
* remove deprecated usage of full room
* Clean up the deprecation
---------
Co-authored-by: Hugh Nimmo-Smith <hughns@matrix.org>
...and renames them, removing the special lowercase and uppercase
versions and exporting the underlying function instead.
Any apps that use these will either need to take the speed hit from
secure random functions and use the new ones, or write their own
insecure versions.
The lowercase and uppercasde verisons were used exactly once each
in element-web and never in js-sdk itself. The underlying function
is very simple and exporting just this gives more flexibility with
fewer exports.
* update join and leave internal api.
* rename onMembershipUpdate and triggerCallMembershipEventUpdate to onMembershipsUpdate
This makes it more clear that we do not talk about our own membership but all memberships in the session
* cleanup MembershipManager
- add comments and interface how to test this class.
- sort methods by public/private
- make triggerCallMembershipEventUpdate private
* docstrings for getFocusInUse and getActiveFocus
* simplify tests and make them only use MembershipManagerInterface methods.
This allows to exchange the membershipManager with a different implementation.
* convert interface to abstract class.
* review (implement interface, make interface internal, dont change public api.)
* Make the interface an actual interface.
The actual constructor of the class now contains the `Pick` to define what it needs from the client.
* move update condition into MembershipManager
* renaming public api
* Update src/matrixrtc/MatrixRTCSession.ts
Co-authored-by: Hugh Nimmo-Smith <hughns@users.noreply.github.com>
* Update src/matrixrtc/MatrixRTCSession.ts
Co-authored-by: Hugh Nimmo-Smith <hughns@users.noreply.github.com>
---------
Co-authored-by: Hugh Nimmo-Smith <hughns@users.noreply.github.com>
* split joinConfig
- myMembership related properties get moved into its own interface
* Add MyMembershipManager
* Remove methods and functions that are from MatrixRTCSession (they now live in MyMembershipManager)
* Refactor MatrixRTCSession to use myMembershipManager
* fix tests
* review
* get rid of more memberhsip manager usage in tests
* review - fix tests using private membershipManager props
* fix circular import
* remove all legacy call related code and adjust tests.
We actually had a bit of tests just for legacy and not for session events. All those tests got ported over so we do not remove any tests.
* dont adjust tests but remove legacy tests
* Remove deprecated CallMembership.getLocalExpiry()
* Remove references to legacy in test case names
* Clean up SessionMembershipData tsdoc
* Remove CallMembership.expires
* Use correct expire duration.
* make expiration methods not return optional values and update docstring
* add docs to `SessionMembershipData`
* Add new tests for session type member events that before only existed for legacy member events.
This reverts commit 795a3cffb61d672941c49e8139eb1d7b15c87d73.
* remove code we do not need yet.
* Cleanup
---------
Co-authored-by: Hugh Nimmo-Smith <hughns@matrix.org>
* remove all legacy call related code and adjust tests.
We actually had a bit of tests just for legacy and not for session events. All those tests got ported over so we do not remove any tests.
* dont adjust tests but remove legacy tests
* Remove deprecated CallMembership.getLocalExpiry()
* Remove references to legacy in test case names
* Clean up SessionMembershipData tsdoc
* Remove CallMembership.expires
* Use correct expire duration.
* make expiration methods not return optional values and update docstring
* add docs to `SessionMembershipData`
* Use `MSC4143` (instaed of `non-legacy`) wording in comment
Co-authored-by: Hugh Nimmo-Smith <hughns@users.noreply.github.com>
* Incorporate feedback from review
* Fix test name
---------
Co-authored-by: Hugh Nimmo-Smith <hughns@matrix.org>
Co-authored-by: Hugh Nimmo-Smith <hughns@users.noreply.github.com>
* Handle M_MAX_DELAY_EXCEEDED errors
Use a lower delay time if the server rejects a delay as too long.
* Add test
* Lint test
* Update src/matrixrtc/MatrixRTCSession.ts
Co-authored-by: Robin <robin@robin.town>
* Test computed expiry timeout value
---------
Co-authored-by: Robin <robin@robin.town>
* MatrixRTCSession: handle rate limit errors
* Lint
* Handle ratelimiting for non-legacy state setting
Each request must be retried, as the non-legacy flow involves a sequence
of requests that must resolve in order.
* Fix broken test
* Check for MSC3757 instead of the unmerged MSC3779
* Move helper out of beforeEach
* Test ratelimit errors
* Do not rotate MatrixRTC media encryption key when a new member joins a call
This change reverts https://github.com/matrix-org/matrix-js-sdk/pull/4422.
Instead, the rotation when a new member joins will be reintroduced as part of supporting to-device based MatrixRTC encryption key distribution.
* Improve function name
* Refactor/simplify Promises in MatrixRTCSession
* Update src/matrixrtc/MatrixRTCSession.ts
Co-authored-by: Hugh Nimmo-Smith <hughns@users.noreply.github.com>
* Fix+document+test leaveRoomSession's return value
* Throw instead of using expect in teardown
because lint rules forbid using expect outside of test functions
---------
Co-authored-by: Hugh Nimmo-Smith <hughns@users.noreply.github.com>
* Prepare delayed call leave events more reliably
- Try sending call join after preparing delayed leave
- On leave, send delayed leave instead of a new event
* Don't rely on errcodes for retry logic
because they are unavailable in widget mode
* Make arrow method readonly
SonarCloud rule typescript:S2933
* Test coverage for restarting delayed call leave
* Remove unneeded unstable_features mock
It's unneeded because all affected methods are mocked
* Don't share full key history for RTC per-participant encryption
Also record stats for how many keys have been sent/received and age of those received
* Update src/matrixrtc/MatrixRTCSession.ts
Co-authored-by: Robin <robin@robin.town>
* Add comment about why we track total age of events
---------
Co-authored-by: Robin <robin@robin.town>
* Use origin server timestamp for calculating group call membership expiry
* Fix tests
* Docs
* Refactor comments to reflect that the logic hasn't changed
* Make comment maintainable
* Fix up merge
* Fix test
* Handle MatrixRTC encryption keys arriving out of order
* Apply suggestions from code review
Co-authored-by: Andrew Ferrazzutti <andrewf@element.io>
* Suggestion from code review
---------
Co-authored-by: Andrew Ferrazzutti <andrewf@element.io>
* Resend MatrixRTC encryption keys if a membership has changed
* JSDoc
* Update src/matrixrtc/MatrixRTCSession.ts
Co-authored-by: Andrew Ferrazzutti <andrewf@element.io>
* Add note about using Set. symmetricDifference() when available
* Always store latest fingerprints
Should reduce unnecessary retransmits
* Refactor
---------
Co-authored-by: Andrew Ferrazzutti <andrewf@element.io>
and use them for more reliable MatrixRTC session membership events.
Also implement "parent" delayed events, which were in a previous version
of the MSC and may be reintroduced or be part of a new MSC later.
NOTE: Still missing is support for sending encrypted delayed events.
* Prefix the user+device state key if needed
No need to prefix it for rooms that use MSC3779.
Otherwise, prefix it to bypass the auth rule for state events with keys
starting with @.
* Use RegExp.exec() method instead
Sonar typescript:S6594
* Split nested ternary operator into method
Sonar typescript:S3358
* Add test coverage
* Use legacy call membership if anyone else is
* Convert nullish to boolean
* Update tests
* Lint
* Use computed decision to use legacy events or not
* Check if discovered legacy sessions are ongoing
* Lint
* Lint again
* Increase test coverage
* Refactor to preferred and active foci.
Signed-off-by: Timo K <toger5@hotmail.de>
* make the sdk compatible with MSC4143 but still be backwards compatible
* comment fixes
* also fallback to legacy if the current member event is legacy
* use XOR types
* use EitherAnd
* make livekit Foucs types simpler
* review
* fix tests
* test work
* more review + more tests
* remove unnecassary await that is in conflict with the comment
* make joinRoomSession sync
* Update src/matrixrtc/MatrixRTCSession.ts
Co-authored-by: Andrew Ferrazzutti <af_0_af@hotmail.com>
* review
* fix
* test
* review
* review
* comment clarification
* typo
---------
Signed-off-by: Timo K <toger5@hotmail.de>
Co-authored-by: Andrew Ferrazzutti <af_0_af@hotmail.com>
* Introduce Membership TS type
* Adapt the Membership TS type to be an enum
* Add docstrings for KnownMembership and Membership
* Move Membership types into a separate file, exported from types.ts
---------
Co-authored-by: Stanislav Demydiuk <s.demydiuk@gmail.com>
* ignore memberships of users that are not in the call
Signed-off-by: Timo K <toger5@hotmail.de>
* recompute memberships on room member change.
Signed-off-by: Timo K <toger5@hotmail.de>
* fix Tests and add test for left member
Signed-off-by: Timo K <toger5@hotmail.de>
* fix event type
Signed-off-by: Timo K <toger5@hotmail.de>
* fix import desaster
Signed-off-by: Timo K <toger5@hotmail.de>
* fix mocks
Signed-off-by: Timo K <toger5@hotmail.de>
---------
Signed-off-by: Timo K <toger5@hotmail.de>
* add expire_ts compatibility to matrixRTC
Signed-off-by: Timo K <toger5@hotmail.de>
* add expire_ts
Signed-off-by: Timo K <toger5@hotmail.de>
* rename expire_ts -> expires_ts
Signed-off-by: Timo K <toger5@hotmail.de>
* allow events without `expires`
Signed-off-by: Timo K <toger5@hotmail.de>
* fix test for expires_ts
Signed-off-by: Timo K <toger5@hotmail.de>
* comment clarification
Signed-off-by: Timo K <toger5@hotmail.de>
* add comment where one needs to use the origin_server_ts
Signed-off-by: Timo K <toger5@hotmail.de>
* add additional expires_ts tests
Signed-off-by: Timo K <toger5@hotmail.de>
* fix fake timer
Signed-off-by: Timo K <toger5@hotmail.de>
* change priority order to favor expires
Signed-off-by: Timo K <toger5@hotmail.de>
---------
Signed-off-by: Timo K <toger5@hotmail.de>
* Add CallNotifyEvent to support matrix rtc ringing
Signed-off-by: Timo K <toger5@hotmail.de>
* test SessionId
Signed-off-by: Timo K <toger5@hotmail.de>
* docs + sessionId->callId
Signed-off-by: Timo K <toger5@hotmail.de>
---------
Signed-off-by: Timo K <toger5@hotmail.de>