浏览代码

Changes the way of calculating connection quality.

j8
hristoterezov 9 年前
父节点
当前提交
99e6453e09
共有 1 个文件被更改,包括 30 次插入3 次删除
  1. 30
    3
      modules/connectionquality/connectionquality.js

+ 30
- 3
modules/connectionquality/connectionquality.js 查看文件

@@ -18,6 +18,16 @@ var stats = {};
18 18
  */
19 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 32
  * Converts statistics to format used by VideoLayout
23 33
  * @param stats
@@ -51,6 +61,15 @@ function parseMUCStats(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 73
 export default {
55 74
     /**
56 75
      * Updates the local statistics
@@ -58,7 +77,11 @@ export default {
58 77
      */
59 78
     updateLocalStats: function (data) {
60 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,9 +97,13 @@ export default {
74 97
         }
75 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 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
     /**

正在加载...
取消
保存