Skip to content

Commit

Permalink
fix(RTC): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMcAssey committed Dec 8, 2023
1 parent fe276cb commit 51717eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
15 changes: 3 additions & 12 deletions JitsiMeetJS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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';
Expand Down
8 changes: 7 additions & 1 deletion JitsiTrackErrors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();

Expand All @@ -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( [] );
} );
} );
} );

0 comments on commit 51717eb

Please sign in to comment.