JSPrintManager icon indicating copy to clipboard operation
JSPrintManager copied to clipboard

WebSocket connection to 'wss://localhost:25443/' failed:

Open martinapitakova opened this issue 1 year ago • 9 comments

Hi,

I'm seeking a solution for our specific use case. This script is implemented in a warehouse where employees use scanners and printers. Access to this particular interface is granted to warehouse personnel, but it's also accessible to office staff who do not have scanners or printers. We've encountered an issue where this script throws an exception repeatedly in the console, indicating a failure to connect to the websocket when office personnel access this interface. This occurs because they lack printers and scanners. We want to initiate this script only when scanners or printers are available.

The issue originates from the .start() method, which generates this error in the console. Is there a way to prevent this?

CleanShot 2023-10-26 at 09 34 31

martinapitakova avatar Oct 26 '23 07:10 martinapitakova

That specific machine where the error happens... does it have the JSPrintManager app Version 5.0 installed? Because the script is trying to connect to Version 5 of the app so if the user has installed any other version, then that could be the cause of the issue.

neodynamic avatar Oct 26 '23 11:10 neodynamic

No, that machine is the computer of a manager who works in the office, and JSPrintManager is not installed on their system. I need to prevent this error from occurring if JSPrintManager is not installed. Is there a method to check for its availability?

martinapitakova avatar Nov 02 '23 08:11 martinapitakova

If the app v5 is not installed then that error will be thrown. What you can do is to prevent it from being thrown more than once by using this setting in your website code JSPM.JSPrintManager.auto_reconnect = false;

And to know whether v5 app is installed or not then you should use this https://www.neodynamic.com/Products/Help/JSPrintManager5.0/articles/jsprintmanager.html#detecting-jspm-client-app

neodynamic avatar Nov 02 '23 13:11 neodynamic

I am getting same error, with version 6. I am trying to handle a case where user does not have JSPM installed and I would like to show an instruction/error page. Although I wrapped my code in try/catch statement, I am still getting 'uncaught' error. What is the best way to prevent this, if any? If I set auto reconnect to false, it happens only once, but it still does happen.

denisjovic avatar Dec 05 '23 14:12 denisjovic

@denisjovic we have still that issue also. :/

martinapitakova avatar Dec 05 '23 16:12 martinapitakova

I had the same problem, and I fixed it by downloading the latest version of the JSPrintManager.js file

yolao avatar Dec 18 '23 17:12 yolao

I would also like to know what else could be done. Like maybe to render a modal with instructions on how to install the client app, or at least make the user more aware that it hasn't been installed without the error showing up in console. Some clients don't need the JSPM and some do, even though they use the same product.

mprythero avatar Dec 23 '23 07:12 mprythero

The following func could be used as an alternative to detect whether the JSPM Client App is installed or not.

function is_jspm_installed(appPort) {
return new Promise((ok, er) => {
    var ws = new WebSocket("wss://localhost:" + appPort)
    ws.onmessage = (mj)=> {
      try {
        console.log(mj.data);
        let m = JSON.parse(mj.data);
        if("version" in m && "connection" in m && m["connection"] === "CONNECTED") {
          ok(true)
          return
        }
      }
      catch(e) {
        ok(false)
      }     
    }  
    ws.onerror = _ => er("Error connecting WS")
    ws.onclose = _ => er("Error connecting WS")
  })
}

Each major version uses a specific port and that func can be called as follows depending on the version of our product that your websites is using...

// For V6
is_jspm_installed(26443).then((m) => console.info("V6 is installed")).catch((m) => console.error(m))

// For V5
is_jspm_installed(25443).then((m) => console.info("V5 is installed")).catch((m) => console.error(m))

// For V4
is_jspm_installed(24443).then((m) => console.info("V4 is installed")).catch((m) => console.error(m))

neodynamic avatar Jan 09 '24 18:01 neodynamic

I use this library. So i have a problem that is JSPrintManager.js:2 WebSocket connection to 'wss://localhost:26443/' failed: in my hosted application. The Front End was deployed in AWS. However wanna solve this problem immediately. Please give me solution for me.

umayanga1997 avatar Mar 29 '24 16:03 umayanga1997