11import './mocks/webrtc.mocks' ;
22import { describe , expect , it , vi } from 'vitest' ;
3+ import { fromPartial } from '@total-typescript/shoehorn' ;
34import {
45 AudioBitrateProfile ,
56 PublishOption ,
@@ -24,13 +25,12 @@ describe('videoLayers', () => {
2425 const targetBitrate = 3000000 ;
2526 vi . spyOn ( track , 'getSettings' ) . mockReturnValue ( { width, height } ) ;
2627
27- const publishOption : PublishOption = {
28+ const publishOption : PublishOption = fromPartial ( {
2829 bitrate : targetBitrate ,
29- // @ts -expect-error - incomplete data
3030 codec : { name : 'vp8' } ,
3131 videoDimension : { width, height } ,
3232 fps : 30 ,
33- } ;
33+ } ) ;
3434 const layers = computeVideoLayers ( track , publishOption ) ;
3535 expect ( layers ) . toEqual ( [
3636 {
@@ -66,26 +66,29 @@ describe('videoLayers', () => {
6666 it ( 'should return undefined for audio track' , ( ) => {
6767 const track = new MediaStreamTrack ( ) ;
6868 expect (
69- // @ts -expect-error - incomplete data
70- computeVideoLayers ( track , { trackType : TrackType . AUDIO } ) ,
69+ computeVideoLayers ( track , fromPartial ( { trackType : TrackType . AUDIO } ) ) ,
7170 ) . toBeUndefined ( ) ;
7271 expect (
73- // @ts -expect-error - incomplete data
74- computeVideoLayers ( track , { trackType : TrackType . SCREEN_SHARE_AUDIO } ) ,
72+ computeVideoLayers (
73+ track ,
74+ fromPartial ( { trackType : TrackType . SCREEN_SHARE_AUDIO } ) ,
75+ ) ,
7576 ) . toBeUndefined ( ) ;
7677 } ) ;
7778
7879 it ( 'should use predefined bitrate values when track dimensions cant be determined' , ( ) => {
7980 const bitrate = 3000000 ;
8081 const track = new MediaStreamTrack ( ) ;
8182 vi . spyOn ( track , 'getSettings' ) . mockReturnValue ( { } ) ;
82- const layers = computeVideoLayers ( track , {
83- bitrate,
84- // @ts -expect-error - incomplete data
85- codec : { name : 'vp8' } ,
86- fps : 30 ,
87- videoDimension : { width : 320 , height : 180 } ,
88- } ) ;
83+ const layers = computeVideoLayers (
84+ track ,
85+ fromPartial ( {
86+ bitrate,
87+ codec : { name : 'vp8' } ,
88+ fps : 30 ,
89+ videoDimension : { width : 320 , height : 180 } ,
90+ } ) ,
91+ ) ;
8992 expect ( layers ) . toEqual ( [
9093 {
9194 active : true ,
@@ -104,13 +107,15 @@ describe('videoLayers', () => {
104107 const width = 320 ;
105108 const height = 240 ;
106109 vi . spyOn ( track , 'getSettings' ) . mockReturnValue ( { width, height } ) ;
107- const layers = computeVideoLayers ( track , {
108- bitrate : 0 ,
109- // @ts -expect-error - incomplete data
110- codec : { name : 'vp8' } ,
111- fps : 30 ,
112- videoDimension : { width, height } ,
113- } ) ;
110+ const layers = computeVideoLayers (
111+ track ,
112+ fromPartial ( {
113+ bitrate : 0 ,
114+ codec : { name : 'vp8' } ,
115+ fps : 30 ,
116+ videoDimension : { width, height } ,
117+ } ) ,
118+ ) ;
114119 expect ( layers . length ) . toBe ( 1 ) ;
115120 const [ q ] = layers ;
116121 expect ( q . rid ) . toBe ( 'q' ) ;
@@ -123,13 +128,15 @@ describe('videoLayers', () => {
123128 const width = 640 ;
124129 const height = 480 ;
125130 vi . spyOn ( track , 'getSettings' ) . mockReturnValue ( { width, height } ) ;
126- const layers = computeVideoLayers ( track , {
127- bitrate : 0 ,
128- // @ts -expect-error - incomplete data
129- codec : { name : 'vp8' } ,
130- fps : 30 ,
131- videoDimension : { width, height } ,
132- } ) ;
131+ const layers = computeVideoLayers (
132+ track ,
133+ fromPartial ( {
134+ bitrate : 0 ,
135+ codec : { name : 'vp8' } ,
136+ fps : 30 ,
137+ videoDimension : { width, height } ,
138+ } ) ,
139+ ) ;
133140 expect ( layers . length ) . toBe ( 2 ) ;
134141 const [ q , h ] = layers ;
135142 expect ( q . rid ) . toBe ( 'q' ) ;
@@ -145,13 +152,15 @@ describe('videoLayers', () => {
145152 const width = 1280 ;
146153 const height = 720 ;
147154 vi . spyOn ( track , 'getSettings' ) . mockReturnValue ( { width, height } ) ;
148- const layers = computeVideoLayers ( track , {
149- bitrate : 0 ,
150- // @ts -expect-error - incomplete data
151- codec : { name : 'vp8' } ,
152- fps : 30 ,
153- videoDimension : { width, height } ,
154- } ) ;
155+ const layers = computeVideoLayers (
156+ track ,
157+ fromPartial ( {
158+ bitrate : 0 ,
159+ codec : { name : 'vp8' } ,
160+ fps : 30 ,
161+ videoDimension : { width, height } ,
162+ } ) ,
163+ ) ;
155164 expect ( layers . length ) . toBe ( 3 ) ;
156165 const [ q , h , f ] = layers ;
157166 expect ( q . rid ) . toBe ( 'q' ) ;
@@ -171,13 +180,15 @@ describe('videoLayers', () => {
171180 width : 1280 ,
172181 height : 720 ,
173182 } ) ;
174- const layers = computeVideoLayers ( track , {
175- maxTemporalLayers : 3 ,
176- maxSpatialLayers : 3 ,
177- // @ts -expect-error - incomplete data
178- codec : { name : 'vp9' } ,
179- videoDimension : { width : 1280 , height : 720 } ,
180- } ) ;
183+ const layers = computeVideoLayers (
184+ track ,
185+ fromPartial ( {
186+ maxTemporalLayers : 3 ,
187+ maxSpatialLayers : 3 ,
188+ codec : { name : 'vp9' } ,
189+ videoDimension : { width : 1280 , height : 720 } ,
190+ } ) ,
191+ ) ;
181192 expect ( layers . length ) . toBe ( 3 ) ;
182193 expect ( layers [ 0 ] . scalabilityMode ) . toBe ( 'L3T3_KEY' ) ;
183194 expect ( layers [ 0 ] . rid ) . toBe ( 'q' ) ;
@@ -187,8 +198,10 @@ describe('videoLayers', () => {
187198
188199 it ( 'should activate only a single layer when useSingleLayer is true' , ( ) => {
189200 const track = new MediaStreamTrack ( ) ;
190- // @ts -expect-error - incomplete data
191- const layers = computeVideoLayers ( track , { useSingleLayer : true } ) ;
201+ const layers = computeVideoLayers (
202+ track ,
203+ fromPartial ( { useSingleLayer : true } ) ,
204+ ) ;
192205 expect ( layers . length ) . toBe ( 3 ) ;
193206 expect ( layers [ 0 ] . active ) . toBe ( false ) ;
194207 expect ( layers [ 0 ] . rid ) . toBe ( 'q' ) ;
@@ -201,22 +214,26 @@ describe('videoLayers', () => {
201214 it ( 'should activate only a single layer when useSingleLayer is true in single layer mode' , ( ) => {
202215 const track = new MediaStreamTrack ( ) ;
203216 vi . spyOn ( track , 'getSettings' ) . mockReturnValue ( { width : 320 , height : 180 } ) ;
204- // @ts -expect-error - incomplete data
205- const layers = computeVideoLayers ( track , { useSingleLayer : true } ) ;
217+ const layers = computeVideoLayers (
218+ track ,
219+ fromPartial ( { useSingleLayer : true } ) ,
220+ ) ;
206221 expect ( layers . length ) . toBe ( 1 ) ;
207222 expect ( layers [ 0 ] . active ) . toBe ( true ) ;
208223 expect ( layers [ 0 ] . rid ) . toBe ( 'q' ) ;
209224 } ) ;
210225
211226 it ( 'should activate only one temporal layer when useSingleLayer is true for SVC' , ( ) => {
212227 const track = new MediaStreamTrack ( ) ;
213- const layers = computeVideoLayers ( track , {
214- // @ts -expect-error - incomplete data
215- codec : { name : 'vp9' } ,
216- maxSpatialLayers : 3 ,
217- maxTemporalLayers : 3 ,
218- useSingleLayer : true ,
219- } ) ;
228+ const layers = computeVideoLayers (
229+ track ,
230+ fromPartial ( {
231+ codec : { name : 'vp9' } ,
232+ maxSpatialLayers : 3 ,
233+ maxTemporalLayers : 3 ,
234+ useSingleLayer : true ,
235+ } ) ,
236+ ) ;
220237 expect ( layers . length ) . toBe ( 3 ) ;
221238 expect ( layers [ 0 ] . rid ) . toBe ( 'q' ) ;
222239 expect ( layers [ 0 ] . active ) . toBe ( false ) ;
@@ -318,13 +335,15 @@ describe('videoLayers', () => {
318335
319336 it ( 'should use integer for maxBitrate' , ( ) => {
320337 const track = new MediaStreamTrack ( ) ;
321- const layers = computeVideoLayers ( track , {
322- bitrate : 2999777 ,
323- // @ts -expect-error - incomplete data
324- codec : { name : 'vp8' } ,
325- videoDimension : { width : 1920 , height : 1080 } ,
326- fps : 30 ,
327- } ) ;
338+ const layers = computeVideoLayers (
339+ track ,
340+ fromPartial ( {
341+ bitrate : 2999777 ,
342+ codec : { name : 'vp8' } ,
343+ videoDimension : { width : 1920 , height : 1080 } ,
344+ fps : 30 ,
345+ } ) ,
346+ ) ;
328347 expect ( layers ) . toBeDefined ( ) ;
329348 for ( const layer of layers ! ) {
330349 expect ( Number . isInteger ( layer . width ) ) . toBe ( true ) ;
@@ -422,40 +441,46 @@ describe('audioLayers', () => {
422441 it ( 'should use predefined bitrates when publish options are missing' , ( ) => {
423442 expect (
424443 computeAudioLayers (
425- // @ts -expect-error - incomplete data
426- { trackType : TrackType . AUDIO , id : 1 , audioBitrateProfiles : [ ] } ,
444+ fromPartial ( {
445+ trackType : TrackType . AUDIO ,
446+ id : 1 ,
447+ audioBitrateProfiles : [ ] ,
448+ } ) ,
427449 { audioBitrateProfile : AudioBitrateProfile . VOICE_STANDARD_UNSPECIFIED } ,
428450 ) ,
429451 ) . toEqual ( [ { maxBitrate : 64000 } ] ) ;
430452 expect (
431453 computeAudioLayers (
432- // @ts -expect-error - incomplete data
433- { trackType : TrackType . AUDIO , id : 1 , audioBitrateProfiles : [ ] } ,
454+ fromPartial ( {
455+ trackType : TrackType . AUDIO ,
456+ id : 1 ,
457+ audioBitrateProfiles : [ ] ,
458+ } ) ,
434459 { audioBitrateProfile : AudioBitrateProfile . VOICE_HIGH_QUALITY } ,
435460 ) ,
436461 ) . toEqual ( [ { maxBitrate : 128000 } ] ) ;
437462 expect (
438463 computeAudioLayers (
439- // @ts -expect-error - incomplete data
440- { trackType : TrackType . AUDIO , id : 1 , audioBitrateProfiles : [ ] } ,
464+ fromPartial ( {
465+ trackType : TrackType . AUDIO ,
466+ id : 1 ,
467+ audioBitrateProfiles : [ ] ,
468+ } ) ,
441469 { audioBitrateProfile : AudioBitrateProfile . MUSIC_HIGH_QUALITY } ,
442470 ) ,
443471 ) . toEqual ( [ { maxBitrate : 128000 } ] ) ;
444472 } ) ;
445473
446474 it ( 'should use the predefined bitrate when the SFU does not provide audioBitrateProfiles' , ( ) => {
447475 expect (
448- computeAudioLayers (
449- // @ts -expect-error - incomplete data
450- { trackType : TrackType . AUDIO , id : 1 } ,
451- { audioBitrateProfile : AudioBitrateProfile . VOICE_STANDARD_UNSPECIFIED } ,
452- ) ,
476+ computeAudioLayers ( fromPartial ( { trackType : TrackType . AUDIO , id : 1 } ) , {
477+ audioBitrateProfile : AudioBitrateProfile . VOICE_STANDARD_UNSPECIFIED ,
478+ } ) ,
453479 ) . toEqual ( [ { maxBitrate : 64000 } ] ) ;
454480 } ) ;
455481
456482 it ( 'should respect the bitrates provided in publish options' , ( ) => {
457- // @ts -expect-error - incomplete data
458- const config : PublishOption = {
483+ const config : PublishOption = fromPartial ( {
459484 trackType : TrackType . AUDIO ,
460485 id : 1 ,
461486 audioBitrateProfiles : [
@@ -472,7 +497,7 @@ describe('audioLayers', () => {
472497 bitrate : 192000 ,
473498 } ,
474499 ] ,
475- } ;
500+ } ) ;
476501 expect (
477502 computeAudioLayers ( config , {
478503 audioBitrateProfile : AudioBitrateProfile . VOICE_STANDARD_UNSPECIFIED ,
0 commit comments