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

This commit is contained in:
Lyubomir Marinov 2016-01-25 09:36:58 -06:00
parent fe834ac9af
commit 92254e449b
5 changed files with 5651 additions and 5534 deletions

View File

@ -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.

File diff suppressed because it is too large Load Diff

32
lib-jitsi-meet.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -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).
}

View File

@ -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;