muaz-khan / WebRTC-Experiment

WebRTC, WebRTC and WebRTC. Everything here is all about WebRTC!!
https://www.webrtc-experiment.com/
MIT License
11.65k stars 3.95k forks source link

Deploying WebRTC Experiment on own server #111

Open syedks opened 10 years ago

syedks commented 10 years ago

Guys, has anyone deployed the code on their own servers? I like the examples and they work brilliantly now I would like to implement the code of video conferencing with up to 10 people.

Can anyone please point me to the right direction? If I get an Amazon EC2 instance can this code be setup and used from there? Also, how can I make sure that the server code is secure and can only be called by my web app?

Cheers

roeeyud commented 10 years ago

Also looking into this but can't find how to replace firebird hosting.

dirkk0 commented 10 years ago

You need to set up two components, one of them being the experiment you want to use (for example video-conferencing), the other one is the signal server (here: https://github.com/muaz-khan/WebRTC-Experiment/tree/master/socketio-over-nodejs/webrtc-signaling ).

If you install the experiment as it is, the code uses the ressources kindly provides by muaz-kahn. If you want to use your own servers, you will want to setup your own signalling server and change the references and ports to your liking in the corresponding html/js file. (namely here https://github.com/muaz-khan/WebRTC-Experiment/blob/master/video-conferencing/index.html or for an easier example here: https://github.com/muaz-khan/WebRTC-Experiment/tree/master/video-conferencing on the bottom of the page)

syedks commented 10 years ago

drikk0 thanks for your message. the issue is "how to install it" :) I have now an ec2 running with nodejs and express. how can i install this code?

erichlof commented 10 years ago

I'm a little confused by this as well. @dirkk0, what does "setup your own signalling server" entail? I understand about changing the references on my .js/.html file to point at my website which is devoted to the client-side WebRTC experiment of my choice, but what code does the server need to run?

Am I right in thinking that Muaz-Kahn's library code (let's say DataChannel.js for example) tells the server what to do? Do we just need a blank server somewhere out on the internet with our name on it? Or does it need to be running his 'signaler.js' around the clock as well? Or do we even need any server code at all if we have an Amazon server with our own devoted webpage to these experiments?

Sorry for all the questions. Any help will be greatly appreciated - thanks! -Erich

@muaz-khan

Could you please add a step-by-step list of how to set up a signalling server at the bottom of your WebRTC GitHub homepage README.md file? Maybe using an ec2 server and a random simple experiment of your choice as an example? This would greatly help WebRTC noobs like me! Thanks for your wonderful libraries!

dirkk0 commented 10 years ago

I just wrote a few lines to explain the details but accidentally deleted them - argh!

In general a) git clone the whole project b) go to the video-conferening directory c) put the files in there into a directory called public

No we need a small static web server like this: c) git clone https://gist.github.com/dirkk0/7156731 - it will serve the files in public d) npm install socket.io node-static e) node server.js (there might be typos!)

If you surf to http://someurl.com:8080 you should see a working example - but it works with the signaling server provided by muaz-kahn.

If you want your own server you need to setup your own signaling server which runs 24/7, yes.

I need to run now, but as soon as I get home, I try to explain how to do that in more detail.

erichlof commented 10 years ago

@dirkk0 Thanks so much! I will wait for your signalling server details.

I also created an account at Firebase. This might ease the server-side code burden a little. I posted a signalling server-setup question on their blogs as well, and I will report back to this board any info that I receive from them. :-)

Thanks again, -Erich

syedks commented 10 years ago

Top man dirkk and erich. For me, all i want is own server where i run my own code (signalling and what not).

Dirkk, to make my life easy, and seems like you have done it before, set it up on my server and i pay you a little? Skype me if can spare a few mins.... ambabaji

Otherwise ill try to follow through your instructions. Cheers

syedks commented 10 years ago

Btw, here https://www.webrtc-experiment.com/video-conferencing/ he mentions abt a media server... How to get one setup and going? I will defo need more than one people and quality will be crap.

What is this media server and how to configure it?

dirkk0 commented 10 years ago

@syedks Thanks for the offer - since I suspect more people have this problem, I'll try to describe the solution to the best of my knowledge so that other people can learn from this, too. Then we'll see if you still want me to engage on your server.

dirkk0 commented 10 years ago

We tried video conferencing with four people and the quality was very good. If you have more than 10 people you will have other issues than technical ones :-).

What he meant was - if you have really large numbers of users, you are better off with professional video conferencing software as opposed to a peer-2-peer WebRTC solution.

