muaz-khan / RTCMultiConnection

RTCMultiConnection is a WebRTC JavaScript library for peer-to-peer applications (screen sharing, audio/video conferencing, file sharing, media streaming etc.)
https://muazkhan.com:9001/
MIT License
2.56k stars 1.37k forks source link

Problem with socket.io #685

Open nenadfemic opened 5 years ago

nenadfemic commented 5 years ago

Hello Muaz,

I am trying to test demo, but not work on server, only work in localhost.

socket.io.js:1 Failed to load resource: the server responded with a status of 404 () RTCMultiConnection.min.js:15 socket.io url is: https://ananym/ RTCMultiConnection.min.js:15 Uncaught ReferenceError: io is not defined at new SocketConnection (RTCMultiConnection.min.js:15) at connectSocket (RTCMultiConnection.min.js:17) at RTCMultiConnection.connection.open (RTCMultiConnection.min.js:17) at HTMLButtonElement.document.getElementById.onclick (Video-Conferencing.html:82)

In config.json:

{ "socketURL": "https://ananym:9001/", "dirPath": "", "homePage": "/demos/index.html", "socketMessageEvent": "RTCMultiConnection-Message", "socketCustomEvent": "RTCMultiConnection-Custom-Message", "port": "9001", "enableLogs": "true", "autoRebootServerOnFailure": "false", "isUseHTTPs": "true", "sslKey": "./fake-keys/privatekey.pem", "sslCert": "./fake-keys/certificate.pem", "sslCabundle": "", "enableAdmin": "false", "adminUserName": "username", "adminPassword": "password" }

I am run server.js Socket.io is listening at: https://ananym:9001 Your web-browser (HTML file) MUST set this line: connection.socketURL = "https://ananym:9001"; For more help: node server.js --help

How to run demo files on server. I think is problem with Socket.IO but not sure how to set up. On localhost server with url http://localhost:9001 work fine but on server can not run video

ghost commented 5 years ago
wget https://github.com/muaz-khan/RTCMultiConnection/archive/master.zip
unzip master.zip
cd RTCMultiConnection-master
npm install --production

Modify config.json Running node server.js

Оpened port 9001, 80, 443 on the server.

How to check if server is running correctly? Open this URL: https://YouDomain:9001/socket.io/socket.io.js

via https://github.com/muaz-khan/RTCMultiConnection/blob/master/docs/installation-guide.md

muaz-khan commented 5 years ago
git clone https://github.com/muaz-khan/RTCMultiConnection-Server.git ./RTCMultiConnection-Server
cd RTCMultiConnection-Server
mkdir node_modules
npm install
vi config.json

and config.json:

{
  "socketURL": "/",
  "dirPath": "",
  "homePage": "/demos/index.html",
  "socketMessageEvent": "RTCMultiConnection-Message",
  "socketCustomEvent": "RTCMultiConnection-Custom-Message",
  "port": "9001",
  "enableLogs": "false",
  "autoRebootServerOnFailure": "false",
  "isUseHTTPs": "true",
  "sslKey": "./fake-keys/privatekey.pem",
  "sslCert": "./fake-keys/certificate.pem",
  "sslCabundle": "",
  "enableAdmin": "false",
  "adminUserName": "username",
  "adminPassword": "password"
}

Please make sure to pass valid keys for sslKey and sslCert fields.

Now run the server:

node server

Now open this:

https://rtctestserver.doxx.de:9001/socket.io/socket.io.js

Did not load the file?

iptables -I INPUT 1 -i eth0 -p tcp --dport 9001 -j ACCEPT

Run server.js again. Now, are you facing SSL issues? You can install certificate using letsencrypt:

sudo -s
apt-get install software-properties-common
add-apt-repository ppa:certbot/certbot
apt-get update
apt-get install python-certbot-apache
certbot --apache
certbot renew --dry-run

Now config.json looks like this:

{
  "socketURL": "/",
  "dirPath": "",
  "homePage": "/demos/index.html",
  "socketMessageEvent": "RTCMultiConnection-Message",
  "socketCustomEvent": "RTCMultiConnection-Custom-Message",
  "port": "9001",
  "enableLogs": "false",
  "autoRebootServerOnFailure": "false",
  "isUseHTTPs": "true",
  "sslKey": "/etc/letsencrypt/live/rtctestserver.doxx.de/privkey.pem",
  "sslCert": "/etc/letsencrypt/live/rtctestserver.doxx.de/fullchain.pem",
  "sslCabundle": "",
  "enableAdmin": "false",
  "adminUserName": "username",
  "adminPassword": "password"
}

Now run the server:

node server

Now open this:

