Setting up a signaling server
In order to provide the web and WebSocket server functionality, we will create a basic Node.js application. You could implement this functionality using any server and programming language of your choice. And you could separate the web component and the WebSocket component into different code bases too. However, for this example, we have integrated them into a single simple JavaScript application to keep it similar to the previous browser side code examples.
This server application really is very simple, is less than 100 lines long, and contains five basic steps:
First, we load in some useful libraries that make it easier to implement this application. The most important one is the
websocket
library. If you don't already have that installed in your Node.js implementation, then you should be able to easily install that usingnpm
, the node package manager. From the command line, this can be as easy as typingnpm install websocket
.We then define a set of general...