@@ -19,15 +19,15 @@ import { TypedEventEmitter } from "../models/typed-event-emitter.ts";
19
19
import { EventTimeline } from "../models/event-timeline.ts" ;
20
20
import { type Room } from "../models/room.ts" ;
21
21
import { type MatrixClient } from "../client.ts" ;
22
- import { EventType } from "../@types/event.ts" ;
22
+ import { EventType , RelationType } from "../@types/event.ts" ;
23
23
import { CallMembership } from "./CallMembership.ts" ;
24
24
import { RoomStateEvent } from "../models/room-state.ts" ;
25
25
import { type Focus } from "./focus.ts" ;
26
26
import { KnownMembership } from "../@types/membership.ts" ;
27
27
import { MembershipManager } from "./MembershipManager.ts" ;
28
28
import { EncryptionManager , type IEncryptionManager } from "./EncryptionManager.ts" ;
29
29
import { logDurationSync } from "../utils.ts" ;
30
- import { type Statistics , type CallNotifyType , isMyMembership } from "./types.ts" ;
30
+ import { type Statistics , type RTCNotificationType } from "./types.ts" ;
31
31
import { RoomKeyTransport } from "./RoomKeyTransport.ts" ;
32
32
import type { IMembershipManager } from "./IMembershipManager.ts" ;
33
33
import { RTCEncryptionManager } from "./RTCEncryptionManager.ts" ;
@@ -71,7 +71,7 @@ export interface SessionConfig {
71
71
* What kind of notification to send when starting the session.
72
72
* @default `undefined` (no notification)
73
73
*/
74
- notificationType ?: CallNotifyType ;
74
+ notificationType ?: Exclude < RTCNotificationType , "decline" > ;
75
75
}
76
76
77
77
// The names follow these principles:
@@ -562,16 +562,32 @@ export class MatrixRTCSession extends TypedEventEmitter<
562
562
/**
563
563
* Sends a notification corresponding to the configured notify type.
564
564
*/
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
+
567
570
this . client
568
571
. sendEvent ( this . roomSubset . roomId , EventType . CallNotify , {
569
572
"application" : "m.call" ,
570
573
"m.mentions" : { user_ids : [ ] , room : true } ,
571
- "notify_type" : this . joinConfig . notificationType ,
574
+ "notify_type" : notificationType === "notification" ? "notify" : notificationType ,
572
575
"call_id" : this . callId ! ,
573
576
} )
574
577
. 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 ) ) ;
575
591
}
576
592
}
577
593
0 commit comments