-
Notifications
You must be signed in to change notification settings - Fork 158
Make Element Call widgets compatible with Matrix 2.0 mode #3686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+196
−30
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /* | ||
| Copyright 2026 New Vector Ltd. | ||
|
|
||
| SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial | ||
| Please see LICENSE in the repository root for full details. | ||
| */ | ||
|
|
||
| import { beforeAll, describe, expect, vi, it } from "vitest"; | ||
| import { createRoomWidgetClient, EventType } from "matrix-js-sdk"; | ||
|
|
||
| import { getUrlParams } from "./UrlParams"; | ||
| import { initializeWidget, widget } from "./widget"; | ||
| import { Config } from "./config/Config"; | ||
| import { ElementCallReactionEventType } from "./reactions"; | ||
|
|
||
| vi.mock("matrix-js-sdk", { spy: true }); | ||
| const createRoomWidgetClientSpy = vi.mocked(createRoomWidgetClient); | ||
|
|
||
| vi.mock("./config/Config", () => ({ | ||
| Config: { | ||
| init: vi.fn().mockImplementation(async () => Promise.resolve()), | ||
| }, | ||
| })); | ||
| const configInitSpy = vi.mocked(Config.init); | ||
|
|
||
| vi.mock("./UrlParams", () => ({ | ||
| getUrlParams: vi.fn(() => ({ | ||
| widgetId: "id", | ||
| parentUrl: "http://parentUrl", | ||
| roomId: "room", | ||
| userId: "myYser", | ||
| deviceId: "AAAAA", | ||
| baseUrl: "http://baseUrl", | ||
| e2eEnabled: true, | ||
| })), | ||
| })); | ||
|
|
||
| initializeWidget(); | ||
| describe("widget", () => { | ||
| beforeAll(() => {}); | ||
|
|
||
| it("should create an embedded client with the correct params", () => { | ||
| expect(getUrlParams()).toStrictEqual({ | ||
| widgetId: "id", | ||
| parentUrl: "http://parentUrl", | ||
| roomId: "room", | ||
| userId: "myYser", | ||
| deviceId: "AAAAA", | ||
| baseUrl: "http://baseUrl", | ||
| e2eEnabled: true, | ||
| }); | ||
| expect(widget).toBeDefined(); | ||
| expect(configInitSpy).toHaveBeenCalled(); | ||
| const sendEvent = [ | ||
| EventType.CallNotify, // Sent as a deprecated fallback | ||
| EventType.RTCNotification, | ||
| ]; | ||
| const sendRecvEvent = [ | ||
| "org.matrix.rageshake_request", | ||
| EventType.CallEncryptionKeysPrefix, | ||
| EventType.Reaction, | ||
| EventType.RoomRedaction, | ||
| ElementCallReactionEventType, | ||
| EventType.RTCDecline, | ||
| EventType.RTCMembership, | ||
| ]; | ||
|
|
||
| const sendState = [ | ||
| "myYser", // Legacy call membership events | ||
| `_myYser_AAAAA_m.call`, // Session membership events | ||
| `myYser_AAAAA_m.call`, // The above with no leading underscore, for room versions whose auth rules allow it | ||
| ].map((stateKey) => ({ | ||
| eventType: EventType.GroupCallMemberPrefix, | ||
| stateKey, | ||
| })); | ||
| const receiveState = [ | ||
| { eventType: EventType.RoomCreate }, | ||
| { eventType: EventType.RoomName }, | ||
| { eventType: EventType.RoomMember }, | ||
| { eventType: EventType.RoomEncryption }, | ||
| { eventType: EventType.GroupCallMemberPrefix }, | ||
| ]; | ||
|
|
||
| const sendRecvToDevice = [ | ||
| EventType.CallInvite, | ||
| EventType.CallCandidates, | ||
| EventType.CallAnswer, | ||
| EventType.CallHangup, | ||
| EventType.CallReject, | ||
| EventType.CallSelectAnswer, | ||
| EventType.CallNegotiate, | ||
| EventType.CallSDPStreamMetadataChanged, | ||
| EventType.CallSDPStreamMetadataChangedPrefix, | ||
| EventType.CallReplaces, | ||
| EventType.CallEncryptionKeysPrefix, | ||
| ]; | ||
|
|
||
| expect(createRoomWidgetClientSpy.mock.calls[0][1]).toStrictEqual({ | ||
| sendEvent: [...sendEvent, ...sendRecvEvent], | ||
| receiveEvent: sendRecvEvent, | ||
| sendState, | ||
| receiveState, | ||
| sendToDevice: sendRecvToDevice, | ||
| receiveToDevice: sendRecvToDevice, | ||
| turnServers: false, | ||
| sendDelayedEvents: true, | ||
| updateDelayedEvents: true, | ||
| sendSticky: true, | ||
| receiveSticky: true, | ||
| }); | ||
|
|
||
| expect(createRoomWidgetClientSpy.mock.calls[0][2]).toStrictEqual("room"); | ||
| expect(createRoomWidgetClientSpy.mock.calls[0][3]).toStrictEqual({ | ||
| baseUrl: "http://baseUrl", | ||
| userId: "myYser", | ||
| deviceId: "AAAAA", | ||
| timelineSupport: true, | ||
| useE2eForGroupCall: true, | ||
| fallbackICEServerAllowed: undefined, | ||
| store: expect.any(Object), | ||
| cryptoStore: expect.any(Object), | ||
| idBaseUrl: undefined, | ||
| scheduler: expect.any(Object), | ||
| }); | ||
| expect(createRoomWidgetClientSpy.mock.calls[0][4]).toStrictEqual(false); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@BillCarsonFr For the record this is what I was referring to with the test being a close copy of the code: The obvious way to write it has all the same lists from
widget.tsduplicated here, with anexpectat the end rather than a function call.My take is that writing tests like this is busywork, since they don't tell the reviewer anything that they wouldn't have already known from reading the source file. In general my attitude toward tests - maybe an unpopular opinion :) - is that properties of code that are trivial or self-evident do not need testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also can get behind that. But there is some hardcoded values in there that we also check.
I was considering just writing down the full list as raw strings. But for the sake of time made it like that.
But what makes this a bit of a maintenance. burden also has the advantage, that if I mess around with the widget file, the test will force me to rethink if that is what I actually want to do.