Skip to content

Commit

Permalink
updated localhost fetch function (#56)
Browse files Browse the repository at this point in the history
* updated localhost fetch function

* simplified localhost check

* removed a log
  • Loading branch information
samankittani authored Jan 18, 2024
1 parent 9b2627f commit 9e62af9
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 27 deletions.
18 changes: 16 additions & 2 deletions extensions/AugmentedReality/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
(async function () {

let videoMirrored = false;

const localhost = (await fetch('http://localhost:8000/extensions/AugmentedReality/index.js')).ok;

async function checkLocalhost(){
try {
const response = await fetch('http://localhost:8000/extensions/AugmentedReality/index.js');
if (!response.ok) {
console.log('INFO: Failed to reach localhost');
return false;
}else{
return true;
}
} catch (error) {
console.log("INFO: localhost fetch failed with error", error)
return false;
}
}
const localhost = await checkLocalhost();
const root = localhost? 'http://localhost:8000/' : 'https://extensions.netsblox.org/';

const rendererURL = root + 'extensions/AugmentedReality/js/renderModule.mjs';
Expand Down
2 changes: 1 addition & 1 deletion extensions/AugmentedReality/js/renderModule.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as handModule from '../../HandGestures/handLandmarkerModule.mjs';
import * as tagModule from './tagHandler.mjs';
import * as filters from './filters.mjs';

const localhost = (await fetch('http://localhost:8000/extensions/AugmentedReality/js/renderModule.mjs')).ok;
const localhost = window.location.search.includes('localhost');
const root = localhost? 'http://localhost:8000/' : 'https://extensions.netsblox.org/';

const models = {};
Expand Down
2 changes: 0 additions & 2 deletions extensions/AugmentedReality/js/tagHandler.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const positVersion = 1;

const localhost = (await fetch('http://localhost:8000/extensions/AugmentedReality/js/tagHandler.mjs')).ok;

class aprilTagHandler {
constructor() {
this.detector = new AR.Detector({dictionaryName: 'APRILTAG_16h5'});
Expand Down
17 changes: 2 additions & 15 deletions extensions/AugmentedReality/js/ui-morphs.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
let root = 'https://extensions.netsblox.org/';
fetch('http://localhost:8000/extensions/AugmentedReality/js/ui-morphs.js')
.then((value) => {
root = 'http://localhost:8000/';
})
.catch(() => {
//do nothing
})
.finally(() => {
console.log('done checking for localhost');
});

function ArucoGenMorph (){
this.init();
}
const localhost = window.location.search.includes('localhost');
const root = localhost? 'http://localhost:8000/' : 'https://extensions.netsblox.org/';

ArucoGenMorph.prototype = new DialogBoxMorph();
ArucoGenMorph.prototype.constructor = ArucoGenMorph;
Expand Down
4 changes: 2 additions & 2 deletions extensions/FaceLandmarker/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(async function () {

const localhost = (await fetch('http://localhost:8000/extensions/FaceLandmarker/index.js')).ok;
const localhost = window.location.search.includes('localhost');
const root = localhost? 'http://localhost:8000/' : 'https://extensions.netsblox.org/';

const DEVURL = {
Expand Down
17 changes: 16 additions & 1 deletion extensions/HandGestures/handLandmarkerModule.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
const localhost = (await fetch('http://localhost:8000/extensions/HandGestures/handLandmarkerModule.mjs')).ok;
async function checkLocalhost(){
try {
const response = await fetch('http://localhost:8000/extensions/HandGestures/handLandmarkerModule.mjs');
if (!response.ok) {
console.log('INFO: Failed to reach localhost');
return false;
}else{
return true;
}
} catch (error) {
console.log("INFO: localhost fetch failed with error", error)
return false;
}
}

const localhost = await checkLocalhost();
const root = localhost? 'http://localhost:8000/' : 'https://extensions.netsblox.org/';

const DEVURL = {
Expand Down
3 changes: 1 addition & 2 deletions extensions/HandGestures/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(async function () {

const localhost = (await fetch('http://localhost:8000/extensions/HandGestures/handLandmarkerModule.mjs')).ok;
const localhost = window.location.search.includes('localhost');
const root = localhost? 'http://localhost:8000/' : 'https://extensions.netsblox.org/';

const moduleURL = root + 'extensions/HandGestures/handLandmarkerModule.mjs';
Expand Down
3 changes: 1 addition & 2 deletions extensions/PoseLandmarker/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(async function () {

const localhost = (await fetch('http://localhost:8000/extensions/PoseLandmarker/index.js')).ok;
const localhost = window.location.search.includes('localhost');
const root = localhost? 'http://localhost:8000/' : 'https://extensions.netsblox.org/';

const DEVURL = {
Expand Down

0 comments on commit 9e62af9

Please sign in to comment.