(function () { /* in userData root object "feedback": { "eventName": "LoadTest_11_17_2018" }, "signup": { "linkURL": "https://highfidelity.com/futvre-lands" }, "apps": ["https://hifi-content.s3.amazonaws.com/Experiences/LoadTest/VoteApp/Final/V8/voteApp.js"] */ var FEEDBACK_CURRENT_EVENTNAME = "io.highfidelity.feedbackApp.currentEventName"; var SIGNUP_APP_SETTING = 'io.highfidelity.signup.app.url'; var VOTE_APP_FILE = 'voteApp.js'; var PREV_VERS_VOTE_APP_FILE = "https://hifi-content.s3.amazonaws.com/Experiences/LoadTest/VoteApp/Final/V7/voteApp.js"; var appList = []; var userData; function getRunningURLList () { var scriptList = ScriptDiscoveryService.getRunning(); var urlList = scriptList.map(function (scriptInfo) { return scriptInfo.url; }); return urlList; } function runScript(url) { var urlList = getRunningURLList(); Script.setTimeout(function () { if (urlList.indexOf(url) === -1) { ScriptDiscoveryService.loadScript(url); } }, 500); } var feedback = { /* feedback: { eventName: "LoadTest_11_17_2018" } */ isSetup: false, defaultURL: "http://hifi-content.s3-us-west-1.amazonaws.com/Experiences/LoadTest/AppLoader/Apps/Feedback/feedback_loader.js", url: "", setup: function () { this.isSetup = true; Settings.setValue(FEEDBACK_CURRENT_EVENTNAME, userData.feedback.eventName); this.url = userData.feedback.url ? userData.feedback.url : this.defaultURL; runScript(this.url); }, unload: function () { this.isSetup = false; ScriptDiscoveryService.stopScript(this.url); } } var signup = { /* signup: { linkURL: "eventbrite.com" } */ isSetup: false, defaultURL: "http://hifi-content.s3-us-west-1.amazonaws.com/Experiences/LoadTest/AppLoader/Apps/Signup/SignupApp_loader.js", url: "", setup: function () { this.isSetup = true; if (userData.signup.linkURL) { Settings.setValue(SIGNUP_APP_SETTING, userData.signup.linkURL); } this.url = userData.signup.url ? userData.signup.url : this.defaultURL; runScript(this.url); }, unload: function () { this.isSetup = false; ScriptDiscoveryService.stopScript(this.url); } } var AppsToLoad = function () {} AppsToLoad.prototype = { preload: function (id) { var properties = Entities.getEntityProperties(id, ["userData"]); try { userData = JSON.parse(properties.userData); } catch (e) { console.error("Error parsing userData: ", e); } if (userData) { if (userData.feedback) { feedback.setup(); } if (userData.signup) { signup.setup(); } if (userData.apps) { if (Array.isArray(userData.apps)) { appList = userData.apps; Script.setTimeout(function () { var urlList = getRunningURLList(); // check for previous vote app and unload if found if (urlList.indexOf(PREV_VERS_VOTE_APP_FILE) !== -1) { ScriptDiscoveryService.stopScript(PREV_VERS_VOTE_APP_FILE); } appList.forEach(function (url) { runScript(url); }); }, 500); } else { console.error("AppsToLoad: userData.apps is not an array!"); } } } }, unload: function () { if (feedback.isSetup) { feedback.unload(); } if (signup.isSetup) { signup.unload(); } if (appList.length) { appList.forEach(function (url) { if (url.indexOf(VOTE_APP_FILE) === -1) { // do not unload voteApp.js ScriptDiscoveryService.stopScript(url); } }); } } }; return new AppsToLoad (); })