From 51717eba73da1bc73dc4dfa65eae05508b1ffc15 Mon Sep 17 00:00:00 2001 From: Daniel McAssey Date: Fri, 8 Dec 2023 16:41:27 +0000 Subject: [PATCH] fix(RTC): fix tests --- JitsiMeetJS.ts | 15 +++------------ JitsiTrackErrors.spec.ts | 8 +++++++- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/JitsiMeetJS.ts b/JitsiMeetJS.ts index c145e00952..49a30df538 100644 --- a/JitsiMeetJS.ts +++ b/JitsiMeetJS.ts @@ -437,7 +437,8 @@ export default { */ createLocalTracksFromMediaStreams(tracksInfo) { return RTC.createLocalTracks(tracksInfo.map((trackInfo) => { - const tracks = trackInfo.stream.getTracks(); + const tracks = trackInfo.stream.getTracks() + .filter(track => track.kind === trackInfo.mediaType); if (!tracks || tracks.length === 0) { throw new JitsiTrackError(JitsiTrackErrors.TRACK_NO_STREAM_TRACKS_FOUND, null, null); @@ -447,17 +448,7 @@ export default { throw new JitsiTrackError(JitsiTrackErrors.TRACK_TOO_MANY_TRACKS_IN_STREAM, null, null); } - if (trackInfo.mediaType === MediaType.AUDIO) { - trackInfo.track = tracks.find(track => track.kind === 'audio'); - } else if (trackInfo.mediaType === MediaType.VIDEO) { - trackInfo.track = tracks.find(track => track.kind === 'video'); - } else { - throw new JitsiTrackError(JitsiTrackErrors.NOT_FOUND, null, null); - } - - if (!trackInfo.track) { - throw new JitsiTrackError(JitsiTrackErrors.TRACK_NO_STREAM_TRACKS_FOUND, null, null); - } + trackInfo.track = tracks[0]; if (!trackInfo.sourceId) { trackInfo.sourceId = 'GENERATEDVALUEHERE'; diff --git a/JitsiTrackErrors.spec.ts b/JitsiTrackErrors.spec.ts index d651ac6f3a..ca37bfae7e 100644 --- a/JitsiTrackErrors.spec.ts +++ b/JitsiTrackErrors.spec.ts @@ -16,6 +16,8 @@ describe( "/JitsiTrackErrors members", () => { TRACK_IS_DISPOSED, TRACK_NO_STREAM_FOUND, UNSUPPORTED_RESOLUTION, + TRACK_TOO_MANY_TRACKS_IN_STREAM, + TRACK_NO_STREAM_TRACKS_FOUND, JitsiTrackErrors, ...others } = exported; @@ -33,6 +35,8 @@ describe( "/JitsiTrackErrors members", () => { expect( TRACK_IS_DISPOSED ).toBe( 'track.track_is_disposed' ); expect( TRACK_NO_STREAM_FOUND ).toBe( 'track.no_stream_found' ); expect( UNSUPPORTED_RESOLUTION ).toBe( 'gum.unsupported_resolution' ); + expect( TRACK_TOO_MANY_TRACKS_IN_STREAM ).toBe( 'track.too_many_tracks_in_stream' ); + expect( TRACK_NO_STREAM_TRACKS_FOUND ).toBe( 'track.no_stream_tracks_found' ); expect( JitsiTrackErrors ).toBeDefined(); @@ -48,10 +52,12 @@ describe( "/JitsiTrackErrors members", () => { expect( JitsiTrackErrors.TRACK_IS_DISPOSED ).toBe( 'track.track_is_disposed' ); expect( JitsiTrackErrors.TRACK_NO_STREAM_FOUND ).toBe( 'track.no_stream_found' ); expect( JitsiTrackErrors.UNSUPPORTED_RESOLUTION ).toBe( 'gum.unsupported_resolution' ); + expect( JitsiTrackErrors.TRACK_TOO_MANY_TRACKS_IN_STREAM ).toBe( 'track.too_many_tracks_in_stream' ); + expect( JitsiTrackErrors.TRACK_NO_STREAM_TRACKS_FOUND ).toBe( 'track.no_stream_tracks_found' ); } ); it( "unknown members", () => { const keys = Object.keys( others ); expect( keys ).withContext( `Extra members: ${ keys.join( ", " ) }` ).toEqual( [] ); } ); -} ); \ No newline at end of file +} );