Parcourir la source

Asynchronously downloads the callstats.io API because the third-party server may take 'forever' to respond.

j8
Lyubomir Marinov il y a 9 ans
Parent
révision
ca3dd8865f
2 fichiers modifiés avec 38 ajouts et 6 suppressions
  1. 0
    1
      index.html
  2. 38
    5
      modules/statistics/CallStats.js

+ 0
- 1
index.html Voir le fichier

@@ -225,7 +225,6 @@
225 225
     <script type="text/javascript">
226 226
       if (!config.disableThirdPartyRequests) {
227 227
         [
228
-          'https://api.callstats.io/static/callstats.min.js',
229 228
           // FIXME The implementation provided by analytics.js starts an
230 229
           // asynchronous download of the Google Analytics integration.
231 230
           // Unfortunately, modules/statistics/AnalyticsAdapter.js has already

+ 38
- 5
modules/statistics/CallStats.js Voir le fichier

@@ -18,16 +18,49 @@ var wrtcFuncNames = {
18 18
     getUserMedia:         "getUserMedia"
19 19
 };
20 20
 
21
-// some errors may happen before CallStats init
22
-// in this case we accumulate them in this array
23
-// and send them to callstats on init
21
+/**
22
+ * Some errors may occur before CallStats.init in which case we will accumulate 
23
+ * them and submit them to callstats.io on CallStats.init.
24
+ */
24 25
 var pendingErrors = [];
25 26
 
26 27
 function initCallback (err, msg) {
27 28
     console.log("CallStats Status: err=" + err + " msg=" + msg);
28 29
 }
29 30
 
30
-var callStatsIntegrationEnabled = config.callStatsID && config.callStatsSecret;
31
+/**
32
+ * The indicator which determines whether the integration of callstats.io is
33
+ * enabled/allowed. Its value does not indicate whether the integration will
34
+ * succeed at runtime but rather whether it is to be attempted at runtime at
35
+ * all.
36
+ */
37
+var _enabled
38
+    = config.callStatsID && config.callStatsSecret
39
+        // Even though AppID and AppSecret may be specified, the integration of
40
+        // callstats.io may be disabled because of globally-disallowed requests
41
+        // to any third parties.
42
+        && (config.disableThirdPartyRequests !== true);
43
+
44
+if (_enabled) {
45
+    // Since callstats.io is a third party, we cannot guarantee the quality of
46
+    // their service. More specifically, their server may take noticeably long
47
+    // time to respond. Consequently, it is in our best interest (in the sense
48
+    // that the intergration of callstats.io is pretty important to us but not
49
+    // enough to allow it to prevent people from joining a conference) to (1)
50
+    // start downloading their API as soon as possible and (2) do the
51
+    // downloading asynchronously.
52
+    (function (d, src) {
53
+        var elementName = 'script';
54
+        var newScript = d.createElement(elementName);
55
+        var referenceNode = d.getElementsByTagName(elementName)[0];
56
+
57
+        newScript.async = true;
58
+        newScript.src = src;
59
+        referenceNode.parentNode.insertBefore(newScript, referenceNode);
60
+    })(document, 'https://api.callstats.io/static/callstats.min.js');
61
+    // FIXME At the time of this writing, we hope that the callstats.io API will
62
+    // have loaded by the time we needed it (i.e. CallStats.init is invoked).
63
+}
31 64
 
32 65
 /**
33 66
  * Returns a function which invokes f in a try/catch block, logs any exception
@@ -101,7 +134,7 @@ var CallStats = {
101 134
      * false.
102 135
      */
103 136
     isEnabled: function() {
104
-        return callStatsIntegrationEnabled;
137
+        return _enabled;
105 138
     },
106 139
 
107 140
     pcCallback: _try_catch(function (err, msg) {

Chargement…
Annuler
Enregistrer