@@ -27,7 +27,13 @@ import { KnownMembership } from "../@types/membership.ts";
2727import { MembershipManager } from "./MembershipManager.ts" ;
2828import { EncryptionManager , type IEncryptionManager } from "./EncryptionManager.ts" ;
2929import { deepCompare , logDurationSync } from "../utils.ts" ;
30- import { type Statistics , type RTCNotificationType , type Status } from "./types.ts" ;
30+ import {
31+ type Statistics ,
32+ type RTCNotificationType ,
33+ type Status ,
34+ type IRTCNotificationContent ,
35+ type ICallNotifyContent ,
36+ } from "./types.ts" ;
3137import { RoomKeyTransport } from "./RoomKeyTransport.ts" ;
3238import {
3339 MembershipManagerEvent ,
@@ -42,6 +48,7 @@ import {
4248} from "./RoomAndToDeviceKeyTransport.ts" ;
4349import { TypedReEmitter } from "../ReEmitter.ts" ;
4450import { ToDeviceKeyTransport } from "./ToDeviceKeyTransport.ts" ;
51+ import { type ISendEventResponse } from "src/matrix.ts" ;
4552
4653export enum MatrixRTCSessionEvent {
4754 // A member joined, left, or updated a property of their membership.
@@ -54,6 +61,8 @@ export enum MatrixRTCSessionEvent {
5461 EncryptionKeyChanged = "encryption_key_changed" ,
5562 /** The membership manager had to shut down caused by an unrecoverable error */
5663 MembershipManagerError = "membership_manager_error" ,
64+ /** The RTCSession did send a call notification caused by joining the call as the first member */
65+ DidSendCallNotification = "did_send_call_notification" ,
5766}
5867
5968export type MatrixRTCSessionEventHandlerMap = {
@@ -68,6 +77,10 @@ export type MatrixRTCSessionEventHandlerMap = {
6877 participantId : string ,
6978 ) => void ;
7079 [ MatrixRTCSessionEvent . MembershipManagerError ] : ( error : unknown ) => void ;
80+ [ MatrixRTCSessionEvent . DidSendCallNotification ] : (
81+ notificationContentNew : IRTCNotificationContent ,
82+ notificationContentLegacy : ICallNotifyContent ,
83+ ) => void ;
7184} ;
7285
7386export interface SessionConfig {
@@ -652,19 +665,24 @@ export class MatrixRTCSession extends TypedEventEmitter<
652665 * Sends a notification corresponding to the configured notify type.
653666 */
654667 private sendCallNotify ( parentEventId : string , notificationType : RTCNotificationType ) : void {
655- // Send legacy event:
656- this . client
657- . sendEvent ( this . roomSubset . roomId , EventType . CallNotify , {
668+ const sendLegacyNotificationEvent = async ( ) : Promise < {
669+ response : ISendEventResponse ;
670+ content : ICallNotifyContent ;
671+ } > => {
672+ const content : ICallNotifyContent = {
658673 "application" : "m.call" ,
659674 "m.mentions" : { user_ids : [ ] , room : true } ,
660675 "notify_type" : notificationType === "notification" ? "notify" : notificationType ,
661676 "call_id" : this . callId ! ,
662- } )
663- . catch ( ( e ) => this . logger . error ( "Failed to send call notification" , e ) ) ;
664-
665- // Send new event:
666- this . client
667- . sendEvent ( this . roomSubset . roomId , EventType . RTCNotification , {
677+ } ;
678+ const response = await this . client . sendEvent ( this . roomSubset . roomId , EventType . CallNotify , content ) ;
679+ return { response, content } ;
680+ } ;
681+ const sendNewNotificationEvent = async ( ) : Promise < {
682+ response : ISendEventResponse ;
683+ content : IRTCNotificationContent ;
684+ } > => {
685+ const content : IRTCNotificationContent = {
668686 "m.mentions" : { user_ids : [ ] , room : true } ,
669687 "notification_type" : notificationType ,
670688 "m.relates_to" : {
@@ -673,8 +691,21 @@ export class MatrixRTCSession extends TypedEventEmitter<
673691 } ,
674692 "sender_ts" : Date . now ( ) ,
675693 "lifetime" : 30_000 , // 30 seconds
694+ } ;
695+ const response = await this . client . sendEvent ( this . roomSubset . roomId , EventType . RTCNotification , content ) ;
696+ return { response, content } ;
697+ } ;
698+
699+ void Promise . all ( [ sendLegacyNotificationEvent ( ) , sendNewNotificationEvent ( ) ] )
700+ . then ( ( [ legacy , newNotification ] ) => {
701+ // Join event_id and origin event content
702+ const legacyResult = { ...legacy . response , ...legacy . content } ;
703+ const newResult = { ...newNotification . response , ...newNotification . content } ;
704+ this . emit ( MatrixRTCSessionEvent . DidSendCallNotification , newResult , legacyResult ) ;
676705 } )
677- . catch ( ( e ) => this . logger . error ( "Failed to send call notification" , e ) ) ;
706+ . catch ( ( [ errorLegacy , errorNew ] ) =>
707+ this . logger . error ( "Failed to send call notification" , errorLegacy , errorNew ) ,
708+ ) ;
678709 }
679710
680711 /**
0 commit comments