Ver código fonte

Creates connection quality module.

j8
hristoterezov 10 anos atrás
pai
commit
e20274c2f7

+ 0
- 2
app.js Ver arquivo

@@ -834,8 +834,6 @@ $(document).ready(function () {
834 834
         APIConnector.init();
835 835
 
836 836
     UI.start();
837
-    statistics.addConnectionStatsListener(ConnectionQuality.updateLocalStats);
838
-    statistics.addRemoteStatsStopListener(ConnectionQuality.stopSendingStats);
839 837
     statistics.start();
840 838
     
841 839
     Moderator.init();

+ 0
- 127
connectionquality.js Ver arquivo

@@ -1,127 +0,0 @@
1
-var ConnectionQuality = (function () {
2
-
3
-    /**
4
-     * Constructs new ConnectionQuality object
5
-     * @constructor
6
-     */
7
-    function ConnectionQuality() {
8
-
9
-    }
10
-
11
-    /**
12
-     * local stats
13
-     * @type {{}}
14
-     */
15
-    var stats = {};
16
-
17
-    /**
18
-     * remote stats
19
-     * @type {{}}
20
-     */
21
-    var remoteStats = {};
22
-
23
-    /**
24
-     * Interval for sending statistics to other participants
25
-     * @type {null}
26
-     */
27
-    var sendIntervalId = null;
28
-
29
-    /**
30
-     * Updates the local statistics
31
-     * @param data new statistics
32
-     */
33
-    ConnectionQuality.updateLocalStats = function (data) {
34
-        stats = data;
35
-        UI.updateLocalConnectionStats(100 - stats.packetLoss.total,stats);
36
-        if(sendIntervalId == null)
37
-        {
38
-            startSendingStats();
39
-        }
40
-    };
41
-
42
-    /**
43
-     * Start statistics sending.
44
-     */
45
-    function startSendingStats() {
46
-        sendStats();
47
-        sendIntervalId = setInterval(sendStats, 10000);
48
-    }
49
-
50
-    /**
51
-     * Sends statistics to other participants
52
-     */
53
-    function sendStats() {
54
-        connection.emuc.addConnectionInfoToPresence(convertToMUCStats(stats));
55
-        connection.emuc.sendPresence();
56
-    }
57
-
58
-    /**
59
-     * Converts statistics to format for sending through XMPP
60
-     * @param stats the statistics
61
-     * @returns {{bitrate_donwload: *, bitrate_uplpoad: *, packetLoss_total: *, packetLoss_download: *, packetLoss_upload: *}}
62
-     */
63
-    function convertToMUCStats(stats) {
64
-        return {
65
-            "bitrate_download": stats.bitrate.download,
66
-            "bitrate_upload": stats.bitrate.upload,
67
-            "packetLoss_total": stats.packetLoss.total,
68
-            "packetLoss_download": stats.packetLoss.download,
69
-            "packetLoss_upload": stats.packetLoss.upload
70
-        };
71
-    }
72
-
73
-    /**
74
-     * Converts statitistics to format used by VideoLayout
75
-     * @param stats
76
-     * @returns {{bitrate: {download: *, upload: *}, packetLoss: {total: *, download: *, upload: *}}}
77
-     */
78
-    function parseMUCStats(stats) {
79
-        return {
80
-            bitrate: {
81
-                download: stats.bitrate_download,
82
-                upload: stats.bitrate_upload
83
-            },
84
-            packetLoss: {
85
-                total: stats.packetLoss_total,
86
-                download: stats.packetLoss_download,
87
-                upload: stats.packetLoss_upload
88
-            }
89
-        };
90
-    }
91
-
92
-    /**
93
-     * Updates remote statistics
94
-     * @param jid the jid associated with the statistics
95
-     * @param data the statistics
96
-     */
97
-    ConnectionQuality.updateRemoteStats = function (jid, data) {
98
-        if(data == null || data.packetLoss_total == null)
99
-        {
100
-            UI.updateConnectionStats(jid, null, null);
101
-            return;
102
-        }
103
-        remoteStats[jid] = parseMUCStats(data);
104
-
105
-        UI.updateConnectionStats(jid, 100 - data.packetLoss_total,remoteStats[jid]);
106
-
107
-    };
108
-
109
-    /**
110
-     * Stops statistics sending.
111
-     */
112
-    ConnectionQuality.stopSendingStats = function () {
113
-        clearInterval(sendIntervalId);
114
-        sendIntervalId = null;
115
-        //notify UI about stopping statistics gathering
116
-        UI.onStatsStop();
117
-    };
118
-
119
-    /**
120
-     * Returns the local statistics.
121
-     */
122
-    ConnectionQuality.getStats = function () {
123
-        return stats;
124
-    }
125
-
126
-    return ConnectionQuality;
127
-})();

+ 1
- 1
index.html Ver arquivo

@@ -30,6 +30,7 @@
30 30
     <script src="service/RTC/RTCBrowserType.js?v=1"></script>
31 31
     <script src="service/RTC/StreamEventTypes.js?v=1"></script>
32 32
     <script src="service/RTC/MediaStreamTypes.js?v=1"></script>
33
+    <script src="libs/modules/connectionquality.bundle.js?v=1"></script>
33 34
     <script src="libs/modules/UI.bundle.js?v=1"></script>
34 35
     <script src="libs/modules/statistics.bundle.js?v=1"></script>
35 36
     <script src="libs/modules/RTC.bundle.js?v=1"></script>
@@ -40,7 +41,6 @@
40 41
     <script src="util.js?v=7"></script><!-- utility functions -->
41 42
     <script src="moderatemuc.js?v=4"></script><!-- moderator plugin -->
42 43
     <script src="analytics.js?v=1"></script><!-- google analytics plugin -->
43
-    <script src="connectionquality.js?v=1"></script>
44 44
     <script src="moderator.js?v=2"></script><!-- media stream -->
45 45
     <script src="tracking.js?v=1"></script><!-- tracking -->
46 46
     <script src="api_connector.js?v=2"></script>

+ 1
- 1
libs/modules/UI.bundle.js Ver arquivo

@@ -3782,7 +3782,7 @@ ConnectionIndicator.prototype.generateText = function () {
3782 3782
     }
3783 3783
 
3784 3784
     var resolutionValue = null;
3785
-    if(this.resolution)
3785
+    if(this.resolution && this.jid != null)
3786 3786
     {
3787 3787
         var keys = Object.keys(this.resolution);
3788 3788
         if(keys.length == 1)

+ 122
- 0
libs/modules/connection_quality.bundle.js Ver arquivo

@@ -0,0 +1,122 @@
1
+!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;"undefined"!=typeof window?n=window:"undefined"!=typeof global?n=global:"undefined"!=typeof self&&(n=self),n.connectionquality=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2
+/**
3
+ * local stats
4
+ * @type {{}}
5
+ */
6
+var stats = {};
7
+
8
+/**
9
+ * remote stats
10
+ * @type {{}}
11
+ */
12
+var remoteStats = {};
13
+
14
+/**
15
+ * Interval for sending statistics to other participants
16
+ * @type {null}
17
+ */
18
+var sendIntervalId = null;
19
+
20
+
21
+/**
22
+ * Start statistics sending.
23
+ */
24
+function startSendingStats() {
25
+    sendStats();
26
+    sendIntervalId = setInterval(sendStats, 10000);
27
+}
28
+
29
+/**
30
+ * Sends statistics to other participants
31
+ */
32
+function sendStats() {
33
+    connection.emuc.addConnectionInfoToPresence(convertToMUCStats(stats));
34
+    connection.emuc.sendPresence();
35
+}
36
+
37
+/**
38
+ * Converts statistics to format for sending through XMPP
39
+ * @param stats the statistics
40
+ * @returns {{bitrate_donwload: *, bitrate_uplpoad: *, packetLoss_total: *, packetLoss_download: *, packetLoss_upload: *}}
41
+ */
42
+function convertToMUCStats(stats) {
43
+    return {
44
+        "bitrate_download": stats.bitrate.download,
45
+        "bitrate_upload": stats.bitrate.upload,
46
+        "packetLoss_total": stats.packetLoss.total,
47
+        "packetLoss_download": stats.packetLoss.download,
48
+        "packetLoss_upload": stats.packetLoss.upload
49
+    };
50
+}
51
+
52
+/**
53
+ * Converts statitistics to format used by VideoLayout
54
+ * @param stats
55
+ * @returns {{bitrate: {download: *, upload: *}, packetLoss: {total: *, download: *, upload: *}}}
56
+ */
57
+function parseMUCStats(stats) {
58
+    return {
59
+        bitrate: {
60
+            download: stats.bitrate_download,
61
+            upload: stats.bitrate_upload
62
+        },
63
+        packetLoss: {
64
+            total: stats.packetLoss_total,
65
+            download: stats.packetLoss_download,
66
+            upload: stats.packetLoss_upload
67
+        }
68
+    };
69
+}
70
+
71
+
72
+var ConnectionQuality = {
73
+    /**
74
+     * Updates the local statistics
75
+     * @param data new statistics
76
+     */
77
+    updateLocalStats: function (data) {
78
+        stats = data;
79
+        UI.updateLocalConnectionStats(100 - stats.packetLoss.total, stats);
80
+        if (sendIntervalId == null) {
81
+            startSendingStats();
82
+        }
83
+    },
84
+
85
+    /**
86
+     * Updates remote statistics
87
+     * @param jid the jid associated with the statistics
88
+     * @param data the statistics
89
+     */
90
+    updateRemoteStats: function (jid, data) {
91
+        if (data == null || data.packetLoss_total == null) {
92
+            UI.updateConnectionStats(jid, null, null);
93
+            return;
94
+        }
95
+        remoteStats[jid] = parseMUCStats(data);
96
+
97
+        UI.updateConnectionStats(jid, 100 - data.packetLoss_total, remoteStats[jid]);
98
+
99
+    },
100
+
101
+    /**
102
+     * Stops statistics sending.
103
+     */
104
+    stopSendingStats: function () {
105
+        clearInterval(sendIntervalId);
106
+        sendIntervalId = null;
107
+        //notify UI about stopping statistics gathering
108
+        UI.onStatsStop();
109
+    },
110
+
111
+    /**
112
+     * Returns the local statistics.
113
+     */
114
+    getStats: function () {
115
+        return stats;
116
+    }
117
+
118
+};
119
+
120
+module.exports = ConnectionQuality;
121
+},{}]},{},[1])(1)
122
+});

