@@ -95,13 +95,21 @@ function newRTCStatsReport(stats) {
95
95
describe ( 'PeerConnectionAnalyzer' , ( ) => {
96
96
97
97
let peerConnectionAnalyzer
98
+ let changeConnectionQualityAudioHandler
99
+ let changeConnectionQualityVideoHandler
98
100
let peerConnection
99
101
100
102
beforeEach ( ( ) => {
101
103
jest . useFakeTimers ( )
102
104
103
105
peerConnectionAnalyzer = new PeerConnectionAnalyzer ( )
104
106
107
+ changeConnectionQualityAudioHandler = jest . fn ( )
108
+ peerConnectionAnalyzer . on ( 'change:connectionQualityAudio' , changeConnectionQualityAudioHandler )
109
+
110
+ changeConnectionQualityVideoHandler = jest . fn ( )
111
+ peerConnectionAnalyzer . on ( 'change:connectionQualityVideo' , changeConnectionQualityVideoHandler )
112
+
105
113
peerConnection = newRTCPeerConnection ( )
106
114
} )
107
115
@@ -161,8 +169,12 @@ describe('PeerConnectionAnalyzer', () => {
161
169
162
170
if ( kind === 'audio' ) {
163
171
expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . GOOD )
172
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
173
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . GOOD )
164
174
} else {
165
175
expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . GOOD )
176
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
177
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . GOOD )
166
178
}
167
179
} )
168
180
@@ -209,8 +221,12 @@ describe('PeerConnectionAnalyzer', () => {
209
221
210
222
if ( kind === 'audio' ) {
211
223
expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . MEDIUM )
224
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
225
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . MEDIUM )
212
226
} else {
213
227
expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . MEDIUM )
228
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
229
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . MEDIUM )
214
230
}
215
231
} )
216
232
@@ -257,8 +273,12 @@ describe('PeerConnectionAnalyzer', () => {
257
273
258
274
if ( kind === 'audio' ) {
259
275
expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . BAD )
276
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
277
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . BAD )
260
278
} else {
261
279
expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . BAD )
280
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
281
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . BAD )
262
282
}
263
283
} )
264
284
@@ -305,8 +325,12 @@ describe('PeerConnectionAnalyzer', () => {
305
325
306
326
if ( kind === 'audio' ) {
307
327
expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
328
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
329
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
308
330
} else {
309
331
expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
332
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
333
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
310
334
}
311
335
} )
312
336
@@ -353,8 +377,12 @@ describe('PeerConnectionAnalyzer', () => {
353
377
354
378
if ( kind === 'audio' ) {
355
379
expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
380
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
381
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
356
382
} else {
357
383
expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
384
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
385
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
358
386
}
359
387
} )
360
388
@@ -401,8 +429,12 @@ describe('PeerConnectionAnalyzer', () => {
401
429
402
430
if ( kind === 'audio' ) {
403
431
expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
432
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
433
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
404
434
} else {
405
435
expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
436
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
437
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
406
438
}
407
439
} )
408
440
@@ -449,8 +481,12 @@ describe('PeerConnectionAnalyzer', () => {
449
481
450
482
if ( kind === 'audio' ) {
451
483
expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . NO_TRANSMITTED_DATA )
484
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
485
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . NO_TRANSMITTED_DATA )
452
486
} else {
453
487
expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . NO_TRANSMITTED_DATA )
488
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
489
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . NO_TRANSMITTED_DATA )
454
490
}
455
491
} )
456
492
@@ -506,8 +542,12 @@ describe('PeerConnectionAnalyzer', () => {
506
542
507
543
if ( kind === 'audio' ) {
508
544
expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . NO_TRANSMITTED_DATA )
545
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
546
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . NO_TRANSMITTED_DATA )
509
547
} else {
510
548
expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . NO_TRANSMITTED_DATA )
549
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
550
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . NO_TRANSMITTED_DATA )
511
551
}
512
552
} )
513
553
@@ -562,8 +602,12 @@ describe('PeerConnectionAnalyzer', () => {
562
602
563
603
if ( kind === 'audio' ) {
564
604
expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . GOOD )
605
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
606
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . GOOD )
565
607
} else {
566
608
expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . GOOD )
609
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
610
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . GOOD )
567
611
}
568
612
} )
569
613
} )
0 commit comments