# WebsocketSignaling
To run the server first you need node.js & npm: https://nodejs.org/
Make sure to use the recommended node.js version! Versions with a leading 0 e.g. 0.10.x and other older versions might not work! This application was developed using npm 6.9.0 and node version v8.11.3.
After installing run the following commands:
#get the files
git clone https://github.com/because-why-not/awrtc_signaling
#install dependencies
cd awrtc_signaling
npm install
#compile typescript to java script
npm run build
#run the server
npm start
The app should print the following lines (or similar) once ready to receive connections:
websockets/http listening on { address: '0.0.0.0', family: 'IPv4', port: 80 }
secure websockets/https listening on { address: '0.0.0.0', family: 'IPv4', port: 443 }
Shut down using ctrl + c. If the first run was successful then now is a good time to customize it:
If this was too quick: You can also find more details tutorials here: https://www.because-why-not.com/webrtc/tutorials-server-side/
You can now test if your server is running properly via an URL:
http://yourip:yourport/
secure connection (this will show a security warning if you use the default ssl.crt / ssl.key):
https://yourip:yourport/
Both pages just show a html file in the "public" folder showing the text "running". If the page fails to load the server might not have started properly or a firewall of your server / provider blocks the port.
Testing with the Unity assets CallApp example:
Testing with awrtc_browser:
Other testing advice:
If you still have open quests or any problems visit https://github.com/because-why-not/awrtc_signaling/issues
example lines in config.json:
"httpConfig": //settings for ws protocol. Remove this to deactivate ws
{
"port": 12776, //port used for incoming connections
"host": "0.0.0.0" //ip to listen at. 0.0.0.0 for all
},
"httpsConfig": //settings for wss protocol
{
"port": 12777,
"host": "0.0.0.0",
"ssl_key_file": "ssl.key", //your private key
"ssl_cert_file": "ssl.crt" //your ssl certificate + the certificate of the certification authority
}
You can change used ports and other details in the file config.json. By default the app will use two ports 12776 for websockets (ws/http) and 12777 for secure websockets(wss/https). Many cloud services / hosting provider only support one port for a single app which is being set via the PORT environment variable (process.env.port in node.js). In this case you can only run ws/http or wss/https in a single app and you should remove either httpConfig or httpsConfig from the config.json.
Some providers have other restrictions and you might have to change the server.js. Please check with your hosting provider if you have problems.
It is recommended to use port 80 for ws and 443 for wss if possible! Other ports are more likely to be blocked by firewalls outside of your control e.g. firewalls on the endusers network.
Using HTTPS / WSS for secure connections: The files ssl.cert and ssl.key contain an example ssl certificate to allow testing secure connections via native applications. Browsers / WebGL apps will not accept this certificate and trigger a security error. You need to replace the files with your own certificate which needs to be created for your specific domain name.
Also make sure your own ssl.cert will contain two "BEGIN CERTIFICATE" sections. One for your certificate and one for the certification authority! You can find more about this in the server guide & FAQ: https://www.because-why-not.com/webrtc/tutorials-server-side/ https://because-why-not.com/webrtc/faq/
Other settings:
If you want to restrict access to the signaling server you can set the property adminToken in the config.json to a token of your choice (any string). This will block all websocket connections by default unless they have a valid token.
To allow a specific connection you must first register a userToken via a REST API call e.g. with command line tool curl you can register a new user taken "new_user_token" like this:
curl -X POST -H "Authorization: my_secret_admin_token" -d '{"timeout": 30, "userToken": "new_user_token"}' http://localhost:12776/api/admin/regUserToken
To use the token the following signaling URL must be used: ws://localhost:12776?userToken=new_user_token After 30 seconds any existing websocket connection remains open but no new connections are accepted.
Make sure to always use https and wss for production.