@@ -45,6 +45,7 @@ import { type JitsiCallMemberContent, JitsiCallMemberEventType } from "../call-t
4545import SdkConfig from "../SdkConfig.ts" ;
4646import RoomListStore from "../stores/room-list/RoomListStore.ts" ;
4747import { DefaultTagID } from "../stores/room-list/models.ts" ;
48+ import { getJoinedNonFunctionalMembers } from "../utils/room/getJoinedNonFunctionalMembers.ts" ;
4849
4950const TIMEOUT_MS = 16000 ;
5051
@@ -542,6 +543,13 @@ export class JitsiCall extends Call {
542543 } ;
543544}
544545
546+ export enum ElementCallIntent {
547+ StartCall = 'start_call' ,
548+ JoinExisting = 'join_existing' ,
549+ StartCallDM = 'start_call_dm' ,
550+ JoinExistingDM = 'join_existing_dm' ,
551+ }
552+
545553/**
546554 * A group call using MSC3401 and Element Call as a backend.
547555 * (somewhat cheekily named)
@@ -560,7 +568,7 @@ export class ElementCall extends Call {
560568 this . checkDestroy ( ) ;
561569 }
562570
563- private static generateWidgetUrl ( client : MatrixClient , roomId : string ) : URL {
571+ private static generateWidgetUrl ( client : MatrixClient , roomId : string , intent ?: ElementCallIntent ) : URL {
564572 const baseUrl = window . location . href ;
565573 let url = new URL ( "./widgets/element-call/index.html#" , baseUrl ) ; // this strips hash fragment from baseUrl
566574
@@ -582,6 +590,7 @@ export class ElementCall extends Call {
582590 lang : getCurrentLanguage ( ) . replace ( "_" , "-" ) ,
583591 fontScale : ( FontWatcher . getRootFontSize ( ) / FontWatcher . getBrowserDefaultFontSize ( ) ) . toString ( ) ,
584592 theme : "$org.matrix.msc2873.client_theme" ,
593+ ...( intent && { intent } )
585594 } ) ;
586595
587596 const room = client . getRoom ( roomId ) ;
@@ -672,9 +681,24 @@ export class ElementCall extends Call {
672681 return ecWidget ;
673682 }
674683
684+ let intent : ElementCallIntent | undefined ;
685+ const room = client . getRoom ( roomId ) ;
686+ const functionalMembers = room && getJoinedNonFunctionalMembers ( room ) ;
687+ const isDm = functionalMembers ? functionalMembers . length === 2 : false ;
688+
689+ if ( room && isDm ) {
690+ const oldestMembership = client . matrixRTC . getRoomSession ( room ) . getOldestMembership ( ) ;
691+ if ( ! oldestMembership ) {
692+ // We are starting a call
693+ intent = ElementCallIntent . StartCallDM ;
694+ } else if ( oldestMembership . sender !== client . getSafeUserId ( ) ) {
695+ intent = ElementCallIntent . JoinExistingDM ;
696+ } // else, the call is ongoing but it was from us so just handle as normal.
697+ }
698+
675699 // To use Element Call without touching room state, we create a virtual
676700 // widget (one that doesn't have a corresponding state event)
677- const url = ElementCall . generateWidgetUrl ( client , roomId ) ;
701+ const url = ElementCall . generateWidgetUrl ( client , roomId , intent ) ;
678702 const createdWidget = WidgetStore . instance . addVirtualWidget (
679703 {
680704 id : secureRandomString ( 24 ) , // So that it's globally unique
0 commit comments