@@ -663,8 +663,142 @@ describe('PeerConnectionAnalyzer', () => {
663
663
} )
664
664
665
665
test . each ( [
666
- [ 'very bad quality due to low packets' , 'audio' ] ,
667
- [ 'very bad quality due to low packets' , 'video' ] ,
666
+ [ 'very bad quality with low packets and packet loss' , 'audio' ] ,
667
+ [ 'very bad quality with low packets and packet loss' , 'video' ] ,
668
+ ] ) ( '%s, %s' , async ( name , kind ) => {
669
+ peerConnection . getStats
670
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
671
+ { type : 'outbound-rtp' , kind, packetsSent : 5 , timestamp : 10000 } ,
672
+ { type : 'remote-inbound-rtp' , kind, packetsReceived : 3 , timestamp : 10000 , packetsLost : 2 , roundTripTime : 0.1 } ,
673
+ ] ) )
674
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
675
+ { type : 'outbound-rtp' , kind, packetsSent : 10 , timestamp : 11000 } ,
676
+ { type : 'remote-inbound-rtp' , kind, packetsReceived : 6 , timestamp : 11000 , packetsLost : 4 , roundTripTime : 0.1 } ,
677
+ ] ) )
678
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
679
+ { type : 'outbound-rtp' , kind, packetsSent : 15 , timestamp : 11950 } ,
680
+ { type : 'remote-inbound-rtp' , kind, packetsReceived : 9 , timestamp : 11950 , packetsLost : 6 , roundTripTime : 0.1 } ,
681
+ ] ) )
682
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
683
+ { type : 'outbound-rtp' , kind, packetsSent : 20 , timestamp : 13020 } ,
684
+ { type : 'remote-inbound-rtp' , kind, packetsReceived : 12 , timestamp : 13020 , packetsLost : 8 , roundTripTime : 0.1 } ,
685
+ ] ) )
686
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
687
+ { type : 'outbound-rtp' , kind, packetsSent : 25 , timestamp : 14010 } ,
688
+ { type : 'remote-inbound-rtp' , kind, packetsReceived : 15 , timestamp : 14010 , packetsLost : 10 , roundTripTime : 0.1 } ,
689
+ ] ) )
690
+ // A sixth report is needed for the initial calculation due to
691
+ // the first stats report being used as the base to calculate
692
+ // relative values of cumulative stats.
693
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
694
+ { type : 'outbound-rtp' , kind, packetsSent : 30 , timestamp : 14985 } ,
695
+ { type : 'remote-inbound-rtp' , kind, packetsReceived : 18 , timestamp : 14985 , packetsLost : 12 , roundTripTime : 0.1 } ,
696
+ ] ) )
697
+
698
+ peerConnectionAnalyzer . setPeerConnection ( peerConnection , PEER_DIRECTION . SENDER )
699
+
700
+ jest . advanceTimersByTime ( 5000 )
701
+ // Force the promises returning the stats to be executed.
702
+ await null
703
+
704
+ expect ( peerConnection . getStats ) . toHaveBeenCalledTimes ( 5 )
705
+
706
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
707
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
708
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 0 )
709
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 0 )
710
+
711
+ jest . advanceTimersByTime ( 1000 )
712
+ // Force the promises returning the stats to be executed.
713
+ await null
714
+
715
+ expect ( peerConnection . getStats ) . toHaveBeenCalledTimes ( 6 )
716
+
717
+ if ( kind === 'audio' ) {
718
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
719
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
720
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
721
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
722
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 0 )
723
+ } else {
724
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
725
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
726
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 0 )
727
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
728
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
729
+ }
730
+ } )
731
+
732
+ test . each ( [
733
+ [ 'good quality even with low packets if no packet loss, missing remote packet count' , 'audio' ] ,
734
+ [ 'good quality even with low packets if no packet loss, missing remote packet count' , 'video' ] ,
735
+ ] ) ( '%s, %s' , async ( name , kind ) => {
736
+ peerConnection . getStats
737
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
738
+ { type : 'outbound-rtp' , kind, packetsSent : 5 , timestamp : 10000 } ,
739
+ { type : 'remote-inbound-rtp' , kind, timestamp : 10000 , packetsLost : 2 , roundTripTime : 0.1 } ,
740
+ ] ) )
741
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
742
+ { type : 'outbound-rtp' , kind, packetsSent : 10 , timestamp : 11000 } ,
743
+ { type : 'remote-inbound-rtp' , kind, timestamp : 11000 , packetsLost : 4 , roundTripTime : 0.1 } ,
744
+ ] ) )
745
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
746
+ { type : 'outbound-rtp' , kind, packetsSent : 15 , timestamp : 11950 } ,
747
+ { type : 'remote-inbound-rtp' , kind, timestamp : 11950 , packetsLost : 6 , roundTripTime : 0.1 } ,
748
+ ] ) )
749
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
750
+ { type : 'outbound-rtp' , kind, packetsSent : 20 , timestamp : 13020 } ,
751
+ { type : 'remote-inbound-rtp' , kind, timestamp : 13020 , packetsLost : 8 , roundTripTime : 0.1 } ,
752
+ ] ) )
753
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
754
+ { type : 'outbound-rtp' , kind, packetsSent : 25 , timestamp : 14010 } ,
755
+ { type : 'remote-inbound-rtp' , kind, timestamp : 14010 , packetsLost : 10 , roundTripTime : 0.1 } ,
756
+ ] ) )
757
+ // A sixth report is needed for the initial calculation due to
758
+ // the first stats report being used as the base to calculate
759
+ // relative values of cumulative stats.
760
+ . mockResolvedValueOnce ( newRTCStatsReport ( [
761
+ { type : 'outbound-rtp' , kind, packetsSent : 30 , timestamp : 14985 } ,
762
+ { type : 'remote-inbound-rtp' , kind, timestamp : 14985 , packetsLost : 12 , roundTripTime : 0.1 } ,
763
+ ] ) )
764
+
765
+ peerConnectionAnalyzer . setPeerConnection ( peerConnection , PEER_DIRECTION . SENDER )
766
+
767
+ jest . advanceTimersByTime ( 5000 )
768
+ // Force the promises returning the stats to be executed.
769
+ await null
770
+
771
+ expect ( peerConnection . getStats ) . toHaveBeenCalledTimes ( 5 )
772
+
773
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
774
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
775
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 0 )
776
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 0 )
777
+
778
+ jest . advanceTimersByTime ( 1000 )
779
+ // Force the promises returning the stats to be executed.
780
+ await null
781
+
782
+ expect ( peerConnection . getStats ) . toHaveBeenCalledTimes ( 6 )
783
+
784
+ if ( kind === 'audio' ) {
785
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
786
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
787
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
788
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
789
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 0 )
790
+ } else {
791
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
792
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
793
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 0 )
794
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
795
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
796
+ }
797
+ } )
798
+
799
+ test . each ( [
800
+ [ 'good quality even with low packets if no packet loss' , 'audio' ] ,
801
+ [ 'good quality even with low packets if no packet loss' , 'video' ] ,
668
802
] ) ( '%s, %s' , async ( name , kind ) => {
669
803
peerConnection . getStats
670
804
. mockResolvedValueOnce ( newRTCStatsReport ( [
@@ -715,23 +849,23 @@ describe('PeerConnectionAnalyzer', () => {
715
849
expect ( peerConnection . getStats ) . toHaveBeenCalledTimes ( 6 )
716
850
717
851
if ( kind === 'audio' ) {
718
- expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
852
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . GOOD )
719
853
expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
720
854
expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
721
- expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
855
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . GOOD )
722
856
expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 0 )
723
857
} else {
724
858
expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
725
- expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
859
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . GOOD )
726
860
expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 0 )
727
861
expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
728
- expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
862
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . GOOD )
729
863
}
730
864
} )
731
865
732
866
test . each ( [
733
- [ 'very bad quality due to low packets, missing remote packet count' , 'audio' ] ,
734
- [ 'very bad quality due to low packets, missing remote packet count' , 'video' ] ,
867
+ [ 'good quality even with low packets if no packet loss , missing remote packet count' , 'audio' ] ,
868
+ [ 'good quality even with low packets if no packet loss , missing remote packet count' , 'video' ] ,
735
869
] ) ( '%s, %s' , async ( name , kind ) => {
736
870
peerConnection . getStats
737
871
. mockResolvedValueOnce ( newRTCStatsReport ( [
@@ -782,17 +916,17 @@ describe('PeerConnectionAnalyzer', () => {
782
916
expect ( peerConnection . getStats ) . toHaveBeenCalledTimes ( 6 )
783
917
784
918
if ( kind === 'audio' ) {
785
- expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
919
+ expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . GOOD )
786
920
expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
787
921
expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 1 )
788
- expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
922
+ expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . GOOD )
789
923
expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 0 )
790
924
} else {
791
925
expect ( peerConnectionAnalyzer . getConnectionQualityAudio ( ) ) . toBe ( CONNECTION_QUALITY . UNKNOWN )
792
- expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . VERY_BAD )
926
+ expect ( peerConnectionAnalyzer . getConnectionQualityVideo ( ) ) . toBe ( CONNECTION_QUALITY . GOOD )
793
927
expect ( changeConnectionQualityAudioHandler ) . toHaveBeenCalledTimes ( 0 )
794
928
expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledTimes ( 1 )
795
- expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . VERY_BAD )
929
+ expect ( changeConnectionQualityVideoHandler ) . toHaveBeenCalledWith ( peerConnectionAnalyzer , CONNECTION_QUALITY . GOOD )
796
930
}
797
931
} )
798
932
0 commit comments