Sfoglia il codice sorgente

Moves loading of analytics in the library.

master
damencho 9 anni fa
parent
commit
234f3384e1

+ 1
- 4
JitsiConference.js Vedi File

@@ -8,7 +8,6 @@ var JitsiConferenceEvents = require("./JitsiConferenceEvents");
8 8
 var JitsiConferenceErrors = require("./JitsiConferenceErrors");
9 9
 var JitsiParticipant = require("./JitsiParticipant");
10 10
 var Statistics = require("./modules/statistics/statistics");
11
-var AnalyticsAdapter = require("./modules/statistics/AnalyticsAdapter");
12 11
 var JitsiDTMFManager = require('./modules/DTMF/JitsiDTMFManager');
13 12
 var JitsiTrackEvents = require("./JitsiTrackEvents");
14 13
 var JitsiTrackErrors = require("./JitsiTrackErrors");
@@ -99,8 +98,6 @@ JitsiConference.prototype._init = function (options) {
99 98
         this.statistics = new Statistics(this.xmpp, {
100 99
             callStatsID: this.options.config.callStatsID,
101 100
             callStatsSecret: this.options.config.callStatsSecret,
102
-            disableThirdPartyRequests:
103
-                this.options.config.disableThirdPartyRequests,
104 101
             roomName: this.options.name
105 102
         });
106 103
     }