dirkk0 commented 10 years ago

@erichlof you create a signaling server on an Amazon EC2 Ubuntu instance (with nodejs installed) like that:

mkdir signalserver
cd signalserver

wget https://raw.github.com/muaz-khan/WebRTC-Experiment/master/socketio-over-nodejs/webrtc-signaling/signaler.js

npm install express socket.io
cd ..

To start it you do either

 cd signalserver; node signaler.js

or better

screen -S signalserver -L -dm bash -c "cd signalserver; node signaler.js"

to run it in the background.

You need to open port 8888 in the AWS Security settings (or set the right port in signaler.js, line 9).

erichlof commented 10 years ago

Thanks so much for the detailed server instructions dirkk0! I'm going to file this page in my bookmarks so I can refer back to it when I want to deploy.

Like I mentioned, I have created a Firebase account, and am awaiting their response to my similar question in their forums. Hopefully, having a Firebase or similar service running for you will eliminate some of the set up and maintenance of the signalling back-end. If not, might as well get the Amazon server right?

Thanks again!

dirkk0 commented 10 years ago

You are very welcome.

I also am very fond of Firebase (as you can see here: https://groups.google.com/forum/#!topic/firebase-talk/ygzogFCyVnA) Still, I am wondering, why you prefer one third party service (Firebase) over another third party service (muaz-kahn)?

erichlof commented 10 years ago

@dirkk0 Well let's just say I'm a noob when it comes to node.js, servers, and back-end codes and commands in general. My interest in all this comes from wanting to have a small multiplayer 3d game (using the awesome THREE.js webGL library), which is running all the time 24/7 where a small number of players can come and go as they wish. I asked Muaz Kahn a while ago which library of his I should use for the quickest messaging, and he pointed me towards the DataChannel.js library for my fast game data messaging needs.

I come from a C background, having made 3D games in the past with some snippets of Carmack's Quake source code and my own OpenGL code running on Windows machines (I don't have a preference, just that's what I grew up with) . I've made the transition to the JavaScript language pretty well (being based on C and all), but when it comes to servers in general, I've not even scratched the surface of what I need to have running in the background.

Before this thread opened, I was naive in thinking that all we had to do was include the DataChannel.js in a script tag and we are good to go. I wasn't even aware that Muaz was graciously hosting the back-end server for our projects. The only reason I'm looking into Firebase was because Muaz Kahn says we should use it until we are comfortable: https://www.webrtc-experiment.com/docs/webrtc-for-newbies.html Scroll down to right below "I'm confused about Node.js"

I was just blindly following what he said. If indeed the Firebase service eliminates any server-side code that I would have to type, I might just want to go with that for easiness sake, and to get a little game up and running as soon as possible.

If there's an easier way, I'll take it! :-) -Erich

dirkk0 commented 10 years ago

Regarding 3D plus multiplayer - you only need socket.io for that, a peer2peer solution would not be approriate IMHO.

I did exactly that some time ago: http://www.youtube.com/watch?v=6_wbAsfJWJw http://www.youtube.com/watch?v=-TiZzovx5YE

Problem is - the code of this example is a mess, and I desperately need to refactor it (which I promised several people already).

I try to hurry up and put some code online as soon as I can.

If you want to look at a simple socket.io example take this very simple chat: https://github.com/dirkk0/simplechat you can install it with npm installand start it with npm start.

erichlof commented 10 years ago

Hi Dirk,

Wow I've seen those YouTube videos before and I didn't realize that was you! Your three.js/cannon.js examples are very impressive! This is along the lines of what I would like to eventually do. Thanks for the links to the simple chat code. I can learn a lot from this kind of Hello World-type example.

I have been hesitant to jump into sockets over node.js simply because it's a little foreign to me. But with your example maybe I can finally dive in.

Unless I am not understanding correctly, I thought that DataChannel.js would be faster than socket.io because webRTC tries to make a direct data link between peers, whereas sockets are still going through the server first. Assuming the end users have the latest version of chrome, shouldn't Muaz Kahn's webRTC library offer faster data transfer than older sockets? Maybe I don't have a grasp yet of network concepts.

Anyway thanks for the video and code links. I eagerly await your source code to those YouTube examples! I am going to Star some of your GitHub repositories! :-)

dirkk0 commented 10 years ago

Hi,

thank you! :-)

For a multiplayer game you rather want to have a client-server architecture since in a simple scenario all players need all positions (and velocity etc). Also you need one instance that synchronizes physics and prevents cheating. This seems to call for a centralized architecture.