https://rtctestserver.doxx.de:9001/socket.io/socket.io.js

You can use pm2 to run server in background, only if all above steps are successful.

pm2 startup
pm2 start server.js
pm2 save

Now copy any demo from demos directory:

For example this demo:

Press Ctrl+F and find and replace all occurrences of "/ with "https://rtctestserver.doxx.de:9001/.

Now your main website can upload and run this demo:

https://rtctestserver.doxx.de/Video-Conferencing.html

In simple words, port 9001 is used for socket.io and port 443 is used for main website. You can run PHP or Python or any server on port 443. It is possible to run nodejs on port 443 however personally I prefer PHP.

Here is an example for you:

  1. Socket.io is running on port 9001: https://webrtcweb.com:9002/
  2. However PHP is running on port 443: https://webrtcweb.com/
  3. This demo is using socket.io from heroku: https://webrtcweb.com/fs
nenadfemic commented 5 years ago
git clone https://github.com/muaz-khan/RTCMultiConnection-Server.git ./RTCMultiConnection-Server
cd RTCMultiConnection-Server
mkdir node_modules
npm install
vi config.json

and config.json:

{
  "socketURL": "/",
  "dirPath": "",
  "homePage": "/demos/index.html",
  "socketMessageEvent": "RTCMultiConnection-Message",
  "socketCustomEvent": "RTCMultiConnection-Custom-Message",
  "port": "9001",
  "enableLogs": "false",
  "autoRebootServerOnFailure": "false",
  "isUseHTTPs": "true",
  "sslKey": "./fake-keys/privatekey.pem",
  "sslCert": "./fake-keys/certificate.pem",
  "sslCabundle": "",
  "enableAdmin": "false",
  "adminUserName": "username",
  "adminPassword": "password"
}

Please make sure to pass valid keys for sslKey and sslCert fields.

Now run the server:

node server

Now open this:

https://ananym:9001/socket.io/socket.io.js

Did not load the file?

iptables -I INPUT 1 -i eth0 -p tcp --dport 9001 -j ACCEPT

Run server.js again. Now, are you facing SSL issues? You can install certificate using letsencrypt:

sudo -s
apt-get install software-properties-common
add-apt-repository ppa:certbot/certbot
apt-get update
apt-get install python-certbot-apache
certbot --apache
certbot renew --dry-run

Now config.json looks like this:

{
  "socketURL": "/",
  "dirPath": "",
  "homePage": "/demos/index.html",
  "socketMessageEvent": "RTCMultiConnection-Message",
  "socketCustomEvent": "RTCMultiConnection-Custom-Message",
  "port": "9001",
  "enableLogs": "false",
  "autoRebootServerOnFailure": "false",
  "isUseHTTPs": "true",
  "sslKey": "/etc/ananym/privksdsdsdey.pem",
  "sslCert": "/etc/ananym/fsddssdain.pem",
  "sslCabundle": "",
  "enableAdmin": "false",
  "adminUserName": "username",
  "adminPassword": "password"
}

Now run the server:

node server

Now open this:

https://ananym/socket.io/socket.io.js

You can use pm2 to run server in background, only if all above steps are successful.

pm2 startup
pm2 start server.js
pm2 save

Now copy any demo from demos directory:

* https://github.com/muaz-khan/RTCMultiConnection/tree/master/demos

For example this demo:

* https://github.com/muaz-khan/RTCMultiConnection/blob/master/demos/Video-Conferencing.html

Press Ctrl+F and find and replace all occurrences of "/ with "https://ananym:9001/.

Now your main website can upload and run this demo:

https://ananym/Video-Conferencing.html

In simple words, port 9001 is used for socket.io and port 443 is used for main website. You can run PHP or Python or any server on port 443. It is possible to run nodejs on port 443 however personally I prefer PHP.

Here is an example for you:

1. Socket.io is running on port 9001: `https://webrtcweb.com:9002/`

2. However PHP is running on port 443: `https://webrtcweb.com/`

3. This demo is using socket.io from heroku: `https://webrtcweb.com/fs`

Hello Muaz,

Thanks on very fast response.

We do everthing as you did suggest, but it look can not load Socket.IO

https://ananym:9001/socket.io/socket.io.js

Very strange.

Also we put our configuration: { "socketURL": "/", "dirPath": "", "homePage": "/demos/index.html", "socketMessageEvent": "RTCMultiConnection-Message", "socketCustomEvent": "RTCMultiConnection-Custom-Message", "port": "9001", "enableLogs": "false", "autoRebootServerOnFailure": "false", "isUseHTTPs": "true", "sslKey": "/etananym/prsdfdsfkey.pem", "sslCert": "/etananym/fuhsdfsdfsdfsfain.pem", "sslCabundle": "", "enableAdmin": "false", "adminUserName": "username", "adminPassword": "password" }

