Introduces a utility function to load optional scripts such as callstats.io.
This commit is contained in:
parent
fe834ac9af
commit
92254e449b
|
@ -9,6 +9,7 @@ var Logger = require("jitsi-meet-logger");
|
|||
var RTC = require("./modules/RTC/RTC");
|
||||
var Statistics = require("./modules/statistics/statistics");
|
||||
var Resolutions = require("./service/RTC/Resolutions");
|
||||
var ScriptUtil = require("./modules/util/ScriptUtil");
|
||||
|
||||
function getLowerResolution(resolution) {
|
||||
if(!Resolutions[resolution])
|
||||
|
@ -128,7 +129,15 @@ var LibJitsiMeet = {
|
|||
},
|
||||
enumerateDevices: function (callback) {
|
||||
RTC.enumerateDevices(callback);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Represents a hub/namespace for utility functionality which may be of
|
||||
* interest to LibJitsiMeet clients.
|
||||
*/
|
||||
util: {
|
||||
ScriptUtil: ScriptUtil,
|
||||
},
|
||||
};
|
||||
|
||||
//Setups the promise object.
|
||||
|
|
11096
lib-jitsi-meet.js
11096
lib-jitsi-meet.js
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
|
@ -4,6 +4,7 @@ var RTPStats = require("./RTPStatsCollector.js");
|
|||
var EventEmitter = require("events");
|
||||
var StatisticsEvents = require("../../service/statistics/Events");
|
||||
var CallStats = require("./CallStats");
|
||||
var ScriptUtil = require('../util/ScriptUtil');
|
||||
|
||||
// Since callstats.io is a third party, we cannot guarantee the quality of
|
||||
// their service. More specifically, their server may take noticeably long
|
||||
|
@ -13,15 +14,10 @@ var CallStats = require("./CallStats");
|
|||
// start downloading their API as soon as possible and (2) do the
|
||||
// downloading asynchronously.
|
||||
function loadCallStatsAPI() {
|
||||
(function (d, src) {
|
||||
var elementName = 'script';
|
||||
var newScript = d.createElement(elementName);
|
||||
var referenceNode = d.getElementsByTagName(elementName)[0];
|
||||
|
||||
newScript.async = true;
|
||||
newScript.src = src;
|
||||
referenceNode.parentNode.insertBefore(newScript, referenceNode);
|
||||
})(document, 'https://api.callstats.io/static/callstats.min.js');
|
||||
ScriptUtil.loadScript(
|
||||
'https://api.callstats.io/static/callstats.min.js',
|
||||
/* async */ true,
|
||||
/* prepend */ true);
|
||||
// FIXME At the time of this writing, we hope that the callstats.io API will
|
||||
// have loaded by the time we needed it (i.e. CallStats.init is invoked).
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Implements utility functions which facilitate the dealing with scripts such
|
||||
* as the download and execution of a JavaScript file.
|
||||
*/
|
||||
var ScriptUtil = {
|
||||
/**
|
||||
* Loads a script from a specific source.
|
||||
*
|
||||
* @param src the source from the which the script is to be (down)loaded
|
||||
* @param async true to asynchronously load the script or false to
|
||||
* synchronously load the script
|
||||
* @param prepend true to schedule the loading of the script as soon as
|
||||
* possible or false to schedule the loading of the script at the end of the
|
||||
* scripts known at the time
|
||||
*/
|
||||
loadScript: function (src, async, prepend) {
|
||||
var d = document;
|
||||
var tagName = 'script';
|
||||
var script = d.createElement(tagName);
|
||||
var referenceNode = d.getElementsByTagName(tagName)[0];
|
||||
|
||||
script.async = async;
|
||||
script.src = src;
|
||||
if (prepend) {
|
||||
referenceNode.parentNode.insertBefore(script, referenceNode);
|
||||
} else {
|
||||
referenceNode.parentNode.appendChild(script);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = ScriptUtil;
|
Loading…
Reference in New Issue