Browse Source

Changes the way of calculating connection quality.

j8
hristoterezov 9 years ago
parent
commit
99e6453e09
1 changed files with 30 additions and 3 deletions
  1. 30
    3
      modules/connectionquality/connectionquality.js

+ 30
- 3
modules/connectionquality/connectionquality.js View File

18
  */
18
  */
19
 var remoteStats = {};
19
 var remoteStats = {};
20
 
20
 
21
+/**
22
+ * Quality percent( 100% - good, 0% - bad.) for the local user.
23
+ */
24
+var localConnectionQuality = 100;
25
+
26
+/**
27
+ * Quality percent( 100% - good, 0% - bad.) stored per id.
28
+ */
29
+var remoteConnectionQuality = {};
30
+
21
 /**
31
 /**
22
  * Converts statistics to format used by VideoLayout
32
  * Converts statistics to format used by VideoLayout
23
  * @param stats
33
  * @param stats
51
     };
61
     };
52
 }
62
 }
53
 
63
 
64
+/**
65
+ * Calculates the quality percent based on passed new and old value.
66
+ * @param newVal the new value
67
+ * @param oldVal the old value
68
+ */
69
+function calculateQuality(newVal, oldVal) {
70
+    return (newVal <= oldVal) ? newVal : (9*oldVal + newVal) / 10;
71
+}
72
+
54
 export default {
73
 export default {
55
     /**
74
     /**
56
      * Updates the local statistics
75
      * Updates the local statistics
58
      */
77
      */
59
     updateLocalStats: function (data) {
78
     updateLocalStats: function (data) {
60
         stats = data;
79
         stats = data;
61
-        eventEmitter.emit(CQEvents.LOCALSTATS_UPDATED, 100 - stats.packetLoss.total, stats);
80
+        var newVal = 100 - stats.packetLoss.total;
81
+        localConnectionQuality =
82
+            calculateQuality(newVal, localConnectionQuality);
83
+        eventEmitter.emit(CQEvents.LOCALSTATS_UPDATED, localConnectionQuality,
84
+            stats);
62
     },
85
     },
63
 
86
 
64
     /**
87
     /**
74
         }
97
         }
75
         remoteStats[id] = data;
98
         remoteStats[id] = data;
76
 
99
 
100
+        var newVal = 100 - data.packetLoss.total;
101
+        var oldVal = remoteConnectionQuality[id];
102
+        remoteConnectionQuality[id] = calculateQuality(newVal, oldVal);
103
+
77
         eventEmitter.emit(
104
         eventEmitter.emit(
78
-            CQEvents.REMOTESTATS_UPDATED, id, 100 - data.packetLoss_total, remoteStats[id]
79
-        );
105
+            CQEvents.REMOTESTATS_UPDATED, id, remoteConnectionQuality[id],
106
+            remoteStats[id]);
80
     },
107
     },
81
 
108
 
82
     /**
109
     /**

Loading…
Cancel
Save