Preparing the environment
Let's start with the setup:
Create a folder for the whole application somewhere on your disk. Let's call it
my_rtc_project
.Create a directory named
my_rtc_project/www
. Here, we will put all the client-side code (JavaScript files or HTML pages).The signaling server's code will be placed under its separate folder, so create a directory for it and name it
my_rtc_project /apps/rtcserver/src
.Please note that we will use Git, a free and open source-distributed version control system. For Linux boxes, it can be installed using the default package manager. For a Windows system, I recommend that you install and use the implementation available at https://github.com/msysgit/msysgit.
If you're using a Windows box, install msysgit and add a path to its
bin
folder to yourPATH
environment variable.
Installing Erlang
The signaling server is developed in the Erlang language. Erlang is a great choice to develop server-side applications due to the following reasons:
It is very comfortable and easy for prototyping
Its processes (aktors) are very lightweight and cheap
It does support network operations with no need of any external libraries
The code has been compiled to a bytecode that runs on a very powerful Erlang Virtual Machine
The following are some great projects developed using Erlang:
Yaws and Cowboy: These are web servers
Riak and CouchDB: These are distributed databases
Cloudant: This is a database service based on the forking of CouchDB
Ejabberd: This is an XMPP instant messaging service
Zotonic: This is a content management system
RabbitMQ: This is a message bus
Wings 3D: This is a 3D modeler
GitHub: This is a web-based hosting service for software development projects that use the Git versioning system
WhatsApp: This is a famous mobile messenger, sold to Facebook
Call of Duty: This is a computer game that uses Erlang on the server side
Goldman Sachs: This is a company that uses high-frequency trading computer programs
The following is a very brief history of Erlang:
1982–1985: Ericsson starts experimenting with the programming of telecom, because existing languages weren't suitable for the task.
1985–1986: Ericsson decides it must develop its own language with the desirable features of Lisp, Prolog, and Parlog. The language should have built-in concurrency and error recovery.
1987: First experiments with a new language, Erlang.
1988: Erlang is first used by external users out of the lab.
1989: Ericsson works on the fast implementation of Erlang.
1990: Erlang is presented at ISS'90 and gets new users.
1991: A fast implementation of Erlang is released to users. Erlang is presented at Telecom'91 and gets a compiler and graphic interface.
1992: Erlang gets a lot of new users. Ericsson ports Erlang to new platforms including VxWorks and Macintosh.
1993: Erlang gets distribution. This makes it possible to run homogeneous Erlang systems on heterogeneous hardware. Ericsson starts selling Erlang implementations and Erlang Tools. A separate organization in Ericsson provides support.
Erlang is supported by many platforms. You can download it from the main website, http://www.erlang.org, and install it.
Installing Rebar
Actually, you can write Erlang programs and compile them without using any additional tools. Nevertheless, it is pretty easy to compile Erlang programs using the Rebar tool.
It works like a Make or auto tools for C or C++ applications and makes a developer's life easier.
You can download the Rebar tool from GitHub at https://github.com/basho/rebar.
The installation process is pretty simple:
git clone git://github.com/rebar/rebar.git $ cd rebar $ ./bootstrap ... ==> rebar (compile) Congratulations!...
Now you have the Rebar executable in the folder where you downloaded the Rebar tool. Put it under a folder that is accessible with the PATH
environment variable.
Configuring a web server
Configure the web server for your application's domain and point it to the my_rtc_project/www
folder.
The basic application that we're considering in this chapter works fine without a web server; you can just open the index page in your web browser locally. Nevertheless, in the following chapters, we will touch on more advanced topics that will need to be configured on the web server in order to gain a better understanding of them.