1

A problem with wialon.js

Topic: A problem with wialon.js

Hi,
Probably this is a stupid question but I can't include the file wialon.js in a project. I use vue/cli 4.0.5 and in public/index.html insert it to the page:
   <div id="app"></div>
   <script src="https://hst-api.wialon.com/wsdk/script/wialon.js">     
   </script>
   <!-- built files will be auto injected -->
</body>
It does't work. What's wrong?

2

A problem with wialon.js

Re: A problem with wialon.js

Hi

You can load wialon.js dynamically. For example, like here https://github.com/wialon/wialon-app-tr … pt.js#L125

3

A problem with wialon.js

Re: A problem with wialon.js

Thank you,
I've tried something like this but still have the error 'wialon' is not defined.

/// Fetch varable from 'GET' request
let get_url_parameter = function (name, def) {
  if (!name) {
    return null;
  }
  let pairs = decodeURIComponent(document.location.search.substr(1)).split("&");
  for (let i = 0; i < pairs.length; i++) {
    let pair = pairs[i].split("=");
    if (pair[0] === name) {
      pair.splice(0, 1);
      return pair.join("=");
    }
  }
  return def || null;
};

/// Load scripts
function load_script(src, callback) {
  let script = document.createElement("script");
  script.setAttribute("type","text/javascript");
  script.setAttribute("charset","UTF-8");
  script.setAttribute("src", src);
  if (callback && typeof callback === "function") {    
      script.onload = callback;    
  }
  document.getElementsByTagName("head")[0].appendChild(script);
}[/i]

[i]let ready = (callback) => {
if (document.readyState != "loading") callback();
else document.addEventListener("DOMContentLoaded", callback);
}[/i]

[i]//DOM is ready
ready(() => {
  let branch = get_url_parameter("b","master");
  let url = get_url_parameter("baseUrl",(branch=="develop"?"https://dev-api.wialon.com":"https://hst-api.wialon.com"));
  if (!url)
    url = get_url_parameter("hostUrl","https://hosting.wialon.com");
  if (!url)
    return null;
  url += "/wsdk/script/wialon.js";  
  // load wialon sdk
  load_script(url, function() {
    let session = wialon.core.Session.getInstance();
    session.initSession('https://hst-api.wialon.com');
  });
});
4

A problem with wialon.js

Re: A problem with wialon.js

gly2008 First of all check network tab to ensure wialon.js passed through it. I think issue with you js bundler (webpack), either with your code.

Here is copy of your code on codepen and it works like a charm https://codepen.io/ashmigelski/pen/GRJJYRO?editors=0011
You can inspect JS separately https://codepen.io/ashmigelski/pen/GRJJYRO.js

5

A problem with wialon.js

Re: A problem with wialon.js

You are right, it's done now, thanks a lot!