@@ -787,7 +784,7 @@ function (jingleSession, jingleOffer, now) {
787 784
     // Accept incoming call
788 785
     this.room.setJingleSession(jingleSession);
789 786
     this.room.connectionTimes["session.initiate"] = now;
790
-    AnalyticsAdapter.sendEvent("muc.idle",
787
+    Statistics.analytics.sendEvent("muc.idle",
791 788
         (now - this.room.connectionTimes["muc.joined"]));
792 789
     try{
793 790
         jingleSession.initialize(false /* initiator */,this.room);

+ 6
- 7
JitsiConferenceEventManager.js Vedi File

@@ -8,7 +8,6 @@ var JitsiConferenceErrors = require("./JitsiConferenceErrors");
8 8
 var AuthenticationEvents =
9 9
     require("./service/authentication/AuthenticationEvents");
10 10
 var Statistics = require("./modules/statistics/statistics");
11
-var AnalyticsAdapter = require("./modules/statistics/AnalyticsAdapter");
12 11
 var MediaType = require("./service/RTC/MediaType");
13 12
 
14 13
 /**
@@ -99,11 +98,11 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function () {
99 98
         {
100 99
             for (var ckey in chatRoom.connectionTimes){
101 100
                 var cvalue = chatRoom.connectionTimes[ckey];
102
-                AnalyticsAdapter.sendEvent('conference.' + ckey, cvalue);
101
+                Statistics.analytics.sendEvent('conference.' + ckey, cvalue);
103 102
             }
104 103
             for (var xkey in chatRoom.xmpp.connectionTimes){
105 104
                 var xvalue = chatRoom.xmpp.connectionTimes[xkey];
106
-                AnalyticsAdapter.sendEvent('xmpp.' + xkey, xvalue);
105
+                Statistics.analytics.sendEvent('xmpp.' + xkey, xvalue);
107 106
             }
108 107
         });
109 108
 
@@ -132,7 +131,7 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function () {
132 131
         JitsiConferenceErrors.VIDEOBRIDGE_NOT_AVAILABLE);
133 132
     chatRoom.addListener(XMPPEvents.BRIDGE_DOWN,
134 133
         function (){
135
-            AnalyticsAdapter.sendEvent('conference.bridgeDown');
134
+            Statistics.analytics.sendEvent('conference.bridgeDown');
136 135
         });
137 136
 
138 137
     this.chatRoomForwarder.forward(XMPPEvents.RESERVATION_ERROR,
@@ -171,7 +170,7 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function () {
171 170
 
172 171
     chatRoom.addListener(XMPPEvents.FOCUS_LEFT,
173 172
         function () {
174
-            AnalyticsAdapter.sendEvent('conference.focusLeft');
173
+            Statistics.analytics.sendEvent('conference.focusLeft');
175 174
             if(!conference.connection._reload())
176 175
                 conference.eventEmitter.emit(
177 176
                     JitsiConferenceEvents.CONFERENCE_FAILED,
@@ -187,7 +186,7 @@ JitsiConferenceEventManager.prototype.setupChatRoomListeners = function () {
187 186
         JitsiConferenceEvents.CONNECTION_INTERRUPTED);
188 187
     chatRoom.addListener(XMPPEvents.CONNECTION_INTERRUPTED,
189 188
         function () {
190
-            AnalyticsAdapter.sendEvent('connection.interrupted');
189
+            Statistics.analytics.sendEvent('connection.interrupted');
191 190
         });
192 191
 
193 192
     this.chatRoomForwarder.forward(XMPPEvents.RECORDER_STATE_CHANGED,
@@ -451,7 +450,7 @@ JitsiConferenceEventManager.prototype.setupRTCListeners = function () {
451 450
         var now = window.performance.now();
452 451
         logger.log("(TIME) data channel opened ", now);
453 452
         conference.room.connectionTimes["data.channel.opened"] = now;
454
-        AnalyticsAdapter.sendEvent('conference.dataChannel.open', now);
453
+        Statistics.analytics.sendEvent('conference.dataChannel.open', now);
455 454
     });
456 455
 
457 456
     this.rtcForwarder.forward(RTCEvents.LASTN_CHANGED,

+ 4
- 4
JitsiConnection.js Vedi File

@@ -2,7 +2,6 @@ var JitsiConference = require("./JitsiConference");
2 2
 var XMPP = require("./modules/xmpp/xmpp");
3 3
 var JitsiConnectionEvents = require("./JitsiConnectionEvents");
4 4
 var JitsiConnectionErrors = require("./JitsiConnectionErrors");
5
-var AnalyticsAdapter = require("./modules/statistics/AnalyticsAdapter");
6 5
 
7 6
 /**
8 7
  * Creates new connection object for the Jitsi Meet server side video conferencing service. Provides access to the
@@ -26,7 +25,7 @@ function JitsiConnection(appID, token, options) {
26 25
 
27 26
     this.addEventListener(JitsiConnectionEvents.CONNECTION_FAILED,
28 27
         function (errType, msg) {
29
-            AnalyticsAdapter.sendEvent('connection.failed.' + errType);
28
+            Statistics.analytics.sendEvent('connection.failed.' + errType);
30 29
             if(errType === JitsiConnectionErrors.OTHER_ERROR &&
31 30
                 (msg === "item-not-found" || msg === "host-unknown")) {
32 31
                     // FIXME: don't report the error if we are going to reload
@@ -40,7 +39,8 @@ function JitsiConnection(appID, token, options) {
40 39
             // and then there are no msgs, but we want to log only disconnects
41 40
             // when there is real error
42 41
             if(msg)
43
-                AnalyticsAdapter.sendEvent('connection.disconnected.' + msg);
42
+                Statistics.analytics.sendEvent(
43
+                    'connection.disconnected.' + msg);
44 44
         });
45 45
 }
46 46
 
@@ -73,7 +73,7 @@ JitsiConnection.prototype.attach = function (options) {
73 73
 JitsiConnection.prototype._reload = function () {
74 74
     if(this.retryOnFail === 0)
75 75
         return false;
76
-    AnalyticsAdapter.sendEvent('connection.reload');
76
+    Statistics.analytics.sendEvent('connection.reload');
77 77
     this.retryOnFail--;
78 78
     var states = {};
79 79
     for(var name in this.conferences) {

+ 3
- 7
JitsiMeetJS.js Vedi File

@@ -16,7 +16,6 @@ var MediaType = require("./service/RTC/MediaType");
16 16
 var RTC = require("./modules/RTC/RTC");
17 17
 var RTCUIHelper = require("./modules/RTC/RTCUIHelper");
18 18
 var Statistics = require("./modules/statistics/statistics");
19
-var AnalyticsAdapter = require("./modules/statistics/AnalyticsAdapter");
20 19
 var Resolutions = require("./service/RTC/Resolutions");
21 20
 var ScriptUtil = require("./modules/util/ScriptUtil");
22 21
 var GlobalOnErrorHandler = require("./modules/util/GlobalOnErrorHandler");
@@ -67,14 +66,11 @@ var LibJitsiMeet = {
67 66
     },
68 67
     logLevels: Logger.levels,
69 68
     mediaDevices: JitsiMediaDevices,
70
-    analytics: AnalyticsAdapter,
69
+    analytics: null,
71 70
     init: function (options) {
72 71
         var logObject, attr;
73
-        Statistics.audioLevelsEnabled = !options.disableAudioLevels;
74
-
75
-        if(typeof options.audioLevelsInterval === 'number') {
76
-            Statistics.audioLevelsInterval = options.audioLevelsInterval;
77
-        }
72
+        Statistics.init(options);
73
+        this.analytics = Statistics.analytics;
78 74
 
79 75
         if (options.enableWindowOnErrorHandler) {
80 76
             GlobalOnErrorHandler.addHandler(

+ 1
- 2
doc/API.md Vedi File

@@ -50,6 +50,7 @@ The ```options``` parameter is JS object with the following properties:
50 50
     9. disableAudioLevels - boolean property. Enables/disables audio levels.
51 51
     10. disableSimulcast - boolean property. Enables/disables simulcast.
52 52
     11. enableWindowOnErrorHandler - boolean property (default false). Enables/disables attaching global onerror handler (window.onerror).
53
+    12. disableThirdPartyRequests - if true - callstats will be disabled and the callstats API won't be included.
53 54
 
54 55
 * ```JitsiMeetJS.JitsiConnection``` - the ```JitsiConnection``` constructor. You can use that to create new server connection.
55 56
 
@@ -214,8 +215,6 @@ This objects represents the server connection. You can create new ```JitsiConnec
214 215
         3. jirecon
215 216
         4. callStatsID - callstats credentials
216 217
         5. callStatsSecret - callstats credentials
217
-        6. disableThirdPartyRequests - if true - callstats will be disabled and
218
-        the callstats API won't be included.
219 218
         **NOTE: if 4 and 5 are set the library is going to send events to callstats. Otherwise the callstats integration will be disabled.**
220 219
 
221 220
 5. addEventListener(event, listener) - Subscribes the passed listener to the event.

+ 1
- 2
modules/RTC/JitsiRemoteTrack.js Vedi File

@@ -1,7 +1,6 @@
1 1
 var JitsiTrack = require("./JitsiTrack");
2 2
 var JitsiTrackEvents = require("../../JitsiTrackEvents");
3 3
 var RTCBrowserType = require("./RTCBrowserType");
4
-var AnalyticsAdapter = require("../statistics/AnalyticsAdapter");
5 4
 
6 5
 var ttfmTrackerAudioAttached = false;
7 6
 var ttfmTrackerVideoAttached = false;
@@ -120,7 +119,7 @@ JitsiRemoteTrack.prototype._attachTTFMTracker = function (container) {
120 119
             - this.conference.getConnectionTimes()["muc.joined"]);
121 120
         this.conference.getConnectionTimes()[type + ".ttfm"] = ttfm;
122 121
         console.log("(TIME) TTFM " + type + ":\t", ttfm);
123
-        AnalyticsAdapter.sendEvent(type +'.ttfm', ttfm);
122
+        Statistics.analytics.sendEvent(type +'.ttfm', ttfm);
124 123
     }.bind(this));
125 124
 };
126 125
 

+ 7
- 10
modules/statistics/AnalyticsAdapter.js Vedi File

@@ -3,27 +3,24 @@ var RTCBrowserType = require("../RTC/RTCBrowserType");
3 3
 function NoopAnalytics() {}
4 4
 NoopAnalytics.prototype.sendEvent = function () {};
5 5
 
6
+function AnalyticsAdapter() {
7
+    this.browserActionSuffix = '.' + RTCBrowserType.getBrowserName();
8
+}
9
+
6 10
 // XXX Since we asynchronously load the integration of the analytics API and the
7 11
 // analytics API may asynchronously load its implementation (e.g. Google
8 12
 // Analytics), we cannot make the decision with respect to which analytics
9 13
 // implementation we will use here and we have to postpone it i.e. we will make
10 14
 // a lazy decision.
11
-
12
-function AnalyticsAdapter() {
13
-    this.browserActionSuffix = '.' + RTCBrowserType.getBrowserName();
14
-}
15
-
16 15
 AnalyticsAdapter.prototype.sendEvent = function (action, data)
17 16
 {
18
-    var a = this.analytics;
19
-
20
-    if (a === null || typeof a === 'undefined') {
17
+    if (this.analytics === null || typeof this.analytics === 'undefined') {
21 18
         var AnalyticsImpl = window.Analytics || NoopAnalytics;
22 19
 
23
-        this.analytics = a = new AnalyticsImpl();
20
+        this.analytics = new AnalyticsImpl();
24 21
     }
25 22
     try {
26
-        a.sendEvent(action + this.browserActionSuffix, data);
23
+        this.analytics.sendEvent(action + this.browserActionSuffix, data);
27 24
     } catch (ignored) {}
28 25
 };
29 26
 

+ 36
- 1
modules/statistics/statistics.js Vedi File

@@ -4,6 +4,7 @@ var logger = require("jitsi-meet-logger").getLogger(__filename);
4 4
 var RTPStats = require("./RTPStatsCollector.js");
5 5
 var EventEmitter = require("events");
6 6
 var StatisticsEvents = require("../../service/statistics/Events");
7
+var AnalyticsAdapter = require("./AnalyticsAdapter");
7 8
 var CallStats = require("./CallStats");
8 9
 var ScriptUtil = require('../util/ScriptUtil');
9 10
 var JitsiTrackError = require("../../JitsiTrackError");
@@ -32,6 +33,21 @@ function loadCallStatsAPI() {
32 33
     // have loaded by the time we needed it (i.e. CallStats.init is invoked).
33 34
 }
34 35
 
36
+// Load the integration of a third-party analytics API such as Google Analytics.
37
+// Since we cannot guarantee the quality of the third-party service (e.g. their
38
+// server may take noticeably long time to respond), it is in our best interest
39
+// (in the sense that the intergration of the analytics API is important to us
40
+// but not enough to allow it to prevent people from joining a conference) to
41
+// download the API asynchronously. Additionally, Google Analytics will download
42
+// its implementation asynchronously anyway so it makes sense to append the
43
+// loading on our side rather than prepend it.
44
+function loadAnalytics() {
45
+    JitsiMeetJS.util.ScriptUtil.loadScript(
46
+        'analytics.js?v=1',
47
+        /* async */ true,
48
+        /* prepend */ false);
49
+}
50
+
35 51
 /**
36 52
  * Log stats via the focus once every this many milliseconds.
37 53
  */
@@ -66,6 +82,23 @@ function formatJitsiTrackErrorForCallStats(error) {
66 82
     return err;
67 83
 }
68 84
 
85
+/**
86
+ * Init statistic options
87
+ * @param options
88
+ */
89
+Statistics.init = function (options) {
90
+    Statistics.audioLevelsEnabled = !options.disableAudioLevels;
91
+
92
+    if(typeof options.audioLevelsInterval === 'number') {
93
+        Statistics.audioLevelsInterval = options.audioLevelsInterval;
94
+    }
95
+
96
+    Statistics.disableThirdPartyRequests = options.disableThirdPartyRequests;
97
+
98
+    if (Statistics.disableThirdPartyRequests !== true)
99
+        loadAnalytics();
100
+}
101
+
69 102
 function Statistics(xmpp, options) {
70 103
     this.rtpStats = null;
71 104
     this.eventEmitter = new EventEmitter();
@@ -76,7 +109,7 @@ function Statistics(xmpp, options) {
76 109
             // Even though AppID and AppSecret may be specified, the integration
77 110
             // of callstats.io may be disabled because of globally-disallowed
78 111
             // requests to any third parties.
79
-            && (this.options.disableThirdPartyRequests !== true);
112
+            && (Statistics.disableThirdPartyRequests !== true);
80 113
     if(this.callStatsIntegrationEnabled)
81 114
         loadCallStatsAPI();
82 115
     this.callStats = null;
@@ -88,6 +121,8 @@ function Statistics(xmpp, options) {
88 121
 }
89 122
 Statistics.audioLevelsEnabled = false;
90 123
 Statistics.audioLevelsInterval = 200;
124
+Statistics.disableThirdPartyRequests = false;
125
+Statistics.analytics = AnalyticsAdapter;
91 126
 
92 127
 /**
93 128
  * Array of callstats instances. Used to call Statistics static methods and

+ 2
- 2
modules/xmpp/JingleSessionPC.js Vedi File

@@ -12,7 +12,7 @@ var XMPPEvents = require("../../service/xmpp/XMPPEvents");
12 12
 var RTCBrowserType = require("../RTC/RTCBrowserType");
13 13
 var RTC = require("../RTC/RTC");
14 14
 var GlobalOnErrorHandler = require("../util/GlobalOnErrorHandler");
15
-var AnalyticsAdapter = require("../statistics/AnalyticsAdapter");
15
+var Statistics = require("../statistics/statistics");
16 16
 
17 17
 /**
18 18
  * Constant tells how long we're going to wait for IQ response, before timeout
@@ -133,7 +133,7 @@ JingleSessionPC.prototype.doInitialize = function () {
133 133
             self.peerconnection.iceConnectionState] = now;
134 134
         logger.log("(TIME) ICE " + self.peerconnection.iceConnectionState +
135 135
                     ":\t", now);
136
-        AnalyticsAdapter.sendEvent(
136
+        Statistics.analytics.sendEvent(
137 137
             'ice.' + self.peerconnection.iceConnectionState, now);
138 138
         switch (self.peerconnection.iceConnectionState) {
139 139
             case 'connected':

+ 5
- 4
modules/xmpp/strophe.jingle.js Vedi File

@@ -6,7 +6,7 @@ var JingleSession = require("./JingleSessionPC");
6 6
 var XMPPEvents = require("../../service/xmpp/XMPPEvents");
7 7
 var RTCBrowserType = require("../RTC/RTCBrowserType");
8 8
 var GlobalOnErrorHandler = require("../util/GlobalOnErrorHandler");
9
-var AnalyticsAdapter = require("../statistics/AnalyticsAdapter");
9
+var Statistics = require("../statistics/statistics");
10 10
 
11 11
 module.exports = function(XMPP, eventEmitter) {
12 12
     Strophe.addConnectionPlugin('jingle', {
@@ -101,7 +101,8 @@ module.exports = function(XMPP, eventEmitter) {
101 101
                             .up();
102 102
                         this.terminate(sess.sid);
103 103
                     }
104
-                    AnalyticsAdapter.sendEvent('xmpp.session-initiate', now);
104
+                    Statistics.analytics.sendEvent(
105
+                        'xmpp.session-initiate', now);
105 106
                     break;
106 107
                 case 'session-terminate':
107 108
                     logger.log('terminating...', sess.sid);
@@ -117,7 +118,7 @@ module.exports = function(XMPP, eventEmitter) {
117 118
                 case 'transport-replace':
118 119
                     var now = window.performance.now();
119 120
                     logger.info("(TIME) Start transport replace", now);
120
-                    AnalyticsAdapter.sendEvent(
121
+                    Statistics.analytics.sendEvent(
121 122
                         'xmpp.transport-replace.start', now);
122 123
 
123 124
                     sess.replaceTransport($(iq).find('>jingle'),
@@ -125,7 +126,7 @@ module.exports = function(XMPP, eventEmitter) {
125 126
                             var now = window.performance.now();
126 127
                             logger.info(
127 128
                                 "(TIME) Transport replace success!", now);
128
-                            AnalyticsAdapter.sendEvent(
129
+                            Statistics.analytics.sendEvent(
129 130
                                 'xmpp.transport-replace.success', now);
130 131
                         },
131 132
                         function(error) {

Loading…
Annulla
Salva