1

Nodejs API

(23/04/2019 21:33:43 отредактировано soporte3)

Тема: Nodejs API

Hi to all,

Recently we started a new project in which we are trying to use wialon.js in node.js to be able to execute some tasks at a specifict time. At this point we tried using:
wialonjs-api
wialon_sdk by LeXXaT
Even tried mocking the window object through(qooxdoo and browser-env which is an implementation of jsdom).

In all of them we are able to initialize a Session instance, but cant send any request, it just goes idle for a moment then returns a "Error performing request"

We've alredy checked other post where the solution is to build our own appy from the gorund, but we strongly believe in running wialon.js in node because we could create some services from previous developments without much effort.

Do you believe it to be possible?

2

Nodejs API

Re: Nodejs API

Hello.

Tried to run example from playground with node, slighly patched it to use NodeHttp, do not use window references.

Code with built wialon.js — https://gist.github.com/Rulexec/04877df … 9896ef919b

$ node units.js 
Logged successfully
unit Audi_retr
unit Chevrolet El Camino
unit Buick Skylark Convertible
...

I do not guarantee, that it will work for all cases (defenitely sure, that file uploads will not work), this js sdk is not intendent to work outside browsers.

I hope, that sdk will be open-sourced somewhen and it will be possible to maintain ability to work under node.

3

Nodejs API

Re: Nodejs API

Hi rual .

Thank you so much for this it looks so awesome and sounds great about letting it to be open-sourced, I hope to hear more about it.

Now I'll try some extra examples.

4

Nodejs API

Re: Nodejs API

Hi again.

This has been pretty useful, but now I'm facing a little problem, when trying to create a Linear Geofence about 600 points within, it throws an error:

 at r.__recieveMessage (...\wialon.node.js:5803:59)

after some debugging found that its related to the requets uri being too long because it uses http.get. For this case I'll use a custom function for making the request, but would be great if you could take a look into this.

5

Nodejs API

Re: Nodejs API

soporte3 пишет:

after some debugging found that its related to the requets uri being too long because it uses http.get. For this case I'll use a custom function for making the request, but would be great if you could take a look into this.

Hi. Sorry for late response. Replaced http.get by POST-request.

I updated gist with new wialon.js file.

6

Nodejs API

Re: Nodejs API

Thanks rual

Looks really good, I'm gonna try it.

7

Nodejs API

Re: Nodejs API

Hi agian,

This time im in need to send a batch for creating multiple zones and some notifications, but i cant figure out how to use the sdk for this. I found 2 methods startBatch() and finishBatch(), but cant make it work.

8

Nodejs API

Re: Nodejs API

Sorry, i just realized that theres is an example in the playground. It's working now

9

Nodejs API

Re: Nodejs API

rual

Since a few weeks ago I detected my app crashing whenever a network loss occurred, even a small one. After some digging around found this comes from this function:

__recieveMessage: function(counter) {
                    var callback = this._callbacks[counter];
                    if (callback) {
                        debugger;
                        var tm1 = new Date,
                            data =eval("(" + callback[6] + ")");//When callback[6]="" causes the eval to fail.
                        if (data) {
                            if (data.error && 1003 == data.error && callback[3] < 3) return callback[3]++, callback[6] = "", callback[4] && callback[5] && (clearTimeout(callback[5]), callback[5] = setTimeout(qx.lang.Function.bind(this.__timeout, this, counter), 1e3 * callback[4])), void setTimeout(qx.lang.Function.bind(function(e) {
                                this.__postMessage(counter)
                            }, this, counter), 1e3 * Math.random());
                            callback[0] && callback[0](data), callback[4] && callback[5] && clearTimeout(callback[5]), delete this._callbacks[counter]
                        } else callback[1]()
                    }
                }

whenever the network fails callback[6] gets the value of an empty string and causes eval to fail, tried to fix it doing this:

data = callback[6]=="" ? false : eval("(" + callback[6] + ")");

It worked in a quick test but I'm not sure about it being the right solution. By the time I'm handling this crashes with pm2.

10

Nodejs API

Re: Nodejs API

Hello. We are trying to eliminate those evals (they are legacy of usage non-ECMA-404 JSON with hexidecimals (0xff)).

I replaced it by JSON.parse.