Problem regarding sockJS with Client Library

Hello,

I've tried to use the JavaScript Client Library to connect to push updates, but I can't seem to initialize the SockJS Object.

Here's the error message:

Uncaught TypeError: SockJS is not a constructor
    at OctoPrintSocketClient.connect (http://127.0.0.1:5000/static/webassets/packed_client.js:488:23)

my relevant code:

<script src="./node_modules/jquery/dist/jquery.min.js"></script>
<script src="http://127.0.0.1:5000/static/js/lib/lodash.min.js"></script>
<script src="http://127.0.0.1:5000/static/webassets/packed_client.js"></script>

...

OctoPrint.options.baseurl = "http://127.0.0.1:5000/"
OctoPrint.options.apikey = "11D742B6682D46709154B045CC222B0D";

OctoPrint.files.list()
  .done(function (response)
  {
    console.log(response)
    // do something with the response
  });
OctoPrint.socket.connect()

The file list works without problem.
Tried to use reconnect instead of connect, but same issue.
Does someone know what could be my error?

Used OctoPrint Version: 1.3.10.post5+g8ce2290d

If you want to use the socket you also need to include the sockjs library in your scripts.

1 Like

oh I somehow thought that was included with the packed client file. Thanks! :smiley: