Web Socket /api/socket

George Paok 6 years ago

So after searching at the forums of traccar, i realized that,
if someone wants to use web sockets. The only way is to through a
pop up for signing in traccar.
https://github.com/traccar/traccar/issues/2547

Creating or getting a session is not enough for handshake.
Am i right? If i call the /session from another web app to the /api. Then Handshake for web sockets cannot be done. Although the session return the user.
With this example :
https://github.com/traccar/traccar/issues/2547
a pop up is showing in my web page. to make a login. but again the hand shake not workign.

Anton Tananaev 6 years ago

It works for the official web app, so clearly it's possible.

George Paok 6 years ago

Ok! Thank you very much. Traccar is awesome

Tony Shelver 6 years ago

Some sample python code that works for me and showing it working.

    signal.signal(signal.SIGINT, signal_handler)

    session = requests.Session()

#    payload = {'email': email, 'password': password}
    payload = {'email': l_uid, 'password': l_pwd}
    params = urlencode(payload, quote_via=quote_plus)

    # params = urllib.urlencode({'email': email, 'password': password})

    headers = {'content-type': 'application/x-www-form-urlencoded',
               'accept': 'application/json'}
    # response = session.post('http://' + url + '/api/session',
    #                         data=params,
    #                         headers=headers)
    response = session.post('http://' + l_url +':' + l_port + '/api/session',
                            data=params,
                            headers=headers)
    print('after connect')
    cookies = session.cookies.get_dict()
    token= cookies['JSESSIONID']

    if response.status_code == 200:
            print("Authentication successfull, Token: " + token)
    else:
            print("Authentication failed, Status:" + response.status_code)
            sys.exit()