Skip to content

Commit 5b21691

Browse files
authored
Merge pull request #3544 from element-hq/valere/fix_hangup
Fix: widget hangup action not working
2 parents 5e0a3f3 + 23bcb57 commit 5b21691

File tree

3 files changed

+73
-3
lines changed

3 files changed

+73
-3
lines changed

src/state/CallViewModel.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ interface CallViewModelInputs {
281281
initialSyncState: SyncState;
282282
}
283283

284-
function withCallViewModel(
284+
export function withCallViewModel(
285285
{
286286
remoteParticipants$ = constant([]),
287287
rtcMembers$ = constant([localRtcMember]),

src/state/CallViewModel.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,8 +1053,12 @@ export class CallViewModel {
10531053
fromEvent(
10541054
widget.lazyActions,
10551055
ElementWidgetActions.HangupCall,
1056-
) as Observable<[CustomEvent<IWidgetApiRequest>]>
1057-
).pipe(tap(([ev]) => widget!.api.transport.reply(ev.detail, {})));
1056+
) as Observable<CustomEvent<IWidgetApiRequest>>
1057+
).pipe(
1058+
tap((ev) => {
1059+
widget!.api.transport.reply(ev.detail, {});
1060+
}),
1061+
);
10581062

10591063
public readonly leave$: Observable<
10601064
"user" | "timeout" | "decline" | "allOthersLeft"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
Copyright 2025 Element Creations Ltd.
3+
4+
SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
5+
Please see LICENSE in the repository root for full details.
6+
*/
7+
8+
import { test, vi, expect } from "vitest";
9+
import EventEmitter from "events";
10+
11+
import { constant } from "./Behavior.ts";
12+
import { withCallViewModel } from "./CallViewModel.test.ts";
13+
import { aliceParticipant, localRtcMember } from "../utils/test-fixtures.ts";
14+
import { ElementWidgetActions, widget } from "../widget.ts";
15+
import { E2eeType } from "../e2ee/e2eeType.ts";
16+
import { type CallViewModel } from "./CallViewModel.ts";
17+
18+
vi.mock("../widget", () => ({
19+
ElementWidgetActions: {
20+
HangupCall: "HangupCall",
21+
// Add other actions if needed
22+
},
23+
widget: {
24+
api: {
25+
transport: {
26+
send: vi.fn().mockResolvedValue(undefined),
27+
reply: vi.fn().mockResolvedValue(undefined),
28+
},
29+
},
30+
lazyActions: new EventEmitter(),
31+
},
32+
}));
33+
34+
test("expect leave when ElementWidgetActions.HangupCall is called", async () => {
35+
const pr = Promise.withResolvers<string>();
36+
withCallViewModel(
37+
{
38+
remoteParticipants$: constant([aliceParticipant]),
39+
rtcMembers$: constant([localRtcMember]),
40+
},
41+
(vm: CallViewModel) => {
42+
vm.leave$.subscribe((s: string) => {
43+
pr.resolve(s);
44+
});
45+
46+
widget!.lazyActions!.emit(
47+
ElementWidgetActions.HangupCall,
48+
new CustomEvent(ElementWidgetActions.HangupCall, {
49+
detail: {
50+
action: "im.vector.hangup",
51+
api: "toWidget",
52+
data: {},
53+
requestId: "widgetapi-1761237395918",
54+
widgetId: "mrUjS9T6uKUOWHMxXvLbSv0F",
55+
},
56+
}),
57+
);
58+
},
59+
{
60+
encryptionSystem: { kind: E2eeType.PER_PARTICIPANT },
61+
},
62+
);
63+
64+
const source = await pr.promise;
65+
expect(source).toBe("user");
66+
});

0 commit comments

Comments
 (0)