Then again there might be other use cases - I don't recall anybody trying this in a p2p fashion before.

Cheers, Dirk

erichlof commented 10 years ago

Hi Dirk, You're absolutely right. As you can see, I've not completely thought this through. :)

I might limit the number of players to 2 for now, just to see how fast Muaz-Khan's DataChannel.js could handle the game messages. If I want to do anything with more than 2 players in the future, like you said, I need to have server-client architecture, which would mean implementing Socket.io over Node.js. Unless there's a way to create a server and multiple peers all sharing Data over DataChannel?

I have been looking more closely into Node.js (thanks for all the info Dirk) and there are now quite a bit of resources out there for networking noobs like me (such as Node express).

I also found this along my internet travels. It looks pretty useful for anyone concerned about setting up a 'signaling' server to be able to run all of Muaz Khan's examples on their own server:

https://github.com/andyet/signalmaster

I think it's pretty relevant to the original poster's discussion/issue. Let me know what you guys think.

Hopefully when Muaz Khan returns, he can shed some light on what his DataChannel.js can and can't do regarding multiple data connections and possible game server-client architecture.

Take care, Erich

muaz-khan commented 9 years ago

Oh, nice discussion! I forgot to comment here :) BTW, just for your information, I've following built-in signaling implementations that can be installed on any server and all of these will work as you're requesting in this page:

  1. https://github.com/muaz-khan/XHR-Signaling
  2. https://github.com/muaz-khan/WebSync-Signaling
  3. https://github.com/muaz-khan/WebRTC-Experiment/tree/master/socketio-over-nodejs
  4. https://github.com/muaz-khan/WebRTC-Experiment/tree/master/websocket-over-nodejs

And following page explains A-to-Z everything about how to use custom signaling servers; e.g. signalmaster that you also mentioned in this page. You can use each and every custom/private/public/etc. signaling server with approximately all WebRTC Experiments and libraries.

https://github.com/muaz-khan/WebRTC-Experiment/blob/master/Signaling.md

You simply need to modify only one method named as "openSocekt"; it looks like this:

var config = {
       openSocket: function(config) {}
};

This method is defined in HTML page, here:

https://github.com/muaz-khan/WebRTC-Experiment/blob/master/video-conferencing/index.html#L125

If you want to use above socketio-over-nodejs link, see openSocket method here:

https://github.com/muaz-khan/WebRTC-Experiment/tree/master/video-conferencing#want-to-use-video-conferencing-in-your-own-webpage

NPM packages for all signaling servers are available here:

https://www.npmjs.org/~muaz-khan

If you want a little bit more examples, consider "openSignalingChannel" and "openSocket" same things with different names:

http://www.rtcmulticonnection.org/docs/openSignalingChannel/

Questions:

1) Can I install signaling servers on my own server (Amazon/etc.)

Sure.

2) Which server?

Anyone available on the web. E.g.

i. https://github.com/andyet/signalmaster ii. https://github.com/peers/peerjs-server iii. https://github.com/SignalR/SignalR iv. http://millermedeiros.github.io/js-signals/ v. https://github.com/sockjs/sockjs-client

3) How to modify code to use my own servers?

Simply modify single method named as "openSocket".

4) Where to modify?

In your UI.js file or in HTML/PHP/ASPX file.

5) What if I'll be using my own server?

Signaling will be used from your server and it can be kept private using something like this:

https://github.com/jfromaniello/passport.socketio

6) What about STUN/TURN servers?

You can install your own TURN-server and you can simply modify/replace Google/Bistri 's STUN/TURN with your own TURN URI. A simple guide is available here:

https://www.webrtc-experiment.com/docs/TURN-server-installation-guide.html

7) Important question, number of interconnected users supported?

WebRTCPedia explains that maximum number of peer connections limit on chrome is 256. Which means that 256 is expected maximum interconnected users' limit.

DataChannel.js provides many-many and many times faster and reliable connection comparing socket.io or other websocket based protocols. SCTP datachannels has lowest possible latency (about 8-10ms) and you can share 64k data per chunk from chrome-to-chrome and 16k per chunk from chrome-to-Firefox.

Even doing some C-hacks, you can reduce a little bit more latency by disabling retransmission and other stuff.

SCTP protocol is expected to be using 50kbits/s bandwidth for each channel; which means that you can easily support 20-interconnected users if you've 1MB modem; and 40-users for 2MB and so on.

Regarding CPU usage, you can check this tutorial:

https://www.webrtc-experiment.com/docs/RTP-usage.html

Remember: Above link is targeting media (RTP) ports; not data (SCTP) one.