Dynamically load TensorFlow JS

This commit is contained in:
Pierre HUBERT 2021-01-31 05:53:35 +01:00
parent 155dc45906
commit c950b4d28e
4 changed files with 8 additions and 25 deletions

View File

@ -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
*/

View File

@ -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,7 +30,7 @@ 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);

View File

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

View File

@ -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"
);
/**