Can you suggest any other help so we can figure out what is problem. Also can you suggest us to buy good external cloud server with Ubunte for RTC server.

Thanks Nenad

muaz-khan commented 5 years ago

Possibilities:

In the first comment, you wrote that when you run server.js, you get this:

Socket.io is listening at:
https://rtctestserver.doxx.de:9001
Your web-browser (HTML file) MUST set this line:
connection.socketURL = "https://rtctestserver.doxx.de:9001";
For more help: node server.js --help

Do you still get same output when you run the server.js file?

nenadfemic commented 5 years ago

Possibilities:

* Port 9001 is still not allowed for HTTP+TCP (both for outgoing and incoming)

* Or `server.js` is not running (`nohup node server.js &` or `pm2 start server.js`)

* Or `node` command has conflicts with `nodejs` i.e. legacy nodejs insallation

* Port 9001 is occupied by another process (`fuser -vk 9001/tcp` or `pm2 list`)

In the first comment, you wrote that when you run server.js, you get this:

Socket.io is listening at:
https://ananym:9001
Your web-browser (HTML file) MUST set this line:
connection.socketURL = "https://ananym:9001";
For more help: node server.js --help

Do you still get same output when you run the server.js file?

Hi Muaz

When i run server node server.js I get next msg in command line: Socket.io is listening at: https://localhost:9001/ Your web-browser (HTML file) MUST set this line: connection.socketURL = "https://localhost:9001/"; When run url from browser: https://ananym:9001/socket.io/socket.io.js I am getting next error: This site can’t be reached ananym took too long to respond. Try: Checking the connection Checking the proxy and the firewall Running Windows Network Diagnostics ERR_CONNECTION_TIMED_OUT Also i have additional question(which could make me confusion): How to node server.js run like https://ananym:9001/. Now It's run by default localhost like https://localhost:9001:/

artiberde27 commented 5 years ago

@muaz-khan I am facing the exact same issue. I have cross checked all the possibilities you have mention 1-Port 9001 is still not allowed for HTTP+TCP -I have opened the port on EC2 instances 2-Or server.js is not running- Server.js is running. Because I am able to browse http://MyDomain/dist/RTCMultiConnection.min.js and when i stopped server.js it gave 502 bad gateway error 3-Or node command has conflicts with nodejs i.e. legacy nodejs installation - I have run node -v and nodejs -v both command displayed output as v4.2.6 4-Port 9001 is occupied by another process -Because I am able to browser http://MyDomain/dist/RTCMultiConnection.min.js and when I stopped node server it gave 502 bad gateway error

I have hosted this application on nginx server below is the site file structure and node server is running using systemd

server {
   listen         80 default_server;
   server_name    MyDomain;
   root           /home/ubuntu/Project/Setup/Nodejs/node_modules/rtcmulticonnection;
   location / {
       proxy_pass http://0.0.0.0:9001;
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection 'upgrade';
       proxy_set_header Host $host;
       proxy_cache_bypass $http_upgrade;
   }
}

I have followed below link to the host application on nginx server Could you please help in what I am missing?

muaz-khan commented 5 years ago

I found this, here:

  location ~* \.io {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://localhost:443;
      proxy_redirect off;

      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }
JasonOldWoo commented 5 years ago

1.Why there are rtcmulticonnection and rtcmulticonnection-server, which one should I use? 2.demos has a lot of js/css file dependencies. demo cannot run properly without dependencies.

JasonOldWoo commented 5 years ago

I need very simple http/https demo running on localhost, does anyone help?

SundasAbbasi commented 4 years ago

Sir @muaz-khan Kindly help me I am getting this error while running the code Uncaught ReferenceError: RTCMultiConnection is not defined Kindly help me Kindly correct me if I am wrong I am using jsfadle.net and all of my setup running on my PC I am really new to node..js and can't even understand how to connect server and node.js.I want to do screen sharing(all features like video conferencing, recording, screen sharing). Really thankful to you if you respond to me as soon as possible have a good day sir

HiroakiLion commented 1 year ago

I don't want to revive an old thread but I'm also having the same issue here. When I move RTCMultiConnection.js from node_modules folder to my public or other places and import from it, it works. but then I have to add

import io from 'socket.io-client';

and it works fine as long as I'm joining the room with local stream but

const constraints = {
        audio: false, // Disable audio capture
        video: false, // Disable video capture
      };

with this constraint attached to joinOrOpen, it gives me "callback is not defined" error at 4512 line. it really doesn't make sense. Can somebody help me?

Thanks!