How to enable WebSockets?

sanger 10 months ago

Hi, how can I enable WebSockets? In my /opt/traccar/conf/traccar.xml file is nothing about Enabling or Disabling WebSockets, just Database settings.
I added following line into the traccar.xml file:

<entry key='web.socket.enabled'>true</entry>

When I'm trying to connect to the WebSocket, it immediately closes the connection.
Any ideas?

Anton Tananaev 10 months ago

WebSockets are enabled by default.

sanger 10 months ago

This is how I try to connect and display it on the map with a marker:

WebSockets.PNG

I also tried to connect with PieHost WebSocket Tester (https://piehost.com/websocket-tester), it immediately closes the connection (doesnt even ask me for login credentials, a token or something else)

Anton Tananaev 10 months ago

What you're doing likely won't work because of security restrictions of the browser. It won't ask you for a login. It needs a session cookie.

sanger 10 months ago

You mean the JSessionID?

Anton Tananaev 10 months ago

Yes.

sanger 10 months ago

I tried, still doesn't work.
Does the Website needs to be in the same VPS as the Traccar Server? Because I am doing it from my localhost with xampp.

I added these 2 configs into traccar.xml:

    <entry key='websocket.enable'>true</entry>
    <entry key='web.origin'>*</entry>

It still doesnt work. I dont know what I'm doing wrong haha
I just want to get the location of the devices with websocket in html, css, php and js.
I dont want to do every 10 secs a request from /api/positions so websocket would be really great

Anton Tananaev 10 months ago

Adding made up configuration parameters certainly won't help with anything. Have you checked official documentation first?

sanger 10 months ago

I did, but I don't know what to do.
Does the Website needs to be in the same VPS as the Traccar Server? Because I am doing it from my localhost with xampp, and my traccar server is on my linux vps

sanger 10 months ago

I figured it out, it has to be on the same Server.
But how do I do it then when doing my own iOS App? Is there a method?

Anton Tananaev 10 months ago

iOS app doesn't have the same restrictions as a browser.