@@ -575,8 +575,120 @@ describe('PeerConnectionAnalyzer', () => {
575
575
} )
576
576
577
577
test . each ( [
578
- [ 'very bad quality due to low packets' , 'audio' ] ,
579
- [ 'very bad quality due to low packets' , 'video' ] ,
578
+ [ 'very bad quality with low packets and packet loss' , 'audio' ] ,
579
+ [ 'very bad quality with low packets and packet loss' , 'video' ] ,
580
+ ] ) ( '%s, %s' , async ( name , kind ) => {
581
+ peerConnection . getStats
582
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
583
+ { type : 'outbound-rtp' , kind, packetsSent : 5 , timestamp : 10000 } ,
584
+ { type : 'remote-inbound-rtp' , kind, packetsReceived : 3 , timestamp : 10000 , packetsLost : 2 , roundTripTime : 0.1 } ,
585
+ ] ) )
586
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
587
+ { type : 'outbound-rtp' , kind, packetsSent : 10 , timestamp : 11000 } ,
588
+ { type : 'remote-inbound-rtp' , kind, packetsReceived : 6 , timestamp : 11000 , packetsLost : 4 , roundTripTime : 0.1 } ,
589
+ ] ) )
590
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
591
+ { type : 'outbound-rtp' , kind, packetsSent : 15 , timestamp : 11950 } ,
592
+ { type : 'remote-inbound-rtp' , kind, packetsReceived : 9 , timestamp : 11950 , packetsLost : 6 , roundTripTime : 0.1 } ,
593
+ ] ) )
594
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
595
+ { type : 'outbound-rtp' , kind, packetsSent : 20 , timestamp : 13020 } ,
596
+ { type : 'remote-inbound-rtp' , kind, packetsReceived : 12 , timestamp : 13020 , packetsLost : 8 , roundTripTime : 0.1 } ,
597
+ ] ) )
598
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
599
+ { type : 'outbound-rtp' , kind, packetsSent : 25 , timestamp : 14010 } ,
600
+ { type : 'remote-inbound-rtp' , kind, packetsReceived : 15 , timestamp : 14010 , packetsLost : 10 , roundTripTime : 0.1 } ,
601
+ ] ) )
602
+ // A sixth report is needed for the initial calculation due to
603
+ // the first stats report being used as the base to calculate
604
+ // relative values of cumulative stats.
605
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
606
+ { type : 'outbound-rtp' , kind, packetsSent : 30 , timestamp : 14985 } ,
607
+ { type : 'remote-inbound-rtp' , kind, packetsReceived : 18 , timestamp : 14985 , packetsLost : 12 , roundTripTime : 0.1 } ,
608
+ ] ) )
609
+
610
+ peerConnectionAnalyzer . setPeerConnection ( peerConnection , PEER_DIRECTION . SENDER )
611
+
612
+ jest . advanceTimersByTime ( 6000 )
613
+ // Force the promises returning the stats to be executed.
614
+ await null
615
+
616
+ expect ( peerConnection . getStats ) . toHaveBeenCalledTimes ( 6 )
617
+
618
+ if ( kind === 'audio' ) {
619
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
620
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
621
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
622
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
623
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 0 )
624
+ } else {
625
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
626
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
627
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 0 )
628
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
629
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
630
+ }
631
+ } )
632
+
633
+ test . each ( [
634
+ [ 'good quality even with low packets if no packet loss, missing remote packet count' , 'audio' ] ,
635
+ [ 'good quality even with low packets if no packet loss, missing remote packet count' , 'video' ] ,
636
+ ] ) ( '%s, %s' , async ( name , kind ) => {
637
+ peerConnection . getStats
638
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
639
+ { type : 'outbound-rtp' , kind, packetsSent : 5 , timestamp : 10000 } ,
640
+ { type : 'remote-inbound-rtp' , kind, timestamp : 10000 , packetsLost : 2 , roundTripTime : 0.1 } ,
641
+ ] ) )
642
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
643
+ { type : 'outbound-rtp' , kind, packetsSent : 10 , timestamp : 11000 } ,
644
+ { type : 'remote-inbound-rtp' , kind, timestamp : 11000 , packetsLost : 4 , roundTripTime : 0.1 } ,
645
+ ] ) )
646
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
647
+ { type : 'outbound-rtp' , kind, packetsSent : 15 , timestamp : 11950 } ,
648
+ { type : 'remote-inbound-rtp' , kind, timestamp : 11950 , packetsLost : 6 , roundTripTime : 0.1 } ,
649
+ ] ) )
650
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
651
+ { type : 'outbound-rtp' , kind, packetsSent : 20 , timestamp : 13020 } ,
652
+ { type : 'remote-inbound-rtp' , kind, timestamp : 13020 , packetsLost : 8 , roundTripTime : 0.1 } ,
653
+ ] ) )
654
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
655
+ { type : 'outbound-rtp' , kind, packetsSent : 25 , timestamp : 14010 } ,
656
+ { type : 'remote-inbound-rtp' , kind, timestamp : 14010 , packetsLost : 10 , roundTripTime : 0.1 } ,
657
+ ] ) )
658
+ // A sixth report is needed for the initial calculation due to
659
+ // the first stats report being used as the base to calculate
660
+ // relative values of cumulative stats.
661
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
662
+ { type : 'outbound-rtp' , kind, packetsSent : 30 , timestamp : 14985 } ,
663
+ { type : 'remote-inbound-rtp' , kind, timestamp : 14985 , packetsLost : 12 , roundTripTime : 0.1 } ,
664
+ ] ) )
665
+
666
+ peerConnectionAnalyzer . setPeerConnection ( peerConnection , PEER_DIRECTION . SENDER )
667
+
668
+ jest . advanceTimersByTime ( 6000 )
669
+ // Force the promises returning the stats to be executed.
670
+ await null
671
+
672
+ expect ( peerConnection . getStats ) . toHaveBeenCalledTimes ( 6 )
673
+
674
+ if ( kind === 'audio' ) {
675
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
676
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
677
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
678
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
679
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 0 )
680
+ } else {
681
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
682
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
683
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 0 )
684
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
685
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
686
+ }
687
+ } )
688
+
689
+ test . each ( [
690
+ [ 'good quality even with low packets if no packet loss' , 'audio' ] ,
691
+ [ 'good quality even with low packets if no packet loss' , 'video' ] ,
580
692
] ) ( '%s, %s' , async ( name , kind ) => {
581
693
peerConnection . getStats
582
694
. mockResolvedValueOnce ( newRTCStatsReport ( [
@@ -616,23 +728,23 @@ describe('PeerConnectionAnalyzer', () => {
616
728
expect ( peerConnection . getStats ) . toHaveBeenCalledTimes ( 6 )
617
729
618
730
if ( kind === 'audio' ) {
619
- expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
731
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . GOOD )
620
732
expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
621
733
expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
622
- expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
734
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . GOOD )
623
735
expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 0 )
624
736
} else {
625
737
expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
626
- expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
738
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . GOOD )
627
739
expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 0 )
628
740
expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
629
- expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
741
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . GOOD )
630
742
}
631
743
} )
632
744
633
745
test . each ( [
634
- [ 'very bad quality due to low packets, missing remote packet count' , 'audio' ] ,
635
- [ 'very bad quality due to low packets, missing remote packet count' , 'video' ] ,
746
+ [ 'good quality even with low packets if no packet loss , missing remote packet count' , 'audio' ] ,
747
+ [ 'good quality even with low packets if no packet loss , missing remote packet count' , 'video' ] ,
636
748
] ) ( '%s, %s' , async ( name , kind ) => {
637
749
peerConnection . getStats
638
750
. mockResolvedValueOnce ( newRTCStatsReport ( [
@@ -672,17 +784,17 @@ describe('PeerConnectionAnalyzer', () => {
672
784
expect ( peerConnection . getStats ) . toHaveBeenCalledTimes ( 6 )
673
785
674
786
if ( kind === 'audio' ) {
675
- expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
787
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . GOOD )
676
788
expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
677
789
expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
678
- expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
790
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . GOOD )
679
791
expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 0 )
680
792
} else {
681
793
expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
682
- expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
794
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . GOOD )
683
795
expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 0 )
684
796
expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
685
- expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
797
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . GOOD )
686
798
}
687
799
} )
688
800
0 commit comments