@@ -6,8 +6,8 @@ import type { IDDPMessage } from '../../../definitions/IDDPMessage';
66import Navigation from '../../navigation/appNavigation' ;
77import { getDMSubscriptionByUsername } from '../../database/services/Subscription' ;
88import { getUidDirectMessage } from '../../methods/helpers/helpers' ;
9- import { mediaSessionStore } from './MediaSessionStore' ;
109import { mediaSessionInstance } from './MediaSessionInstance' ;
10+ import { mediaSessionStore } from './MediaSessionStore' ;
1111
1212jest . mock ( '../../database/services/Subscription' , ( ) => ( {
1313 getDMSubscriptionByUsername : jest . fn ( )
@@ -51,6 +51,11 @@ jest.mock('../sdk', () => ({
5151 }
5252} ) ) ;
5353
54+ const mockMediaCallsStateSignals = jest . fn ( ( ) => Promise . resolve ( { signals : [ ] } ) ) ;
55+ jest . mock ( '../../services/restApi' , ( ) => ( {
56+ mediaCallsStateSignals : ( ...args : unknown [ ] ) => mockMediaCallsStateSignals ( ...args )
57+ } ) ) ;
58+
5459jest . mock ( '../../store/auxStore' , ( ) => ( {
5560 store : {
5661 getState : jest . fn ( ( ) => ( {
@@ -78,28 +83,31 @@ jest.mock('react-native-callkeep', () => ({
7883} ) ) ;
7984
8085jest . mock ( 'react-native-device-info' , ( ) => ( {
81- getUniqueId : jest . fn ( ( ) => 'test-device-id' ) ,
82- getUniqueIdSync : jest . fn ( ( ) => 'test-device-id' ) ,
83- getSystemVersion : jest . fn ( ( ) => '15.0' ) ,
84- getVersion : jest . fn ( ( ) => '4.0.0' ) ,
85- getBuildNumber : jest . fn ( ( ) => '1' ) ,
86- hasNotch : jest . fn ( ( ) => false ) ,
87- getReadableVersion : jest . fn ( ( ) => '4.0.0.1' ) ,
88- getBundleId : jest . fn ( ( ) => 'com.rocket.chat' ) ,
89- getModel : jest . fn ( ( ) => 'iPhone' ) ,
90- isTablet : jest . fn ( ( ) => false ) ,
86+ __esModule : true ,
9187 default : {
9288 getUniqueId : jest . fn ( ( ) => 'test-device-id' ) ,
9389 getUniqueIdSync : jest . fn ( ( ) => 'test-device-id' ) ,
9490 getSystemVersion : jest . fn ( ( ) => '15.0' ) ,
9591 getVersion : jest . fn ( ( ) => '4.0.0' ) ,
9692 getBuildNumber : jest . fn ( ( ) => '1' ) ,
9793 hasNotch : jest . fn ( ( ) => false ) ,
98- getReadableVersion : jest . fn ( ( ) => '4.0.0.1 ' ) ,
94+ getReadableVersion : jest . fn ( ( ) => '4.0.0' ) ,
9995 getBundleId : jest . fn ( ( ) => 'com.rocket.chat' ) ,
100- getModel : jest . fn ( ( ) => 'iPhone' ) ,
96+ getDeviceModel : jest . fn ( ( ) => 'iPhone 14' ) ,
97+ getModel : jest . fn ( ( ) => 'iPhone 14' ) ,
10198 isTablet : jest . fn ( ( ) => false )
102- }
99+ } ,
100+ getUniqueId : jest . fn ( ( ) => 'test-device-id' ) ,
101+ getUniqueIdSync : jest . fn ( ( ) => 'test-device-id' ) ,
102+ getSystemVersion : jest . fn ( ( ) => '15.0' ) ,
103+ getVersion : jest . fn ( ( ) => '4.0.0' ) ,
104+ getBuildNumber : jest . fn ( ( ) => '1' ) ,
105+ hasNotch : jest . fn ( ( ) => false ) ,
106+ getReadableVersion : jest . fn ( ( ) => '4.0.0' ) ,
107+ getBundleId : jest . fn ( ( ) => 'com.rocket.chat' ) ,
108+ getDeviceModel : jest . fn ( ( ) => 'iPhone 14' ) ,
109+ getModel : jest . fn ( ( ) => 'iPhone 14' ) ,
110+ isTablet : jest . fn ( ( ) => false )
103111} ) ) ;
104112
105113jest . mock ( '../../native/NativeVoip' , ( ) => ( {
@@ -185,21 +193,23 @@ function buildClientMediaCall(options: {
185193 const emitter = { on : jest . fn ( ) , off : jest . fn ( ) , emit : jest . fn ( ) } ;
186194 return {
187195 callId : options . callId ,
188- hidden : options . hidden ?? false ,
189196 localParticipant : {
197+ local : true as const ,
198+ participantId : 'mock-participant-id' ,
199+ actorType : 'user' as const ,
200+ actorId : 'mock-actor-id' ,
190201 role : options . role ,
191- contact : { username : 'bob' , sipExtension : '' } ,
192202 muted : false ,
193203 held : false ,
204+ contact : { id : 'u' , displayName : 'U' , username : 'u' , sipExtension : '' } ,
205+ getMediaStream : ( ) => null ,
194206 setMuted : ( ) => { } ,
195207 setHeld : ( ) => { }
196208 } ,
197209 remoteParticipants : [ ] ,
198210 participants : [ ] ,
211+ hidden : options . hidden ?? false ,
199212 reject,
200- accept : jest . fn ( ) ,
201- hangup : jest . fn ( ) ,
202- sendDTMF : jest . fn ( ) ,
203213 emitter : emitter as unknown as IClientMediaCall [ 'emitter' ]
204214 } as unknown as IClientMediaCall ;
205215}
@@ -228,8 +238,8 @@ describe('MediaSessionInstance', () => {
228238 } ) ;
229239
230240 describe ( 'init' , ( ) => {
231- it ( 'should register stream-notify-user listener' , ( ) => {
232- mediaSessionInstance . init ( 'user-1' ) ;
241+ it ( 'should register stream-notify-user listener' , async ( ) => {
242+ await mediaSessionInstance . init ( 'user-1' ) ;
233243 expect ( mockOnStreamData ) . toHaveBeenCalledWith ( 'stream-notify-user' , expect . any ( Function ) ) ;
234244 } ) ;
235245
@@ -537,17 +547,9 @@ describe('MediaSessionInstance', () => {
537547 newCallHandler ( {
538548 call : {
539549 hidden : false ,
550+ role : 'caller' ,
540551 callId : 'c1' ,
541- localParticipant : {
542- role : 'caller' ,
543- contact : { username : 'alice' , sipExtension : '' } ,
544- muted : false ,
545- held : false ,
546- setMuted : ( ) => { } ,
547- setHeld : ( ) => { }
548- } ,
549- remoteParticipants : [ ] ,
550- participants : [ ] ,
552+ contact : { username : 'alice' , sipExtension : '' } ,
551553 emitter : { on : jest . fn ( ) , off : jest . fn ( ) }
552554 } as unknown as IClientMediaCall
553555 } ) ;
@@ -576,17 +578,9 @@ describe('MediaSessionInstance', () => {
576578 newCallHandler ( {
577579 call : {
578580 hidden : false ,
581+ role : 'caller' ,
579582 callId : 'c1' ,
580- localParticipant : {
581- role : 'caller' ,
582- contact : { username : 'alice' , sipExtension : '' } ,
583- muted : false ,
584- held : false ,
585- setMuted : ( ) => { } ,
586- setHeld : ( ) => { }
587- } ,
588- remoteParticipants : [ ] ,
589- participants : [ ] ,
583+ contact : { username : 'alice' , sipExtension : '' } ,
590584 emitter : { on : jest . fn ( ) , off : jest . fn ( ) }
591585 } as unknown as IClientMediaCall
592586 } ) ;
@@ -605,17 +599,9 @@ describe('MediaSessionInstance', () => {
605599 newCallHandler ( {
606600 call : {
607601 hidden : false ,
602+ role : 'caller' ,
608603 callId : 'c1' ,
609- localParticipant : {
610- role : 'caller' ,
611- contact : { username : 'alice' , sipExtension : '100' } ,
612- muted : false ,
613- held : false ,
614- setMuted : ( ) => { } ,
615- setHeld : ( ) => { }
616- } ,
617- remoteParticipants : [ ] ,
618- participants : [ ] ,
604+ contact : { username : 'alice' , sipExtension : '100' } ,
619605 emitter : { on : jest . fn ( ) , off : jest . fn ( ) }
620606 } as unknown as IClientMediaCall
621607 } ) ;
@@ -626,37 +612,29 @@ describe('MediaSessionInstance', () => {
626612
627613 it ( 'answerCall resolves roomId from DM for non-SIP callee' , async ( ) => {
628614 mockGetDMSubscriptionByUsername . mockResolvedValue ( { rid : 'dm-rid' } as any ) ;
629- const calleeCall = buildClientMediaCall ( { callId : 'call-ans' , role : 'callee' } ) ;
630- mockUseCallStoreGetState . mockReturnValue ( {
631- reset : mockCallStoreReset ,
632- setCall : jest . fn ( ) ,
633- setRoomId : mockSetRoomId ,
634- resetNativeCallId : jest . fn ( ) ,
635- call : calleeCall ,
615+ mediaSessionInstance . init ( 'user-1' ) ;
616+ const mainCall = {
636617 callId : 'call-ans' ,
637- nativeAcceptedCallId : null ,
638- roomId : null
639- } ) ;
618+ accept : jest . fn ( ) . mockResolvedValue ( undefined ) ,
619+ localParticipant : {
620+ contact : { username : 'bob' , sipExtension : '' }
621+ }
622+ } ;
640623
641624 await mediaSessionInstance . answerCall ( 'call-ans' ) ;
642625
643626 await waitFor ( ( ) => expect ( mockSetRoomId ) . toHaveBeenCalledWith ( 'dm-rid' ) ) ;
644- expect ( mockGetDMSubscriptionByUsername ) . toHaveBeenCalledWith ( 'bob' ) ;
645627 } ) ;
646628
647629 it ( 'answerCall skips DM lookup for SIP contact' , async ( ) => {
648- const sipCall = buildClientMediaCall ( { callId : 'call-sip' , role : 'callee' } ) ;
649- sipCall . localParticipant . contact . sipExtension = 'ext' ;
650- mockUseCallStoreGetState . mockReturnValue ( {
651- reset : mockCallStoreReset ,
652- setCall : jest . fn ( ) ,
653- setRoomId : mockSetRoomId ,
654- resetNativeCallId : jest . fn ( ) ,
655- call : sipCall ,
630+ mediaSessionInstance . init ( 'user-1' ) ;
631+ const mainCall = {
656632 callId : 'call-sip' ,
657- nativeAcceptedCallId : null ,
658- roomId : null
659- } ) ;
633+ accept : jest . fn ( ) . mockResolvedValue ( undefined ) ,
634+ localParticipant : {
635+ contact : { username : 'bob' , sipExtension : 'ext' }
636+ }
637+ } ;
660638
661639 await mediaSessionInstance . answerCall ( 'call-sip' ) ;
662640
0 commit comments