Skip to content

Commit 739b8e1

Browse files
authored
Remove sending of deprecated notify event (we now use (#5167)
`m.rtc.notification`
1 parent bc57a3f commit 739b8e1

File tree

2 files changed

+30
-82
lines changed

2 files changed

+30
-82
lines changed

spec/unit/matrixrtc/MatrixRTCSession.spec.ts

Lines changed: 25 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,7 @@ describe("MatrixRTCSession", () => {
620620
it("sends a notification when starting a call and emit DidSendCallNotification", async () => {
621621
// Simulate a join, including the update to the room state
622622
// Ensure sendEvent returns event IDs so the DidSendCallNotification payload includes them
623-
sendEventMock
624-
.mockResolvedValueOnce({ event_id: "legacy-evt" })
625-
.mockResolvedValueOnce({ event_id: "new-evt" });
623+
sendEventMock.mockResolvedValueOnce({ event_id: "new-evt" });
626624
const didSendEventFn = vi.fn();
627625
sess!.once(MatrixRTCSessionEvent.DidSendCallNotification, didSendEventFn);
628626
// Create an additional listener to create a promise that resolves after the emission.
@@ -647,43 +645,25 @@ describe("MatrixRTCSession", () => {
647645
"sender_ts": expect.any(Number),
648646
});
649647

650-
// Check if deprecated notify event is also sent.
651-
expect(client.sendEvent).toHaveBeenCalledWith(mockRoom!.roomId, EventType.CallNotify, {
652-
"application": "m.call",
653-
"m.mentions": { user_ids: [], room: true },
654-
"notify_type": "ring",
655-
"call_id": "",
656-
});
657648
await didSendNotification;
658649
// And ensure we emitted the DidSendCallNotification event with both payloads
659-
expect(didSendEventFn).toHaveBeenCalledWith(
660-
{
661-
"event_id": "new-evt",
662-
"lifetime": 30000,
663-
"m.mentions": { room: true, user_ids: [] },
664-
"m.relates_to": {
665-
event_id: expect.any(String),
666-
rel_type: "m.reference",
667-
},
668-
"notification_type": "ring",
669-
"sender_ts": expect.any(Number),
670-
},
671-
{
672-
"application": "m.call",
673-
"call_id": "",
674-
"event_id": "legacy-evt",
675-
"m.mentions": { room: true, user_ids: [] },
676-
"notify_type": "ring",
650+
expect(didSendEventFn).toHaveBeenCalledWith({
651+
"event_id": "new-evt",
652+
"lifetime": 30000,
653+
"m.mentions": { room: true, user_ids: [] },
654+
"m.relates_to": {
655+
event_id: expect.any(String),
656+
rel_type: "m.reference",
677657
},
678-
);
658+
"notification_type": "ring",
659+
"sender_ts": expect.any(Number),
660+
});
679661
});
680662

681663
it("sends a notification with a intent when starting a call and emits DidSendCallNotification", async () => {
682664
// Simulate a join, including the update to the room state
683665
// Ensure sendEvent returns event IDs so the DidSendCallNotification payload includes them
684-
sendEventMock
685-
.mockResolvedValueOnce({ event_id: "legacy-evt" })
686-
.mockResolvedValueOnce({ event_id: "new-evt" });
666+
sendEventMock.mockResolvedValueOnce({ event_id: "new-evt" });
687667
const didSendEventFn = vi.fn();
688668
sess!.once(MatrixRTCSessionEvent.DidSendCallNotification, didSendEventFn);
689669
// Create an additional listener to create a promise that resolves after the emission.
@@ -707,51 +687,35 @@ describe("MatrixRTCSession", () => {
707687
]);
708688

709689
await sess!._onRTCSessionMemberUpdate();
710-
const ownMembershipId = sess?.memberships[0].eventId;
690+
const ownMembershipEventId = sess?.memberships[0].eventId;
711691
expect(sess!.getConsensusCallIntent()).toEqual("audio");
712692

713693
expect(client.sendEvent).toHaveBeenCalledWith(mockRoom!.roomId, EventType.RTCNotification, {
714694
"m.mentions": { user_ids: [], room: true },
715695
"notification_type": "ring",
716696
"m.call.intent": "audio",
717697
"m.relates_to": {
718-
event_id: ownMembershipId,
698+
event_id: ownMembershipEventId,
719699
rel_type: "m.reference",
720700
},
721701
"lifetime": 30000,
722702
"sender_ts": expect.any(Number),
723703
});
724704

725-
// Check if deprecated notify event is also sent.
726-
expect(client.sendEvent).toHaveBeenCalledWith(mockRoom!.roomId, EventType.CallNotify, {
727-
"application": "m.call",
728-
"m.mentions": { user_ids: [], room: true },
729-
"notify_type": "ring",
730-
"call_id": "",
731-
});
732705
await didSendNotification;
733706
// And ensure we emitted the DidSendCallNotification event with both payloads
734-
expect(didSendEventFn).toHaveBeenCalledWith(
735-
{
736-
"event_id": "new-evt",
737-
"lifetime": 30000,
738-
"m.mentions": { room: true, user_ids: [] },
739-
"m.relates_to": {
740-
event_id: expect.any(String),
741-
rel_type: "m.reference",
742-
},
743-
"notification_type": "ring",
744-
"m.call.intent": "audio",
745-
"sender_ts": expect.any(Number),
746-
},
747-
{
748-
"application": "m.call",
749-
"call_id": "",
750-
"event_id": "legacy-evt",
751-
"m.mentions": { room: true, user_ids: [] },
752-
"notify_type": "ring",
707+
expect(didSendEventFn).toHaveBeenCalledWith({
708+
"event_id": "new-evt",
709+
"lifetime": 30000,
710+
"m.mentions": { room: true, user_ids: [] },
711+
"m.relates_to": {
712+
event_id: expect.any(String),
713+
rel_type: "m.reference",
753714
},
754-
);
715+
"notification_type": "ring",
716+
"m.call.intent": "audio",
717+
"sender_ts": expect.any(Number),
718+
});
755719
});
756720

757721
it("doesn't send a notification when joining an existing call", async () => {

src/matrixrtc/MatrixRTCSession.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import type {
3232
RTCNotificationType,
3333
Status,
3434
IRTCNotificationContent,
35-
ICallNotifyContent,
3635
RTCCallIntent,
3736
Transport,
3837
} from "./types.ts";
@@ -81,7 +80,6 @@ export type MatrixRTCSessionEventHandlerMap = {
8180
[MatrixRTCSessionEvent.MembershipManagerError]: (error: unknown) => void;
8281
[MatrixRTCSessionEvent.DidSendCallNotification]: (
8382
notificationContentNew: { event_id: string } & IRTCNotificationContent,
84-
notificationContentLegacy: { event_id: string } & ICallNotifyContent,
8583
) => void;
8684
};
8785

@@ -713,20 +711,7 @@ export class MatrixRTCSession extends TypedEventEmitter<
713711
notificationType: RTCNotificationType,
714712
callIntent?: RTCCallIntent,
715713
): void {
716-
const sendLegacyNotificationEvent = async (): Promise<{
717-
response: ISendEventResponse;
718-
content: ICallNotifyContent;
719-
}> => {
720-
const content: ICallNotifyContent = {
721-
"application": "m.call",
722-
"m.mentions": { user_ids: [], room: true },
723-
"notify_type": notificationType === "notification" ? "notify" : notificationType,
724-
"call_id": this.callId!,
725-
};
726-
const response = await this.client.sendEvent(this.roomSubset.roomId, EventType.CallNotify, content);
727-
return { response, content };
728-
};
729-
const sendNewNotificationEvent = async (): Promise<{
714+
const sendNotificationEvent = async (): Promise<{
730715
response: ISendEventResponse;
731716
content: IRTCNotificationContent;
732717
}> => {
@@ -747,12 +732,11 @@ export class MatrixRTCSession extends TypedEventEmitter<
747732
return { response, content };
748733
};
749734

750-
void Promise.all([sendLegacyNotificationEvent(), sendNewNotificationEvent()])
751-
.then(([legacy, newNotification]) => {
735+
void sendNotificationEvent()
736+
.then((notification) => {
752737
// Join event_id and origin event content
753-
const legacyResult = { ...legacy.response, ...legacy.content };
754-
const newResult = { ...newNotification.response, ...newNotification.content };
755-
this.emit(MatrixRTCSessionEvent.DidSendCallNotification, newResult, legacyResult);
738+
const newResult = { ...notification.response, ...notification.content };
739+
this.emit(MatrixRTCSessionEvent.DidSendCallNotification, newResult);
756740
})
757741
.catch(([errorLegacy, errorNew]) =>
758742
this.logger.error("Failed to send call notification", errorLegacy, errorNew),

0 commit comments

Comments
 (0)