1

Remove item from session

Тема: Remove item from session

Hi every one.

Does any of you know how to remove an item from the session using JS SDK?

Lets say i start a new session and load units to it with this code:

var mySess=wialon.core.Session.getInstance();
mySess.initSession("https://hst-api.wialon.com");
mySess.loadLibrary("itemProfileFields");
mySess.loginToken(TOKEN,"",function (code) {
    if (code) console.log(wialon.core.Errors.getErrorText(code));
    var flags = wialon.item.Item.dataFlag.base;
    mySess.updateDataFlags(
        [{type: "type", data: "avl_unit", flags: flags, mode: 0}],
        function (code) {
                console.log(mySess.getItems("avl_unit"));
     });
 })
;

Then while this session stays active add a new unit to it through CMS, after executing mySess.updateDataflags() and mySess.getItems("avl_unit") i get previous loaded units +1.

But after going again to CMS and revoking access to one unit I just cant find a way to unload it from the active session.
I've tried changing the flags, type, data and mode params in the updateDataFlags method as described in these links:

https://sdk.wialon.com/wiki/en/kit/remo … datafalags
https://sdk.wialon.com/wiki/en/local/re … data_flags

Also checked mySess.searchItems() and myUser.getItemsAccess(), both responses have the right number of units.
Is there any way to update the avl_unit? also is there any way to set a Listener to detech those changes?

2

Remove item from session

Re: Remove item from session

Hello. SDK caches all items, that you are loaded into session and just don't know, that you don't have access to it anymore.

There is two ways to tell SDK to actualize state:

  • session.findNewItems('avl_unit', false, true, callback); (I don't really know, what flags are doing)
  • sdk.s.startNewItemsChecking({ avl_unit: 1 });

First way does searchItems for all items and compares available items with actual and adds/removes items. It must be called manually every time when you think, that you have new/removed items.

Second way is preferred, it subscribes for every access gain/loosing and automatically subscribes for base data flag of new items and removes deleted items from the session. There can be 3-15 seconds delay between actual access grant/revoke and event receiving, depends on the server load.

When new item is available, itemCreated event emitted on the session object. When item removed — itemDeleted event emitted on the item object.

3

Remove item from session

Re: Remove item from session

Thank you so much Rual.

This is just what i needed