Why is my webRTC host not working properly? - webrtc

I made a video chat app that doesn't want to work when I change the host. If I create a peer like this:
const myPeer = new Peer({
host: '/',
port: 443,
})
`
and then run peerjs --port 443 everything works fine, I get client connected: client_id printed on the console.
But if I change the host to something like host: 'some-webrtc-project.herokuapp.com' and then refresh the page, I get the message client disconnected: client_id in console and I can't connect again. Also I don't get any erroros. But if I switch host back to '/' it works fine.

Related

Selenium firefox driver forces https

I have a functional app running in a docker on port 3000. I have selenium tests that works when I set my host to http://localhost:3000. I created a container to launch the selenium tests and it fails with the following error:
WebDriverError:Reachederrorpage:about:neterror?e=nssFailure2&u=https://app:3000/&c=UTF-8&f=regular&d=An error occurred during a connection to app:3000.
SSL received a record that exceeded the maximum permissible length.
Error code: <a id="errorCode" title="SSL_ERROR_RX_RECORD_TOO_LONG">SSL_ERROR_RX_RECORD_TOO_LONG</a>
Snippet of my docker-compose.yml
app:
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- ./:/usr/src/app/
ports:
- "3000:3000"
- "3001:3001"
networks:
tests:
selenium-tester:
build:
context: .
dockerfile: Dockerfile.selenium.tests
volumes:
- ./:/usr/src/app/
- /dev/shm:/dev/shm
depends_on:
- app
networks:
tests:
I replaced the host by http://app:3000 but firefox seems to want to redirect this http to https (which is not working). And finally I build my driver like this:
const ffoptions = new firefox.Options()
.headless()
.setPreference('browser.urlbar.autoFill', 'false'); // test to disable auto https redirect… not working obviously
const driver = Builder()
.setFirefoxOptions(ffoptions)
.forBrowser('firefox')
.build();
When manually contacting the http://app:3000 using curl inside the selenium-tester container it works as expected, I get my homepage.
I'm short on ideas now and even decomposing my problem to write this question didn't get me new ones
I had exactly the same problem - couldn't successfully make request on HTTP to app from Selenium-controlled browsers (Chrome or Firefox) in other Docker container on same network. cURL from that container though worked fine! Connect on HTTP, but something seemed to be trying to force HTTPS. Identical situation right down to the name of the container "app".
The answer is... it's the name of the container!
"app" is a top level domain on the HSTS preloaded list - that is, browsers will force access through HTTPS.
Fix is to use a container name that isn't on HSTS preloaded lists.
HSTS - more reading
As you mentioned manually contacting the http://app:3000 using curl inside the selenium-tester container it works as expected
This error message...
WebDriverError:Reachederrorpage:about:neterror?e=nssFailure2&u=https://app:3000/&c=UTF-8&f=regular&d=An error occurred during a connection to app:3000.
SSL received a record that exceeded the maximum permissible length.
Error code: <a id="errorCode" title="SSL_ERROR_RX_RECORD_TOO_LONG">SSL_ERROR_RX_RECORD_TOO_LONG</a>
...implies that SSL layer in curl or one of its dependencies seems broken.
#RussellFulton in this discussion mentioned:
This seems to be the result you see from Firefox when the server is not configured properly for SSL. Possibly Chrome would have just gave a generic ssl failed error.
This can happen when the browser sends a SSL handshake when the server is expecting an HTTP request. Server responds with a 400 code and an error message that is much bigger that the handshake message that the browser expects. Hence you see the message.
Reasons and Solution
When the error prone code tries to redirect to HTTPS on port 80 (port 3000 in your case).
Solution: Removing the port 80 (port 3000 in your case) from the url, the redirect works.
HTTPS by default runs over port 443.
This error also occurs when you have enabled the SSL module.
Solution: You have run a2enmod ssl.
a2enmod ssl
//or
a2ensite default-ssl
Provided a wrong IP in the ssl config.
Solution: Changed IP to what it should be.
Remove the IP if not needed in the ssl config.
Solution: Change
VirtualHost your.domain.com:443
//to
VirtualHost default:443
curl: (35) SSL received a record that exceeded the maximum permissible length. issue was discussed at length.
As per Curl Support HTTPS proxy and SOCKS+HTTP(s) there was another attempt to get the HTTPS proxy support into Curl.
This curl commit should have addressed your issue.

Accessing localhost outside of server

I am new to node.js and am trying to get into the hang of actually using it. I am very familiar with JavaScript so the language itself is self-explanatory but the use of Node.js is quite different from the browser implementation.
I have my own remote virtual server and have installed Node and the Package Manager and everything works as expected. I am not exactly a server extraordinaire and have limited experience with the Terminal and Apache Configurations.
I can run my server using:
nodejs index.js
Which gives me: listening on *:3300 as expected.
I can then access my localhost from the terminal using: curl http://localhost:3300/ which gives me the response I expect.
Given that the website that links to my server is https://example.com, how do I allow this link to access: http://localhost:3300/ so that I can actually use my node server in production? For example, http://localhost:3300/ runs a Socket Server that I would like to use using Socket.io on https://example.com/chat.html with the JavaScript:
var socket = io.connect('http://localhost:3300/', {transports: ['websocket'], upgrade: false});
Ok, this question has nothing to do with nodeJS.
localhost is a hostname that means this computer. it's equivalent to 127.0.0.1 or whatever IP address you can refer to your computer.
After the double colon (:) you enter the port number.
So if you want to make an HTTP call to a web-server running on your server, you have to know what is the IP address of your server, or the domain name, and then you call it with the port number where the server is running.
For Instance, you would call https://example.com:3300/chat.html to make an HTTP call to a server running on example.com with port 3300.
Keep in mind, that you have to make sure with your firewall configuration, that the specific port is open for incoming HTTP requests.

PeerJS share one computer local stream to another computer in same network

I am a newbie to WebRTC and PeerJS. My aim is to share Computer A local media stream to Computer B. I have successfully do this with the use of the cloud PeerJS server. However, I want to setup my server in local network.
Computer A is responsible for capturing the local media stream and I have the following code written.
var peer = new Peer('mycustomid1', {host: 'localhost', port: 9000});
Computer B is responsible for displaying the stream received from Computer A.
var peer = new Peer('mycustomid2', {host: 'Computer A's ipv4 address', port: 9000});
And I start my server with the code:
node peerjs --port 9000
Is my code correct? P.S. I can access Computer A localhost in a web browser on Computer B.
Thanks in advance.
I also struggled a bit with setting up a peerserver. Try adding the key peerjs when you start the server. From the github page:
peerjs --port 9000 --key peerjs
I think the key gets defaulted to 'peerjs' when you don't supply it when making a peer. Not to sure about this.
Also, try adding the default path when creating the peers.
var peer = new Peer('mycustomid2', {host: 'Computer A's ipv4 address', port: 9000, path: '/'});
Do this on both peers. Hope it helps

node.js, socket.io and SSL

I have an Apache server running with SSL enabled. Now I made a small chat which is using node.js and socket.io to transmit data. Using port 8080 on a none secured connection is working just fine, but when I try it on a SSL secured domain it is not working. I do not get how the whole setup should work since SSL is only working through port 443. Apache is already listining on port 443. On which port should socket.io listen?
I had to set the SSL certificates like
var fs = require('fs');
var options = {
key: fs.readFileSync('/etc/ssl/ebscerts/wildcard.my_example.com.no_pass.key'),
cert: fs.readFileSync('/etc/ssl/ebscerts/wildcard.my_example.com.crt'),
ca: fs.readFileSync('/etc/ssl/ebscerts/bundle.crt')
};
var app = require('https').createServer(options),
io = require('socket.io').listen(app);
app.listen(8080);
I found the solution on github

NowJS cookie field in this.user is empty

According to these: https://gist.github.com/2266544, Session support in Now.js.
This code should return the NowJS clientId, cookie and session:
nowjs.on('connect', function() { console.log(this.user); })
However, what I got was:
{ clientId: 'something', cookie: { } }
The cookie field is empty. There is no session entry (which I read is an official problem).
Additional Information
I am also using ExpressJS, PassportJS, Mongoose, session-mongoose. I initialized NowJS after configuring Express.
Question
Why is my cookie field empty and how can I get it populated?
After many hours of frustration I discovered that the cookie was not being sent because I was listening to port 3000, which was considered a cross domain request. The port that is being listened to has to be the http server that set the cookie.
I am using Dreamhost, which has Apache listening to port 80 and we're not allowed to unbind it, or bind to port 80. But I was able to resolve this by listening to port 8080.
The cookie was successfully sent when I set it to listen to port 8080.
Edit
This only worked for a short time. Not sure why. Cookies stopped being sent after a while.
Edit 2
This worked again after I set up a proxy forwarding 80 to 8080 (google for "dreamhost proxy"). Essentially putting Apache in front of Node.