From c950b4d28e5fc7246ff4d81df597e87e26af755f Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 31 Jan 2021 05:53:35 +0100 Subject: [PATCH] Dynamically load TensorFlow JS --- assets/js/common/functionsSchema.js | 16 ---------------- assets/js/common/jsFiles.js | 10 +++++----- assets/js/components/calls/window.js | 3 +++ system/config/dev.config.php | 4 ---- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index 4446d940..8aca27d9 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -298,22 +298,6 @@ var ComunicWeb = { setStatus: function(success){}, }, - /** - * Operations on JS files - */ - jsFiles:{ - - /** - * Include a Javascript file - */ - includeFile: function(fileURL){}, - - /** - * Execute some source code contained in a variable - */ - executeJSsource: function(source){}, - }, - /** * The date library */ diff --git a/assets/js/common/jsFiles.js b/assets/js/common/jsFiles.js index 349e35ed..32e5adb9 100644 --- a/assets/js/common/jsFiles.js +++ b/assets/js/common/jsFiles.js @@ -10,13 +10,13 @@ * @param {String} fileURL The file URL * @return {Boolean} False if it fails */ -ComunicWeb.common.jsFiles.includeFile = function(fileURL){ +async function includeJS(fileURL) { var fileElem = document.createElement("script"); fileElem.type = "text/javascript"; - fileElem.src = fileURL; + fileElem.innerHTML = await (await fetch(fileURL)).text(); //Append the new element - document.body.appendChild(fileElem); + document.head.appendChild(fileElem); //Debug message ComunicWeb.debug.logMessage("Added JS file " + fileURL); @@ -30,8 +30,8 @@ ComunicWeb.common.jsFiles.includeFile = function(fileURL){ * * @param {String} source The source code to execute */ -ComunicWeb.common.jsFiles.executeJSsource = function(source){ +function executeJSsource(source){ var jsSourceContainer = document.createElement("script"); jsSourceContainer.innerHTML = source; document.body.appendChild(jsSourceContainer); -} +} \ No newline at end of file diff --git a/assets/js/components/calls/window.js b/assets/js/components/calls/window.js index 8bb3f9a4..1f2f48b9 100644 --- a/assets/js/components/calls/window.js +++ b/assets/js/components/calls/window.js @@ -993,6 +993,9 @@ class CallWindow extends CustomEvents { // Load network if required if (!this.backgroundDetectionNetwork) { + await includeJS(ComunicConfig.assetsURL + "3rdparty/tfjs/tfjs-1.2.min.js"); + await includeJS(ComunicConfig.assetsURL + "3rdparty/tensorflow-models/body-pix-2.0.js"); + this.backgroundDetectionNetwork = await bodyPix.load({ multiplier: 0.75, stride: 32, diff --git a/system/config/dev.config.php b/system/config/dev.config.php index 7ddc9fe1..19952b37 100644 --- a/system/config/dev.config.php +++ b/system/config/dev.config.php @@ -168,10 +168,6 @@ class Dev { // Record MediaStream "3rdparty/MediaStreamRecorder.min.js", - - // TensorflowJS - "3rdparty/tfjs/tfjs-1.2.min.js", - "3rdparty/tensorflow-models/body-pix-2.0.js" ); /**