Connection refused to server deployed on AWS

Summary: I have OV, server, and application all running on the same AWS machine. When I try to connect to a session I get “POST http ://localhost:5442/api/sessions net::ERR_CONNECTION_REFUSED”.

Details:

(1) Running OV 2.23 on an AWS machine, with docker-compose.override.yml removed.

(2) I’m running the server from the tutorials using node. I modified .env to have OPENVIDU_URL=http://localhost:5443/
and my own secret.

I also modified index.js so it listens on 5442:
server.listen(5442, () => {

(3) I’m running the filter-tutorial application server, with this change to app.js:
var APPLICATION_SERVER_URL = “http://localhost:5442/”;

(4) I’m tunneling into AWS’s localhost by using localtunnel. The landing page is served, but then when I click on “Join”, nothing happens and I see the “connection refused” message on the console.

Any help? Thanks!

Hello @OM-user , I don’t think a tunneling would work entirely, you need to share more than one port for this to work.

Why don’t you deploy your app with a FQDN as stated in the documentation?

Regards

Thanks for suggestion. I did that, but still getting the same error.

Details: I set up a FQDN, used letsencrypt, got the OV deployment going, and was able to connect directly to it and to the “call” application.

Then I removed docker-compose.override.yml.

I installed the tutorials, and modified the server’s .env to have
OPENVIDU_URL=http://localhost:5443/
and my own secret.

I also modified index.js so it listens on 5442:
server.listen(5442, () => {

(3) I’m running the filter-tutorial application server, with this change to app.js:
var APPLICATION_SERVER_URL = “http://localhost:5442/”;

And I opened up port 8080 and get the filter-app’s landing page. But then when I hit the “join” button, I just get the message that I can’t connect to localhost:5442/api/sessions

I think I am understanding your issue. It is not working because your browser is literally trying to connect to http://localhost:5442/ . You need to put in this line…

var APPLICATION_SERVER_URL = “http://localhost:5442/”;

… the URL of your server. So suppose your domain name is server.openvidu.io, then your application server URL will be…

var APPLICATION_SERVER_URL = “https://server.openvidu.io/”;

What will happen is that all the request will pass through the main openvidu-proxy to the Application Server (which is listening as you said at port 5442), and then, the Application Server will communicate with OpenVidu through OPENVIDU_URL=http://localhost:5443)

Regards,
Carlos

Thanks Carlos! That was indeed what was causing the error, and it’s no longer complaining about that. But now I’m not getting anything when I click “join”, and about 30 seconds later I get a timeout message on the console:

POST http://MYHOST.COM:5442/api/sessions net::ERR_CONNECTION_TIMED_OUT

Ummm, is this in the browser. Remove the port 5442 from the URL configured in your frontend.

The idea is that this frontend webpage communicates with the Application Server. It is deployed in the server at port 5442, but exposed at port 443 because of the openvidu-proxy service.

Yes, in the browser. I modified the APPLICATION_SERVER_URL to remove the 5442 port specification. Now I get this error in the browser console:

OpenVidu initialized
OpenViduLogger.ts:246 Platform detected: Chrome 107.0.0.0 on OS X 10.15.7 64-bit
OpenViduLogger.ts:246 openvidu-browser version: 2.23.0
vc.makefair.ai/:1 Access to XMLHttpRequest at ‘http://vc.makefair.ai/api/sessions’ from origin ‘http://vc.makefair.ai:8080’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: Redirect is not allowed for a preflight request.
jquery-3.3.1.min.js:2 POST http://vc.makefair.ai/api/sessions net::ERR_FAILED

Hi,

You are making your requests with http instead of https. Try to change that :slight_smile:

Where do I make that change? I changed the APPLICATION_SERVER_URL to be https but I still get the same error (“Access to XMLHttpRequest at 'http: …”) which makes me think that’s not the right variable to be changing.

Check the source code which reach the browser and the APPLICATION_SERVER_URL. Maybe the .js file is cached in the browser and changing the APPLICATION_SERVER_URL is not taking any effect.

But it is for sure that variable. The requests are done in this part of the app.js : openvidu-tutorials/app.js at v2.23.0 · OpenVidu/openvidu-tutorials · GitHub

You’re right - I just tried it again and it worked, so probably a caching issue. Thank you, and immediately on to the next issue. I get served a new page when I hit “join”, but I get this error on the browser console:

OpenVidu initialized
OpenViduLogger.ts:246 Platform detected: Chrome 107.0.0.0 on OS X 10.15.7 64-bit
OpenViduLogger.ts:246 openvidu-browser version: 2.23.0
OpenViduLogger.ts:225 STUN/TURN server IP: XXX
OpenViduLogger.ts:225 TURN credentials XXX
OpenViduLogger.ts:246 openvidu-server version: 2.23.0
OpenViduLogger.ts:246 ‘Connection’ created (local)
OpenViduLogger.ts:267 getMediaError: TypeError: Cannot read properties of undefined (reading ‘getUserMedia’)
OpenViduLogger.error @ OpenViduLogger.ts:267
OpenViduLogger.ts:267 Publisher initialization failed. GENERIC_ERROR: TypeError: Cannot read properties of undefined (reading ‘getUserMedia’)
OpenViduLogger.error @ OpenViduLogger.ts:267

Be careful, you are exposing your IP and turn credentials right now.

Well, it seems like your browser is not being able to get the device. Are you using the webcam in another program? Did you give your browser permissions to get the device?

Thanks for the warning - edited my previous message.

I’m not using the webcam in another program. I’m able to access it through other programs (e.g. google meet). I looked at the Chrome camera permissions, nuked the URL and refreshed, and same result. I also get the same result on other browser (Safari). But I also do not get a dialog asking me if it’s ok to access the camera and mic, so the problem is perhaps happening before the attempt to access the camera??

The method getUserMedia() returns undefined when the frontend application is deployed in an insecure context (over http instead of https). (See the TypeError exception MediaDevices.getUserMedia() - Web APIs | MDN).

You need to deploy your frontend app over https for getUserMedia() to work.

You may notice that this does not happen if you use localhost. This is because browsers allow insecure context over localhost, for development purposes I guess.

Regards

For a quick test, you can open Google Chrome with this flag: --unsafely-treat-insecure-origin-as-secure="vc.makefair.ai". In this way, the insecure context will be ignored for your domain name.

Anyway, for production, you will need to expose your frontend app over HTTPS.

Woohoo! Thanks Carlos for all your help.

Hey @OM-user ,
Did It work? :slight_smile:

Yes! I responded to the discourse thread but maybe it didn’t go through? Anyway, thanks for all your help and have a great weekend.

1 Like