From 5df083f009ff26416f4b051e78868d48e7502a59 Mon Sep 17 00:00:00 2001 From: Robin Date: Thu, 13 Mar 2025 15:45:10 -0400 Subject: [PATCH] Stop sending call notification events Since I'd like Element Web to stop doing any more inspection than it needs to into the MatrixRTC session state, I suggest we move all responsibility for sending MatrixRTC events to Element Call. --- src/models/Call.ts | 31 +---------------------------- test/unit-tests/models/Call-test.ts | 25 ----------------------- 2 files changed, 1 insertion(+), 55 deletions(-) diff --git a/src/models/Call.ts b/src/models/Call.ts index 04dc5da716..65722954ee 100644 --- a/src/models/Call.ts +++ b/src/models/Call.ts @@ -23,11 +23,9 @@ import { CallType } from "matrix-js-sdk/src/webrtc/call"; import { NamespacedValue } from "matrix-js-sdk/src/NamespacedValue"; import { type IWidgetApiRequest, type ClientWidgetApi, type IWidgetData } from "matrix-widget-api"; import { - MatrixRTCSession, + type MatrixRTCSession, MatrixRTCSessionEvent, - type CallMembership, MatrixRTCSessionManagerEvents, - type ICallNotifyContent, } from "matrix-js-sdk/src/matrixrtc"; import type EventEmitter from "events"; @@ -45,7 +43,6 @@ import ActiveWidgetStore, { ActiveWidgetStoreEvent } from "../stores/ActiveWidge import { getCurrentLanguage } from "../languageHandler"; import { PosthogAnalytics } from "../PosthogAnalytics"; import { UPDATE_EVENT } from "../stores/AsyncStore"; -import { getJoinedNonFunctionalMembers } from "../utils/room/getJoinedNonFunctionalMembers"; import { isVideoRoom } from "../utils/video-rooms"; import { FontWatcher } from "../settings/watchers/FontWatcher"; import { type JitsiCallMemberContent, JitsiCallMemberEventType } from "../call-types"; @@ -830,31 +827,6 @@ export class ElementCall extends Call { ElementCall.createOrGetCallWidget(room.roomId, room.client, skipLobby, isVideoRoom(room)); } - protected async sendCallNotify(): Promise { - const room = this.room; - const existingOtherRoomCallMembers = MatrixRTCSession.callMembershipsForRoom(room).filter( - // filter all memberships where the application is m.call and the call_id is "" - (m) => { - const isRoomCallMember = m.application === "m.call" && m.callId === ""; - const isThisDevice = m.deviceId === this.client.deviceId; - return isRoomCallMember && !isThisDevice; - }, - ); - - const memberCount = getJoinedNonFunctionalMembers(room).length; - if (!isVideoRoom(room) && existingOtherRoomCallMembers.length === 0) { - // send ringing event - const content: ICallNotifyContent = { - "application": "m.call", - "m.mentions": { user_ids: [], room: true }, - "notify_type": memberCount == 2 ? "ring" : "notify", - "call_id": "", - }; - - await room.client.sendEvent(room.roomId, EventType.CallNotify, content); - } - } - protected async performConnection( audioInput: MediaDeviceInfo | null, videoInput: MediaDeviceInfo | null, @@ -884,7 +856,6 @@ export class ElementCall extends Call { false, // allow user to wait as long as they want (no timeout) ); } - this.sendCallNotify(); } protected async performDisconnection(): Promise { diff --git a/test/unit-tests/models/Call-test.ts b/test/unit-tests/models/Call-test.ts index 6954ee14be..cfc94b5370 100644 --- a/test/unit-tests/models/Call-test.ts +++ b/test/unit-tests/models/Call-test.ts @@ -990,31 +990,6 @@ describe("ElementCall", () => { roomSpy.mockRestore(); addWidgetSpy.mockRestore(); }); - - it("sends notify event on connect in a room with more than two members", async () => { - const sendEventSpy = jest.spyOn(room.client, "sendEvent"); - ElementCall.create(room); - await callConnectProcedure(Call.get(room) as ElementCall); - expect(sendEventSpy).toHaveBeenCalledWith("!1:example.org", "org.matrix.msc4075.call.notify", { - "application": "m.call", - "call_id": "", - "m.mentions": { room: true, user_ids: [] }, - "notify_type": "notify", - }); - }); - it("sends ring on create in a DM (two participants) room", async () => { - setRoomMembers(["@user:example.com", "@user2:example.com"]); - - const sendEventSpy = jest.spyOn(room.client, "sendEvent"); - ElementCall.create(room); - await callConnectProcedure(Call.get(room) as ElementCall); - expect(sendEventSpy).toHaveBeenCalledWith("!1:example.org", "org.matrix.msc4075.call.notify", { - "application": "m.call", - "call_id": "", - "m.mentions": { room: true, user_ids: [] }, - "notify_type": "ring", - }); - }); }); describe("instance in a video room", () => {