瀏覽代碼

Introduces a utility function to load optional scripts such as callstats.io.

master
Lyubomir Marinov 9 年之前
父節點
當前提交
ea8fbf8697
共有 5 個檔案被更改,包括 13982 行新增13865 行删除
  1. 10
    1
      JitsiMeetJS.js
  2. 13919
    13839
      lib-jitsi-meet.js
  3. 16
    16
      lib-jitsi-meet.min.js
  4. 5
    9
      modules/statistics/statistics.js
  5. 32
    0
      modules/util/ScriptUtil.js

+ 10
- 1
JitsiMeetJS.js 查看文件

@@ -9,6 +9,7 @@ var Logger = require("jitsi-meet-logger");
9 9
 var RTC = require("./modules/RTC/RTC");
10 10
 var Statistics = require("./modules/statistics/statistics");
11 11
 var Resolutions = require("./service/RTC/Resolutions");
12
+var ScriptUtil = require("./modules/util/ScriptUtil");
12 13
 
13 14
 function getLowerResolution(resolution) {
14 15
     if(!Resolutions[resolution])
@@ -128,7 +129,15 @@ var LibJitsiMeet = {
128 129
     },
129 130
     enumerateDevices: function (callback) {
130 131
         RTC.enumerateDevices(callback);
131
-    }
132
+    },
133
+
134
+    /**
135
+     * Represents a hub/namespace for utility functionality which may be of
136
+     * interest to LibJitsiMeet clients.
137
+     */
138
+    util: {
139
+        ScriptUtil: ScriptUtil,
140
+    },
132 141
 };
133 142
 
134 143
 //Setups the promise object.

+ 13919
- 13839
lib-jitsi-meet.js
文件差異過大導致無法顯示
查看文件


+ 16
- 16
lib-jitsi-meet.min.js
文件差異過大導致無法顯示
查看文件


+ 5
- 9
modules/statistics/statistics.js 查看文件

@@ -4,6 +4,7 @@ var RTPStats = require("./RTPStatsCollector.js");
4 4
 var EventEmitter = require("events");
5 5
 var StatisticsEvents = require("../../service/statistics/Events");
6 6
 var CallStats = require("./CallStats");
7
+var ScriptUtil = require('../util/ScriptUtil');
7 8
 
8 9
 // Since callstats.io is a third party, we cannot guarantee the quality of
9 10
 // their service. More specifically, their server may take noticeably long
@@ -13,15 +14,10 @@ var CallStats = require("./CallStats");
13 14
 // start downloading their API as soon as possible and (2) do the
14 15
 // downloading asynchronously.
15 16
 function loadCallStatsAPI() {
16
-    (function (d, src) {
17
-        var elementName = 'script';
18
-        var newScript = d.createElement(elementName);
19
-        var referenceNode = d.getElementsByTagName(elementName)[0];
20
-
21
-        newScript.async = true;
22
-        newScript.src = src;
23
-        referenceNode.parentNode.insertBefore(newScript, referenceNode);
24
-    })(document, 'https://api.callstats.io/static/callstats.min.js');
17
+    ScriptUtil.loadScript(
18
+            'https://api.callstats.io/static/callstats.min.js',
19
+            /* async */ true,
20
+            /* prepend */ true);
25 21
     // FIXME At the time of this writing, we hope that the callstats.io API will
26 22
     // have loaded by the time we needed it (i.e. CallStats.init is invoked).
27 23
 }

+ 32
- 0
modules/util/ScriptUtil.js 查看文件

@@ -0,0 +1,32 @@
1
+/**
2
+ * Implements utility functions which facilitate the dealing with scripts such
3
+ * as the download and execution of a JavaScript file.
4
+ */
5
+var ScriptUtil = {
6
+    /**
7
+     * Loads a script from a specific source.
8
+     *
9
+     * @param src the source from the which the script is to be (down)loaded
10
+     * @param async true to asynchronously load the script or false to
11
+     * synchronously load the script
12
+     * @param prepend true to schedule the loading of the script as soon as
13
+     * possible or false to schedule the loading of the script at the end of the
14
+     * scripts known at the time
15
+     */
16
+    loadScript: function (src, async, prepend) {
17
+        var d = document;
18
+        var tagName = 'script';
19
+        var script = d.createElement(tagName);
20
+        var referenceNode = d.getElementsByTagName(tagName)[0];
21
+
22
+        script.async = async;
23
+        script.src = src;
24
+        if (prepend) {
25
+            referenceNode.parentNode.insertBefore(script, referenceNode);
26
+        } else {
27
+            referenceNode.parentNode.appendChild(script);
28
+        }
29
+    },
30
+};
31
+
32
+module.exports = ScriptUtil;

Loading…
取消
儲存