I have an app that uses socket.io (1.4.5) to establish a websocket connection. The app is available via a web URL and also as a packaged Android app using Trigger.io.
The Android app is unable to connect to my websocket server. This is the error I receive
WebSocket connection to 'wss://myserver.com/socket.io/?user_id=xxx&session_token=xxx&EIO=3&transport=websocket' failed: Unspecified reason
The line it references in the socket.io client is within the doOpen()
method.
this.ws = BrowserWebSocket ? new WebSocket(uri) : new WebSocket(uri, protocols, opts);
I haven't made any changes to the websocket server as far as I'm aware. And the website itself is running fine and able to connect to the websocket server.
I've inspected the Trigger.io Android app using Chrome Devtools and when I manually try to connect to my websocket server I get the same error. The following line of code does not work.
new WebSocket("wss://myserver.com/socket.io/?user_id=xxx&session_token=xxx&EIO=3&transport=websocket")
Running the same line of code in the Chrome browser works just fine.
Also, the error response seems too fast. It looks like the webview within the hybrid app isn't even trying to connect. The response is the same whether the websocket server is running or not. Typing in a nonsense URL gives the same error.
new WebSocket("wss://blahblah"); //gives the same error and response immediately
The Chrome version within the Trigger app is 55.0.2883.91.
EDIT : I tested the websocket connection on the mobile browser of the device running the app, just to make sure it's not a proxy / connection issue. And that worked fine.
The solution to this is to use the httpd module in Trigger.
Setting up the httpd server makes the app be served with a http://localhost
URL instead of the contents: or file: protocol. With this in place, whatever Chrome CSP issue was blocking the connection is lifted.
Module docs : https://trigger.io/modules/httpd/current/