Selective device data send on WebSocket to users

shahaba year ago

Hello,
In Traccar when you create a device and assigned a device to a user and when that user login, websocket will send live data of only that device to users. I am a backend developer but doesn’t have expertises on java, but i tried to find how does it work., but unable to understand. If anyone can explain, it would be helpful
Thank you

RastreameMXa year ago

As far as my understand, traccar web is just a interface that connects to traccar via API (websocket), requests info associated with the user account, and adapts it to display correctly on map.

So, if you add a device and enroll it to a specific user account, all users that log in with that specific user account should get new device info on next API request. When the interface receives device information, process it and displays it on devices menu, and map point. That's why it's not neccesary do F5 refresh to display new devices. Each interface receive new device list on new request.

After that, when you do something related with that device (like report request) web interface request the report to traccar server, traccar server verify that the user token have enough permissions to get information about that deviceid, anf if that's true, server answers to web interface with the positions related.

Each request made to traccar server, user token is sent to the server, so Traccar Server can verify what permissions have that user account, and deny or grant the request accordingly.

Greets.

shahaba year ago

Thanks Eduardo for your response
"When the interface receives device information, process it and displays it on devices menu, and map point."
are you saying that traccar will send all vehicle data in websocket but the web app only shows the relevant?

RastreameMXa year ago

No.

I'm saying that, by example, for position update i think that web interface request last position for each device in list. It could be according to internal time range of each device or not, i don't know, but in that case i believe that just last position for each device in list is requested.

For reports, request depends on period selected, so server answers with positions related with the selected period of time.

For commands is the same, when you get into commands window, web interface requests list of enrolled commands with that device and identifies itself with login token. If user have no permission to send commands, then the request will fail. If the user token have permission to use commands, then list of commands enrolled to the device is in the response.

That same happens with preferences and account data.

You could look into modern web interface source code to understand what requests are done and when, and what information answers the server. But Traccar always try to request minimum necesary information, to save resources.

Forgive my bad english please.

Greets.

shahaba year ago

I think you didn’t t get my question, i am only talking about websocket. let me once again explain it
let say I am admin and i have 10 vehicles register in my traccar then i will got live message of it in websocket (https://ibb.co/jwVJFKp)
i have created another user called B and assigned 5 vehicles to it. Now when user B login in its websocket he will see live message of only those 5 allotted vehicles.
Now since traccar is receiving live message for all vehicle, he has to filter or do some buisness logic so that vehicle message will send to(front end/web app) only those ws connection which have it access.
Now my question is how this filter is been done as it is a realtime thing or what is the exact business logic behind it
Thanks

Track-tracea year ago

Doesnt it seem logic to you that traccar web only update the devices which are associated to the user account ?
Thats what the database is for, user account, devices association. Why would it have anything to do with filtering ?

shahaba year ago

I am not talking about traccar web, when you create websocket connection, it is the server who are sending vehicle information.
I have 1200+ vehicles and each vehicles sends data every 5 sec so traccar server is constantly getting all of the vehicles data, now traccar server will decide that which updated vehicle data should be send to which websocket connection.
For example
There is a vehicle V-001, now this is associated with 3 users. whenever V-001 data comes to traccar server, the server will do logic like database query and findout the users(websocket connection) of it, then it send that updated data to those users.
If server do database query to findout users for each vehicle, then i dont think it will be able to handle this amount of data which is not the case.
I want to know the whole process of when traccar receive vehicle information and how he able to send to a particular websocket connection