|
@@ -1,3 +1,6 @@
|
|
1
|
+var currentExecutingScript = require("current-executing-script");
|
|
2
|
+
|
|
3
|
+
|
1
|
4
|
/**
|
2
|
5
|
* Implements utility functions which facilitate the dealing with scripts such
|
3
|
6
|
* as the download and execution of a JavaScript file.
|
|
@@ -12,21 +15,38 @@ var ScriptUtil = {
|
12
|
15
|
* @param prepend true to schedule the loading of the script as soon as
|
13
|
16
|
* possible or false to schedule the loading of the script at the end of the
|
14
|
17
|
* scripts known at the time
|
|
18
|
+ * @param relativeURL whether we need load the library from url relative
|
|
19
|
+ * to the url that lib-jitsi-meet was loaded. Useful when sourcing the
|
|
20
|
+ * library from different location than the app that is using it
|
15
|
21
|
*/
|
16
|
|
- loadScript: function (src, async, prepend) {
|
|
22
|
+ loadScript: function (src, async, prepend, relativeURL) {
|
17
|
23
|
var d = document;
|
18
|
24
|
var tagName = 'script';
|
19
|
25
|
var script = d.createElement(tagName);
|
20
|
26
|
var referenceNode = d.getElementsByTagName(tagName)[0];
|
21
|
27
|
|
22
|
28
|
script.async = async;
|
|
29
|
+
|
|
30
|
+ if (relativeURL) {
|
|
31
|
+ // finds the src url of the current loaded script
|
|
32
|
+ // and use it as base of the src supplied argument
|
|
33
|
+ var scriptEl = currentExecutingScript();
|
|
34
|
+ if(scriptEl) {
|
|
35
|
+ var scriptSrc = scriptEl.src;
|
|
36
|
+ var baseScriptSrc
|
|
37
|
+ = scriptSrc.substring(0, scriptSrc.lastIndexOf('/') + 1);
|
|
38
|
+ if (scriptSrc && baseScriptSrc)
|
|
39
|
+ src = baseScriptSrc + src;
|
|
40
|
+ }
|
|
41
|
+ }
|
|
42
|
+
|
23
|
43
|
script.src = src;
|
24
|
44
|
if (prepend) {
|
25
|
45
|
referenceNode.parentNode.insertBefore(script, referenceNode);
|
26
|
46
|
} else {
|
27
|
47
|
referenceNode.parentNode.appendChild(script);
|
28
|
48
|
}
|
29
|
|
- },
|
|
49
|
+ }
|
30
|
50
|
};
|
31
|
51
|
|
32
|
52
|
module.exports = ScriptUtil;
|