+ 2
- 0
libs/modules/statistics.bundle.js Ver arquivo

@@ -969,6 +969,8 @@ var statistics =
969 969
     },
970 970
 
971 971
     start: function () {
972
+        this.addConnectionStatsListener(connection_quality.updateLocalStats);
973
+        this.addRemoteStatsStopListener(connection_quality.stopSendingStats);
972 974
         RTC.addStreamListener(onStreamCreated,
973 975
             StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
974 976
     }

+ 119
- 0
modules/connection_quality/connection_quality.js Ver arquivo

@@ -0,0 +1,119 @@
1
+/**
2
+ * local stats
3
+ * @type {{}}
4
+ */
5
+var stats = {};
6
+
7
+/**
8
+ * remote stats
9
+ * @type {{}}
10
+ */
11
+var remoteStats = {};
12
+
13
+/**
14
+ * Interval for sending statistics to other participants
15
+ * @type {null}
16
+ */
17
+var sendIntervalId = null;
18
+
19
+
20
+/**
21
+ * Start statistics sending.
22
+ */
23
+function startSendingStats() {
24
+    sendStats();
25
+    sendIntervalId = setInterval(sendStats, 10000);
26
+}
27
+
28
+/**
29
+ * Sends statistics to other participants
30
+ */
31
+function sendStats() {
32
+    connection.emuc.addConnectionInfoToPresence(convertToMUCStats(stats));
33
+    connection.emuc.sendPresence();
34
+}
35
+
36
+/**
37
+ * Converts statistics to format for sending through XMPP
38
+ * @param stats the statistics
39
+ * @returns {{bitrate_donwload: *, bitrate_uplpoad: *, packetLoss_total: *, packetLoss_download: *, packetLoss_upload: *}}
40
+ */
41
+function convertToMUCStats(stats) {
42
+    return {
43
+        "bitrate_download": stats.bitrate.download,
44
+        "bitrate_upload": stats.bitrate.upload,
45
+        "packetLoss_total": stats.packetLoss.total,
46
+        "packetLoss_download": stats.packetLoss.download,
47
+        "packetLoss_upload": stats.packetLoss.upload
48
+    };
49
+}
50
+
51
+/**
52
+ * Converts statitistics to format used by VideoLayout
53
+ * @param stats
54
+ * @returns {{bitrate: {download: *, upload: *}, packetLoss: {total: *, download: *, upload: *}}}
55
+ */
56
+function parseMUCStats(stats) {
57
+    return {
58
+        bitrate: {
59
+            download: stats.bitrate_download,
60
+            upload: stats.bitrate_upload
61
+        },
62
+        packetLoss: {
63
+            total: stats.packetLoss_total,
64
+            download: stats.packetLoss_download,
65
+            upload: stats.packetLoss_upload
66
+        }
67
+    };
68
+}
69
+
70
+
71
+var ConnectionQuality = {
72
+    /**
73
+     * Updates the local statistics
74
+     * @param data new statistics
75
+     */
76
+    updateLocalStats: function (data) {
77
+        stats = data;
78
+        UI.updateLocalConnectionStats(100 - stats.packetLoss.total, stats);
79
+        if (sendIntervalId == null) {
80
+            startSendingStats();
81
+        }
82
+    },
83
+
84
+    /**
85
+     * Updates remote statistics
86
+     * @param jid the jid associated with the statistics
87
+     * @param data the statistics
88
+     */
89
+    updateRemoteStats: function (jid, data) {
90
+        if (data == null || data.packetLoss_total == null) {
91
+            UI.updateConnectionStats(jid, null, null);
92
+            return;
93
+        }
94
+        remoteStats[jid] = parseMUCStats(data);
95
+
96
+        UI.updateConnectionStats(jid, 100 - data.packetLoss_total, remoteStats[jid]);
97
+
98
+    },
99
+
100
+    /**
101
+     * Stops statistics sending.
102
+     */
103
+    stopSendingStats: function () {
104
+        clearInterval(sendIntervalId);
105
+        sendIntervalId = null;
106
+        //notify UI about stopping statistics gathering
107
+        UI.onStatsStop();
108
+    },
109
+
110
+    /**
111
+     * Returns the local statistics.
112
+     */
113
+    getStats: function () {
114
+        return stats;
115
+    }
116
+
117
+};
118
+
119
+module.exports = ConnectionQuality;

+ 2
- 0
modules/statistics/statistics.js Ver arquivo

@@ -126,6 +126,8 @@ var statistics =
126 126
     },
127 127
 
128 128
     start: function () {
129
+        this.addConnectionStatsListener(connection_quality.updateLocalStats);
130
+        this.addRemoteStatsStopListener(connection_quality.stopSendingStats);
129 131
         RTC.addStreamListener(onStreamCreated,
130 132
             StreamEventTypes.EVENT_TYPE_LOCAL_CREATED);
131 133
     }

+ 1
- 1
muc.js Ver arquivo

@@ -140,7 +140,7 @@ Strophe.addConnectionPlugin('emuc', {
140 140
             Strophe.forEachChild(stats[0], "stat", function (el) {
141 141
                 statsObj[el.getAttribute("name")] = el.getAttribute("value");
142 142
             });
143
-            ConnectionQuality.updateRemoteStats(from, statsObj);
143
+            connection_quality.updateRemoteStats(from, statsObj);
144 144
         }
145 145
 
146 146
         // Parse status.

Carregando…
Cancelar
Salvar