Use websocket in traccaar server

vishalv20507 years ago

Right now the server is a proper RESTful server, how would I go about adding websockets for specific purposes to it (just to reduce the authentication overhead for very frequent calls)

Anybody else here tried modifying the code to use websockets ?

Anton Tananaev7 years ago

Traccar already has websockets. See official web app for more details.

vishalv20507 years ago

I am looking for websockets in the traccar server. Dont see any.
Who the webapp is connecting to via websocket ? Sorely it cannot be the traccar server

vishalv20507 years ago

Ok, I see something like AsyncSocket, I will dig more from there.

Anton Tananaev7 years ago
vishalv20507 years ago

But when I try connecting to a socket at ws://0.0.0.0:8082/api/socket using a couple of chrome plugins, i cannot connect and they say "no protocol negotiations"

The API is working fine at http://0.0.0.0:8082/api

api/socket is the path that is being used in Root.js as well, so I think that is correct, what can be wrong with my setup ?

Anton Tananaev7 years ago

You need to pass authentication cookie in the header when you open socket.

Nelio Lucas6 years ago

Hi Anton, iv been having similar issues and i'd like to ask if you could give me some guidelines or an example of how id be able to pass authentication cookie in the header using a Java client

Anton Tananaev6 years ago

See native version of Traccar Manager for a Java example.

Nick6 years ago

Hello all, Anton,

The API calls are working properly, but I'm unable to utilize the websocket on my server. I tried this URI wss://<mydomain>/gps/api/socket on some firefox extensions, and the websocket opens successfully without authentication, and the only message it outputs is the positions and details of all devices. Nothing happens after that. If I disconnect and reconnect the websocket, again it outputs the same message.

How do I interact with the websocket so that it keeps live positions and events data flowing and how can I implement in vanilla JS?
Thankyou in advance.

Anton Tananaev6 years ago

Just wait and you should get live updates.