@@ -30,6 +30,8 @@ import {
30
30
MockMediaStream ,
31
31
MockMediaStreamTrack ,
32
32
installWebRTCMocks ,
33
+ MockRTCPeerConnection ,
34
+ SCREENSHARE_STREAM_ID ,
33
35
} from "../../test-utils/webrtc" ;
34
36
import { CallFeed } from "../../../src/webrtc/callFeed" ;
35
37
import { EventType , MatrixEvent } from "../../../src" ;
@@ -117,6 +119,9 @@ describe('Call', function() {
117
119
} ) ;
118
120
119
121
afterEach ( function ( ) {
122
+ // Hangup to stop timers
123
+ call . hangup ( CallErrorCode . UserHangup , true ) ;
124
+
120
125
client . stop ( ) ;
121
126
global . navigator = prevNavigator ;
122
127
global . window = prevWindow ;
@@ -178,9 +183,6 @@ describe('Call', function() {
178
183
getSender : ( ) => "@test:foo" ,
179
184
} ) ;
180
185
expect ( call . peerConn . addIceCandidate . mock . calls . length ) . toBe ( 1 ) ;
181
-
182
- // Hangup to stop timers
183
- call . hangup ( CallErrorCode . UserHangup , true ) ;
184
186
} ) ;
185
187
186
188
it ( 'should add candidates received before answer if party ID is correct' , async function ( ) {
@@ -283,9 +285,6 @@ describe('Call', function() {
283
285
const ident = call . getRemoteAssertedIdentity ( ) ;
284
286
expect ( ident . id ) . toEqual ( "@steve:example.com" ) ;
285
287
expect ( ident . displayName ) . toEqual ( "Steve Gibbons" ) ;
286
-
287
- // Hangup to stop timers
288
- call . hangup ( CallErrorCode . UserHangup , true ) ;
289
288
} ) ;
290
289
291
290
it ( "should map SDPStreamMetadata to feeds" , async ( ) => {
@@ -734,16 +733,18 @@ describe('Call', function() {
734
733
735
734
describe ( "ignoring streams with ids for which we already have a feed" , ( ) => {
736
735
const STREAM_ID = "stream_id" ;
737
- const FEEDS_CHANGED_CALLBACK = jest . fn ( ) ;
736
+ let FEEDS_CHANGED_CALLBACK : jest . Mock < void , [ ] > ;
738
737
739
738
beforeEach ( async ( ) => {
739
+ FEEDS_CHANGED_CALLBACK = jest . fn ( ) ;
740
+
740
741
await startVoiceCall ( client , call ) ;
741
742
call . on ( CallEvent . FeedsChanged , FEEDS_CHANGED_CALLBACK ) ;
742
743
jest . spyOn ( call , "pushLocalFeed" ) ;
743
744
} ) ;
744
745
745
746
afterEach ( ( ) => {
746
- FEEDS_CHANGED_CALLBACK . mockReset ( ) ;
747
+ call . off ( CallEvent . FeedsChanged , FEEDS_CHANGED_CALLBACK ) ;
747
748
} ) ;
748
749
749
750
it ( "should ignore stream passed to pushRemoteFeed()" , async ( ) => {
@@ -941,4 +942,70 @@ describe('Call', function() {
941
942
942
943
expect ( call . state ) . toEqual ( CallState . Ended ) ;
943
944
} ) ;
945
+
946
+ describe ( "Screen sharing" , ( ) => {
947
+ beforeEach ( async ( ) => {
948
+ await startVoiceCall ( client , call ) ;
949
+
950
+ await call . onAnswerReceived ( {
951
+ getContent : ( ) => {
952
+ return {
953
+ "version" : 1 ,
954
+ "call_id" : call . callId ,
955
+ "party_id" : 'party_id' ,
956
+ "answer" : {
957
+ sdp : DUMMY_SDP ,
958
+ } ,
959
+ "org.matrix.msc3077.sdp_stream_metadata" : {
960
+ "foo" : {
961
+ "purpose" : "m.usermedia" ,
962
+ "audio_muted" : false ,
963
+ "video_muted" : false ,
964
+ } ,
965
+ } ,
966
+ } ;
967
+ } ,
968
+ getSender : ( ) => "@test:foo" ,
969
+ } ) ;
970
+ } ) ;
971
+
972
+ afterEach ( ( ) => {
973
+ // Hangup to stop timers
974
+ call . hangup ( CallErrorCode . UserHangup , true ) ;
975
+ } ) ;
976
+
977
+ it ( "enables and disables screensharing" , async ( ) => {
978
+ await call . setScreensharingEnabled ( true ) ;
979
+
980
+ expect ( call . feeds . filter ( f => f . purpose == SDPStreamMetadataPurpose . Screenshare ) . length ) . toEqual ( 1 ) ;
981
+
982
+ client . client . sendEvent . mockReset ( ) ;
983
+ const sendNegotiatePromise = new Promise < void > ( resolve => {
984
+ client . client . sendEvent . mockImplementationOnce ( ( ) => {
985
+ resolve ( ) ;
986
+ } ) ;
987
+ } ) ;
988
+
989
+ MockRTCPeerConnection . triggerAllNegotiations ( ) ;
990
+ await sendNegotiatePromise ;
991
+
992
+ expect ( client . client . sendEvent ) . toHaveBeenCalledWith (
993
+ FAKE_ROOM_ID ,
994
+ EventType . CallNegotiate ,
995
+ expect . objectContaining ( {
996
+ "version" : "1" ,
997
+ "call_id" : call . callId ,
998
+ "org.matrix.msc3077.sdp_stream_metadata" : expect . objectContaining ( {
999
+ [ SCREENSHARE_STREAM_ID ] : expect . objectContaining ( {
1000
+ purpose : SDPStreamMetadataPurpose . Screenshare ,
1001
+ } ) ,
1002
+ } ) ,
1003
+ } ) ,
1004
+ ) ;
1005
+
1006
+ await call . setScreensharingEnabled ( false ) ;
1007
+
1008
+ expect ( call . feeds . filter ( f => f . purpose == SDPStreamMetadataPurpose . Screenshare ) . length ) . toEqual ( 0 ) ;
1009
+ } ) ;
1010
+ } ) ;
944
1011
} ) ;
0 commit comments