aframe.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. "use strict";
  2. // VWF & A-Frame model driver
  3. // Copyright 2017 Krestianstvo.org project
  4. //
  5. // Copyright 2012 United States Government, as represented by the Secretary of Defense, Under
  6. // Secretary of Defense (Personnel & Readiness).
  7. //
  8. // Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  9. // in compliance with the License. You may obtain a copy of the License at
  10. //
  11. // http://www.apache.org/licenses/LICENSE-2.0
  12. //
  13. // Unless required by applicable law or agreed to in writing, software distributed under the License
  14. // is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  15. // or implied. See the License for the specific language governing permissions and limitations under
  16. // the License.
  17. /// vwf/model/scenejs.js is a placeholder for a 3-D scene manager.
  18. ///
  19. /// @module vwf/model/aframe
  20. /// @requires vwf/model
  21. define(["module", "vwf/model", "vwf/utility"], function (module, model, utility) {
  22. return model.load(module, {
  23. // == Module Definition ====================================================================
  24. // -- initialize ---------------------------------------------------------------------------
  25. initialize: function () {
  26. self = this;
  27. this.state = {
  28. nodes: {},
  29. scenes: {},
  30. prototypes: {},
  31. createLocalNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  32. childSource, childType, childIndex, childName, callback) {
  33. return {
  34. "parentID": nodeID,
  35. "ID": childID,
  36. "extendsID": childExtendsID,
  37. "implementsIDs": childImplementsIDs,
  38. "source": childSource,
  39. "type": childType,
  40. "name": childName,
  41. "prototypes": undefined,
  42. "aframeObj": undefined,
  43. "scene": undefined
  44. };
  45. },
  46. isAFrameClass: function (prototypes, classID) {
  47. if (prototypes) {
  48. for (var i = 0; i < prototypes.length; i++) {
  49. if (prototypes[i] === classID) {
  50. //console.info( "prototypes[ i ]: " + prototypes[ i ] );
  51. return true;
  52. }
  53. }
  54. }
  55. return false;
  56. },
  57. isAFrameComponent: function (prototypes) {
  58. var found = false;
  59. if (prototypes) {
  60. for (var i = 0; i < prototypes.length && !found; i++) {
  61. found = (prototypes[i] === "http://vwf.example.com/aframe/node.vwf");
  62. }
  63. }
  64. return found;
  65. }
  66. };
  67. this.state.kernel = this.kernel.kernel.kernel;
  68. },
  69. // == Model API ============================================================================
  70. // -- creatingNode -------------------------------------------------------------------------
  71. creatingNode: function (nodeID, childID, childExtendsID, childImplementsIDs,
  72. childSource, childType, childIndex, childName, callback /* ( ready ) */) {
  73. // If the parent nodeID is 0, this node is attached directly to the root and is therefore either
  74. // the scene or a prototype. In either of those cases, save the uri of the new node
  75. var childURI = (nodeID === 0 ? childIndex : undefined);
  76. var appID = this.kernel.application();
  77. // If the node being created is a prototype, construct it and add it to the array of prototypes,
  78. // and then return
  79. var prototypeID = utility.ifPrototypeGetId(appID, this.state.prototypes, nodeID, childID);
  80. if (prototypeID !== undefined) {
  81. this.state.prototypes[prototypeID] = {
  82. parentID: nodeID,
  83. ID: childID,
  84. extendsID: childExtendsID,
  85. implementsID: childImplementsIDs,
  86. source: childSource,
  87. type: childType,
  88. name: childName
  89. };
  90. return;
  91. }
  92. var protos = getPrototypes(this.kernel, childExtendsID);
  93. //var kernel = this.kernel.kernel.kernel;
  94. var node;
  95. if (this.state.isAFrameComponent(protos)) {
  96. // Create the local copy of the node properties
  97. if (this.state.nodes[childID] === undefined) {
  98. this.state.nodes[childID] = this.state.createLocalNode(nodeID, childID, childExtendsID, childImplementsIDs,
  99. childSource, childType, childIndex, childName, callback);
  100. }
  101. node = this.state.nodes[childID];
  102. node.prototypes = protos;
  103. node.aframeObj = createAFrameObject(node);
  104. addNodeToHierarchy(node);
  105. //notifyDriverOfPrototypeAndBehaviorProps();
  106. }
  107. },
  108. // -- initializingProperty -----------------------------------------------------------------
  109. initializingProperty: function (nodeID, propertyName, propertyValue) {
  110. var value = undefined;
  111. var node = this.state.nodes[nodeID];
  112. if (node !== undefined) {
  113. value = this.settingProperty(nodeID, propertyName, propertyValue);
  114. }
  115. return value;
  116. },
  117. // -- creatingProperty ---------------------------------------------------------------------
  118. creatingProperty: function (nodeID, propertyName, propertyValue) {
  119. return this.initializingProperty(nodeID, propertyName, propertyValue);
  120. },
  121. // -- deletingNode -------------------------------------------------------------------------
  122. //deletingNode: function( nodeID ) {
  123. //},
  124. // -- deletingNode -------------------------------------------------------------------------
  125. deletingNode: function( nodeID ) {
  126. if ( this.state.nodes[ nodeID ] !== undefined ) {
  127. var node = this.state.nodes[ nodeID ];
  128. if ( node.aframeObj !== undefined ) {
  129. // removes and destroys object
  130. node.aframeObj.parentNode.removeChild(node.aframeObj);
  131. node.aframeObj = undefined;
  132. }
  133. delete this.state.nodes[ nodeID ];
  134. }
  135. },
  136. // -- settingProperty ----------------------------------------------------------------------
  137. settingProperty: function (nodeID, propertyName, propertyValue) {
  138. var node = this.state.nodes[nodeID];
  139. var value = undefined;
  140. if (node && node.aframeObj && utility.validObject(propertyValue)) {
  141. var aframeObject = node.aframeObj;
  142. if (isNodeDefinition(node.prototypes)) {
  143. // 'id' will be set to the nodeID
  144. value = propertyValue;
  145. switch (propertyName) {
  146. default:
  147. value = undefined;
  148. break;
  149. }
  150. }
  151. if ( value === undefined && isAEntityDefinition( node.prototypes ) ) {
  152. value = propertyValue;
  153. switch ( propertyName ) {
  154. case "interpolation":
  155. aframeObject.setAttribute('interpolation', { duration: propertyValue});
  156. break;
  157. case "position":
  158. aframeObject.setAttribute('position', { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] });
  159. break;
  160. case "rotation":
  161. aframeObject.setAttribute('rotation', { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] });
  162. break;
  163. case "scale":
  164. aframeObject.setAttribute('scale', { x: propertyValue[0], y: propertyValue[1], z: propertyValue[2] });
  165. break;
  166. case "color":
  167. aframeObject.setAttribute('color', propertyValue);
  168. break;
  169. case "fog":
  170. aframeObject.setAttribute('material','fog', propertyValue);
  171. break;
  172. case "wireframe":
  173. aframeObject.setAttribute('wireframe', propertyValue);
  174. break;
  175. case "wireframe-linewidth":
  176. aframeObject.setAttribute('wireframeLinewidth', propertyValue);
  177. break;
  178. // case "clickable":
  179. // value = propertyValue;
  180. // break;
  181. // case "clickable":
  182. // if (propertyValue) {
  183. // aframeObject.addEventListener('click', function (evt) {
  184. // vwf_view.kernel.fireEvent(node.ID, "clickEvent");
  185. // });
  186. // }
  187. // break;
  188. case "src":
  189. aframeObject.setAttribute('src', propertyValue);
  190. break;
  191. case "repeat":
  192. aframeObject.setAttribute('repeat', propertyValue);
  193. break;
  194. default:
  195. value = undefined;
  196. break;
  197. }
  198. }
  199. if ( value === undefined && aframeObject.nodeName == "A-TEXT" ) {
  200. value = propertyValue;
  201. switch ( propertyName ) {
  202. case "value":
  203. aframeObject.setAttribute('value', propertyValue);
  204. break;
  205. case "color":
  206. aframeObject.setAttribute('color', propertyValue);
  207. break;
  208. case "side":
  209. aframeObject.setAttribute('side', propertyValue);
  210. break;
  211. default:
  212. value = undefined;
  213. break;
  214. }
  215. }
  216. if ( value === undefined && aframeObject.nodeName == "A-SCENE" ) {
  217. value = propertyValue;
  218. switch ( propertyName ) {
  219. case "fog":
  220. aframeObject.setAttribute('fog', propertyValue);
  221. break;
  222. case "assets":
  223. var assetsElement = document.createElement('a-assets');
  224. aframeObject.appendChild(assetsElement);
  225. if (propertyValue) {
  226. httpGetJson(propertyValue).then(function (response) {
  227. console.log(JSON.parse(response));
  228. let assets = JSON.parse(response);
  229. for (var prop in assets) {
  230. var elm = document.createElement(assets[prop].tag);
  231. elm.setAttribute('id', prop);
  232. elm.setAttribute('src', assets[prop].src);
  233. assetsElement.appendChild(elm);
  234. }
  235. }).catch(function (error) {
  236. console.log(error);
  237. });
  238. }
  239. break;
  240. default:
  241. value = undefined;
  242. break;
  243. }
  244. }
  245. if ( value === undefined && aframeObject.nodeName == "A-BOX") {
  246. value = propertyValue;
  247. switch ( propertyName ) {
  248. case "depth":
  249. aframeObject.setAttribute('depth', propertyValue);
  250. break;
  251. case "height":
  252. aframeObject.setAttribute('height', propertyValue);
  253. break;
  254. case "width":
  255. aframeObject.setAttribute('width', propertyValue);
  256. break;
  257. default:
  258. value = undefined;
  259. break;
  260. }
  261. }
  262. if ( value === undefined && aframeObject.nodeName == "A-LIGHT" ) {
  263. value = propertyValue;
  264. switch ( propertyName ) {
  265. //"angle", "color", "decay", "distance", "ground-color", "intensity", "penumbra", "type", "target"
  266. case "color":
  267. aframeObject.setAttribute('color', propertyValue);
  268. break;
  269. case "type":
  270. aframeObject.setAttribute('type', propertyValue);
  271. break;
  272. case "intensity":
  273. aframeObject.setAttribute('intensity', propertyValue);
  274. break;
  275. case "distance":
  276. aframeObject.setAttribute('distance', propertyValue);
  277. break;
  278. default:
  279. value = undefined;
  280. break;
  281. }
  282. }
  283. if ( value === undefined && aframeObject.nodeName == "A-COLLADA-MODEL") {
  284. value = propertyValue;
  285. switch ( propertyName ) {
  286. case "src":
  287. aframeObject.setAttribute('src', propertyValue);
  288. break;
  289. default:
  290. value = undefined;
  291. break;
  292. }
  293. }
  294. if ( value === undefined && aframeObject.nodeName == "A-PLANE") {
  295. value = propertyValue;
  296. switch ( propertyName ) {
  297. case "height":
  298. aframeObject.setAttribute('height', propertyValue);
  299. break;
  300. case "width":
  301. aframeObject.setAttribute('width', propertyValue);
  302. break;
  303. default:
  304. value = undefined;
  305. break;
  306. }
  307. }
  308. if (value === undefined && aframeObject.nodeName == "A-SPHERE") {
  309. value = propertyValue;
  310. switch (propertyName) {
  311. case "radius":
  312. aframeObject.setAttribute('radius', propertyValue);
  313. break;
  314. default:
  315. value = undefined;
  316. break;
  317. }
  318. }
  319. if (value === undefined && aframeObject.nodeName == "A-CAMERA") {
  320. value = propertyValue;
  321. switch (propertyName) {
  322. case "look-controls-enabled":
  323. aframeObject.setAttribute('look-controls', 'enabled', propertyValue);
  324. break;
  325. case "forAvatar":
  326. if (propertyValue) {
  327. aframeObject.addEventListener('componentchanged', function (evt) {
  328. if (evt.detail.name === 'position') {
  329. self.kernel.fireEvent(node.ID, "setAvatarPosition", evt.detail.newData);
  330. }
  331. if (evt.detail.name === 'rotation') {
  332. self.kernel.fireEvent(node.ID, "setAvatarRotation", evt.detail.newData);
  333. //console.log('Entity has moved from', evt.detail.oldData, 'to', evt.detail.newData, '!');
  334. }
  335. });
  336. }
  337. break;
  338. default:
  339. value = undefined;
  340. break;
  341. }
  342. }
  343. //if (!aframeObject) return value;
  344. //if (propertyValue !== undefined) {
  345. //self = this;
  346. }
  347. return value;
  348. },
  349. // -- gettingProperty ----------------------------------------------------------------------
  350. gettingProperty: function (nodeID, propertyName, propertyValue) {
  351. var node = this.state.nodes[nodeID];
  352. var value = undefined;
  353. if (node && node.aframeObj) {
  354. var aframeObject = node.aframeObj;
  355. if (isNodeDefinition(node.prototypes)) {
  356. switch ( propertyName ) {
  357. }
  358. }
  359. if ( value === undefined && isAEntityDefinition( node.prototypes ) ) {
  360. switch ( propertyName ) {
  361. case "interpolation":
  362. value = aframeObject.getAttribute('interpolation');
  363. break;
  364. case "position":
  365. var pos = aframeObject.getAttribute('position');
  366. if ( pos !== undefined ){
  367. value = [pos.x, pos.y, pos.z];
  368. }
  369. break;
  370. case "scale":
  371. var scale = aframeObject.getAttribute('scale');
  372. if ( scale !== undefined ){
  373. value = [scale.x, scale.y, scale.z];
  374. }
  375. break;
  376. case "rotation":
  377. var rot = aframeObject.getAttribute('rotation');
  378. if ( rot !== undefined ){
  379. value = [rot.x, rot.y, rot.z];
  380. }
  381. break;
  382. case "color":
  383. value = aframeObject.getAttribute('color');
  384. break;
  385. case "fog":
  386. if (aframeObject.getAttribute('material')){
  387. value = aframeObject.getAttribute('material').fog;
  388. }
  389. break;
  390. case "wireframe":
  391. value = aframeObject.getAttribute('wireframe');
  392. break;
  393. case "wireframe-linewidth":
  394. value = aframeObject.getAttribute('wireframeLinewidth');
  395. break;
  396. // case "clickable":
  397. // value = propertyValue;
  398. // break;
  399. case "src":
  400. value = aframeObject.getAttribute('src');
  401. break;
  402. case "repeat":
  403. value = aframeObject.getAttribute('repeat');
  404. }
  405. }
  406. if ( value === undefined && aframeObject.nodeName == "A-SCENE" ) {
  407. switch ( propertyName ) {
  408. case "fog":
  409. value = aframeObject.getAttribute('fog');
  410. break;
  411. }
  412. }
  413. if ( value === undefined && aframeObject.nodeName == "A-BOX" ) {
  414. switch ( propertyName ) {
  415. case "depth":
  416. value = aframeObject.getAttribute('depth');
  417. break;
  418. case "height":
  419. value = aframeObject.getAttribute('height');
  420. break;
  421. case "width":
  422. value = aframeObject.getAttribute('width');
  423. break;
  424. }
  425. }
  426. if ( value === undefined && aframeObject.nodeName == "A-LIGHT" ) {
  427. //"angle", "color", "decay", "distance", "ground-color", "intensity", "penumbra", "type", "target"
  428. switch (propertyName) {
  429. case "color":
  430. value = aframeObject.getAttribute('color');
  431. break;
  432. case "type":
  433. value = aframeObject.getAttribute('type');
  434. break;
  435. case "distance":
  436. value = aframeObject.getAttribute('distance');
  437. break;
  438. case "intensity":
  439. value = aframeObject.getAttribute('intensity');
  440. break;
  441. }
  442. }
  443. if ( value === undefined && aframeObject.nodeName == "A-PLANE" ) {
  444. switch (propertyName) {
  445. case "height":
  446. value = aframeObject.getAttribute('height');
  447. break;
  448. case "width":
  449. value = aframeObject.getAttribute('width');
  450. break;
  451. }
  452. }
  453. if ( value === undefined && aframeObject.nodeName == "A-SPHERE" ) {
  454. switch (propertyName) {
  455. case "radius":
  456. value = aframeObject.getAttribute('radius');
  457. break;
  458. }
  459. }
  460. if ( value === undefined && aframeObject.nodeName == "A-TEXT" ) {
  461. switch (propertyName) {
  462. case "value":
  463. value = aframeObject.getAttribute('value');
  464. break;
  465. case "color":
  466. value = aframeObject.getAttribute('color');
  467. break;
  468. case "side":
  469. value = aframeObject.getAttribute('side');
  470. break;
  471. }
  472. }
  473. if ( value === undefined && aframeObject.nodeName == "A-CAMERA" ) {
  474. switch (propertyName) {
  475. case "look-controls-enabled":
  476. value = aframeObject.getAttribute('look-controls').enabled;
  477. break;
  478. }
  479. }
  480. if ( value === undefined && aframeObject.nodeName == "A-COLLADA-MODEL" ) {
  481. switch (propertyName) {
  482. case "src":
  483. value = aframeObject.getAttribute('src');
  484. break;
  485. }
  486. }
  487. }
  488. if ( value !== undefined ) {
  489. propertyValue = value;
  490. }
  491. return value;
  492. }
  493. });
  494. function createAFrameObject(node, config) {
  495. var protos = node.prototypes;
  496. var aframeObj = undefined;
  497. if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/ascene.vwf")) {
  498. aframeObj = document.createElement('a-scene');
  499. self.state.scenes[node.ID] = aframeObj;
  500. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/acamera.vwf")) {
  501. aframeObj = document.createElement('a-camera');
  502. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/alight.vwf")) {
  503. aframeObj = document.createElement('a-light');
  504. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/acursor.vwf")) {
  505. aframeObj = document.createElement('a-cursor');
  506. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/asky.vwf")) {
  507. aframeObj = document.createElement('a-sky');
  508. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/abox.vwf")) {
  509. aframeObj = document.createElement('a-box');
  510. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/aplane.vwf")) {
  511. aframeObj = document.createElement('a-plane');
  512. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/atext.vwf")) {
  513. aframeObj = document.createElement('a-text');
  514. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/acolladamodel.vwf")) {
  515. aframeObj = document.createElement('a-collada-model');
  516. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/asphere.vwf")) {
  517. aframeObj = document.createElement('a-sphere');
  518. } else if (self.state.isAFrameClass(protos, "http://vwf.example.com/aframe/aentity.vwf")) {
  519. aframeObj = document.createElement('a-entity');
  520. }
  521. return aframeObj;
  522. }
  523. function addNodeToHierarchy(node) {
  524. if (node.aframeObj) {
  525. if (self.state.nodes[node.parentID] !== undefined) {
  526. var parent = self.state.nodes[node.parentID];
  527. if (parent.aframeObj) {
  528. if (parent.children === undefined) {
  529. parent.children = [];
  530. }
  531. parent.children.push(node.ID);
  532. //console.info( "Adding child: " + childID + " to " + nodeID );
  533. parent.aframeObj.appendChild(node.aframeObj);
  534. }
  535. }
  536. if (node.aframeObj.nodeName !== "A-SCENE") {
  537. node.scene = self.state.scenes[self.kernel.application()];
  538. }
  539. }
  540. }
  541. function getPrototypes(kernel, extendsID) {
  542. var prototypes = [];
  543. var id = extendsID;
  544. while (id !== undefined) {
  545. prototypes.push(id);
  546. id = kernel.prototype(id);
  547. }
  548. return prototypes;
  549. }
  550. function isNodeDefinition(prototypes) {
  551. var found = false;
  552. if (prototypes) {
  553. for (var i = 0; i < prototypes.length && !found; i++) {
  554. found = (prototypes[i] == "http://vwf.example.com/aframe/node.vwf");
  555. }
  556. }
  557. return found;
  558. }
  559. function isAEntityDefinition( prototypes ) {
  560. var found = false;
  561. if ( prototypes ) {
  562. for ( var i = 0; i < prototypes.length && !found; i++ ) {
  563. found = ( prototypes[i] == "http://vwf.example.com/aframe/aentity.vwf" );
  564. }
  565. }
  566. return found;
  567. }
  568. // Changing this function significantly from the GLGE code
  569. // Will search hierarchy down until encountering a matching child
  570. // Will look into nodes that don't match.... this might not be desirable
  571. function FindChildByName(obj, childName, childType, recursive) {
  572. var child = undefined;
  573. if (recursive) {
  574. // TODO: If the obj itself has the child name, the object will be returned by this function
  575. // I don't think this this desirable.
  576. if (nameTest.call(this, obj, childName)) {
  577. child = obj;
  578. } else if (obj.children && obj.children.length > 0) {
  579. for (var i = 0; i < obj.children.length && child === undefined; i++) {
  580. child = FindChildByName(obj.children[i], childName, childType, true);
  581. }
  582. }
  583. } else {
  584. if (obj.children) {
  585. for (var i = 0; i < obj.children.length && child === undefined; i++) {
  586. if (nameTest.call(this, obj.children[i], childName)) {
  587. child = obj.children[i];
  588. }
  589. }
  590. }
  591. }
  592. return child;
  593. }
  594. function nameTest(obj, name) {
  595. if (obj.name == "") {
  596. return (obj.parent.name + "Child" == name);
  597. } else {
  598. return (obj.name == name || obj.id == name || obj.vwfID == name);
  599. }
  600. }
  601. function httpGet(url) {
  602. return new Promise(function (resolve, reject) {
  603. // do the usual Http request
  604. let request = new XMLHttpRequest();
  605. request.open('GET', url);
  606. request.onload = function () {
  607. if (request.status == 200) {
  608. resolve(request.response);
  609. } else {
  610. reject(Error(request.statusText));
  611. }
  612. };
  613. request.onerror = function () {
  614. reject(Error('Network Error'));
  615. };
  616. request.send();
  617. });
  618. }
  619. async function httpGetJson(url) {
  620. // check if the URL looks like a JSON file and call httpGet.
  621. let regex = /\.(json)$/i;
  622. if (regex.test(url)) {
  623. // call the async function, wait for the result
  624. return await httpGet(url);
  625. } else {
  626. throw Error('Bad Url Format');
  627. }
  628. }
  629. });