@@ -27,7 +27,13 @@ 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 { 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" ;
31
37
import { RoomKeyTransport } from "./RoomKeyTransport.ts" ;
32
38
import {
33
39
MembershipManagerEvent ,
@@ -42,6 +48,7 @@ import {
42
48
} from "./RoomAndToDeviceKeyTransport.ts" ;
43
49
import { TypedReEmitter } from "../ReEmitter.ts" ;
44
50
import { ToDeviceKeyTransport } from "./ToDeviceKeyTransport.ts" ;
51
+ import { type ISendEventResponse } from "src/matrix.ts" ;
45
52
46
53
export enum MatrixRTCSessionEvent {
47
54
// A member joined, left, or updated a property of their membership.
@@ -54,6 +61,8 @@ export enum MatrixRTCSessionEvent {
54
61
EncryptionKeyChanged = "encryption_key_changed" ,
55
62
/** The membership manager had to shut down caused by an unrecoverable error */
56
63
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" ,
57
66
}
58
67
59
68
export type MatrixRTCSessionEventHandlerMap = {
@@ -68,6 +77,10 @@ export type MatrixRTCSessionEventHandlerMap = {
68
77
participantId : string ,
69
78
) => void ;
70
79
[ MatrixRTCSessionEvent . MembershipManagerError ] : ( error : unknown ) => void ;
80
+ [ MatrixRTCSessionEvent . DidSendCallNotification ] : (
81
+ notificationContentNew : IRTCNotificationContent ,
82
+ notificationContentLegacy : ICallNotifyContent ,
83
+ ) => void ;
71
84
} ;
72
85
73
86
export interface SessionConfig {
@@ -652,19 +665,24 @@ export class MatrixRTCSession extends TypedEventEmitter<
652
665
* Sends a notification corresponding to the configured notify type.
653
666
*/
654
667
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 = {
658
673
"application" : "m.call" ,
659
674
"m.mentions" : { user_ids : [ ] , room : true } ,
660
675
"notify_type" : notificationType === "notification" ? "notify" : notificationType ,
661
676
"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 = {
668
686
"m.mentions" : { user_ids : [ ] , room : true } ,
669
687
"notification_type" : notificationType ,
670
688
"m.relates_to" : {
@@ -673,8 +691,21 @@ export class MatrixRTCSession extends TypedEventEmitter<
673
691
} ,
674
692
"sender_ts" : Date . now ( ) ,
675
693
"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 ) ;
676
705
} )
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
+ ) ;
678
709
}
679
710
680
711
/**
0 commit comments