Skip to content

Commit 3c385a1

Browse files
committed
send new notification event alongside the deprecated one
1 parent 4d19d85 commit 3c385a1

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

src/matrixrtc/MatrixRTCSession.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ import { TypedEventEmitter } from "../models/typed-event-emitter.ts";
1919
import { EventTimeline } from "../models/event-timeline.ts";
2020
import { type Room } from "../models/room.ts";
2121
import { type MatrixClient } from "../client.ts";
22-
import { EventType } from "../@types/event.ts";
22+
import { EventType, RelationType } from "../@types/event.ts";
2323
import { CallMembership } from "./CallMembership.ts";
2424
import { RoomStateEvent } from "../models/room-state.ts";
2525
import { type Focus } from "./focus.ts";
2626
import { KnownMembership } from "../@types/membership.ts";
2727
import { MembershipManager } from "./MembershipManager.ts";
2828
import { EncryptionManager, type IEncryptionManager } from "./EncryptionManager.ts";
2929
import { logDurationSync } from "../utils.ts";
30-
import { type Statistics, type CallNotifyType, isMyMembership } from "./types.ts";
30+
import { type Statistics, type RTCNotificationType } from "./types.ts";
3131
import { RoomKeyTransport } from "./RoomKeyTransport.ts";
3232
import type { IMembershipManager } from "./IMembershipManager.ts";
3333
import { RTCEncryptionManager } from "./RTCEncryptionManager.ts";
@@ -71,7 +71,7 @@ export interface SessionConfig {
7171
* What kind of notification to send when starting the session.
7272
* @default `undefined` (no notification)
7373
*/
74-
notificationType?: CallNotifyType;
74+
notificationType?: Exclude<RTCNotificationType, "decline">;
7575
}
7676

7777
// The names follow these principles:
@@ -562,16 +562,32 @@ export class MatrixRTCSession extends TypedEventEmitter<
562562
/**
563563
* Sends a notification corresponding to the configured notify type.
564564
*/
565-
private sendCallNotify(): void {
566-
if (this.joinConfig?.notificationType !== undefined) {
565+
private sendCallNotify(parentEventId: string): void {
566+
const notificationType = this.joinConfig?.notificationType;
567+
if (notificationType !== undefined) {
568+
// Send legacy event:
569+
567570
this.client
568571
.sendEvent(this.roomSubset.roomId, EventType.CallNotify, {
569572
"application": "m.call",
570573
"m.mentions": { user_ids: [], room: true },
571-
"notify_type": this.joinConfig.notificationType,
574+
"notify_type": notificationType === "notification" ? "notify" : notificationType,
572575
"call_id": this.callId!,
573576
})
574577
.catch((e) => this.logger.error("Failed to send call notification", e));
578+
// Send new event:
579+
this.client
580+
.sendEvent(this.roomSubset.roomId, EventType.RTCNotification, {
581+
"m.mentions": { user_ids: [], room: true },
582+
"notification_type": notificationType,
583+
"m.relates_to": {
584+
event_id: parentEventId,
585+
rel_type: RelationType.unstable_RTCParentEvent,
586+
},
587+
"sender_ts": Date.now(),
588+
"lifetime": 30_000, // 30 seconds
589+
})
590+
.catch((e) => this.logger.error("Failed to send call notification", e));
575591
}
576592
}
577593

0 commit comments

Comments
 (0)