Creating a WebRTC WOW Moment With Raspberri Pi and Node.JS

Want to WOW your friends? Show a video calling service running off your Raspberry Pi.

I’ve been running some trainings for product managers and developers here in Israel for the past several months. All of them are focused on WebRTC and how it transforms the market.

When I first did my developer training, asking for feedback at the end of the workshop, one thing that was raised is that going over sample code and understanding it isn’t enough. What is missing is to show the simplicity. To show how easy it is to get up and running from scratch.

Call it the 0 to 100 kph of doing a hello world video calling.

With WebRTC it can be achieved just before lunch break and in record time.

What I decided doing is purchase a Raspberry Pi Starter Kit. For those who don’t know, a Raspberry Pi is a small machine (credit card size) that can run Linux. It has an ARM chip, HDMI output, 2 USB inputs, SD card input and Ethernet cable input. You can buy one to create your own home video streamer… or you can use it to teach WebRTC.

The idea was simple:

Get a vinyl distribution of a Linux operating system for Raspberry Pi

Install it on the SD card (which is used to boot a Raspberry Pi)

In the training itself, get and install Node, get and install a sample, run the sample

For the curtsy of those who came to the training, and those who just want to understand how simple this is, here are the step-by-step instructions I came up with for myself. I decided to do this on a Windows machine (just because it is what I have during the trainings to show the presentation).

1. Things to download and install

My assumption is that your machine has an SD card reader/writer. Most laptops these days do (mine has one). You will have to have a few tools on your Windows machine to get things going:

2. Get a Raspberry Pi operating system

There are several options for operating systems on a Raspberry Pi. I ended up selecting the “default” one. Go to http://www.raspberrypi.org/downloads/ and select the one you want. I chose to go with Raspbian (Debian ported to Raspberry Pi). Also called on that size Debian Wheezy. The version I used was January 2014 with the release date 2014-01-07.

3. Prepare the SD card

This step is long, so I do it prior to the training, and I do it before each and every training – just to show that I am starting from a vinyl system. Format the SD card To prepare the card, we need to format it and install the image on it: Run SDFormatter, and select Quick Format with no size adjustments.

Once done, it is time to write the image into it. Write the OS image Unzip the Raspbian image file you downloaded. Mine was called 2014-01-07-wheezy-raspbian.img with a size of ~2.8Mb. Run Win32 Disk Imager, select the image file and write it to the SD card. This is going to take a few minutes.

4. Find your Raspberry Pi on the network

Plug the SD card into your Raspberry Pi, connect it to the power and the network with the Ethernet cable. Since I don’t usually have extra display and keyboard in these sessions, my only option to login to the Raspberry Pi is over the network. For that, I am using Zenmap in order to find out the IP address the Raspberry Pi got. Run Zenmap. Write in the target your subnet. For me, that’s 10.0.0.* Switch the profile to Quick scan Count to 10. Look at the results and search for a (Raspberry Pi Foundation) MAC address. That’s going to have the IP address of your Raspberry Pi. Here’s how it looks for me:

Now use your SSH client to login to this IP address. The default username is pi and the default password to go along with it is raspberry.

5. Install Node.js on Raspberry Pi

Logged in? Good. Node.js doesn’t come preinstalled on a Raspberry Pi, so we need it there. Googling a bit, got me to this set of instructions. What I need is:

Node.js

Websocket support for Node.js

Run the following from the command line of your Raspberry Pi:

Shell

1

2

3

wget http://node-arm.herokuapp.com/node_latest_armhf.deb

sudo dpkg-inode_latest_armhf.deb

npm install websocket

The last one installs Websocket support.

6. Get your preferred WebRTC sample

For me, that would be Rob Manson’s Getting Started With WebRTC. This code is explained in detail in his book under the same name which I reviewed here already. Since this is on Github, we follow these instructions:

Shell

1

2

git clonegit://github.com/buildar/getting_started_with_webrtc

cdgetting_started_with_webrtc

7. Prepare the sample

Rob’s sample requires one additional step. The Node.js code sends a .html file to the browser, and in it, there’s an indication where the Websocket signaling need to go to. In the HTML file, that’s set to “localhost”. I had to change that value to the IP address of my Raspberry Pi. For that, just use:

Shell

1

nano video_call_with_chat_and_file_sharing.html

Change in line 149 from “ws://localhost:1234″ to “ws//<ip-address>:1234″

8. Showoff

Start the server by calling:

Shell

1

node webrtc_signal_server.js

Connect 2 browsers to the IP address of your Raspberry Pi at port 1234, or 2 tabs from the same browser. For this sample, you will need to connect the first browser, and then copy the URL provided on the screen to the second browser to join the session.

Why does this matter?

Before WebRTC, getting such a thing to work from source to running a demo took a day or a week.

Now it is down to 5 minutes.

If you wanted disruption, then here you have it: WebRTC is all about reducing the barrier of entry for developers.

Liked this post?

Comments

I have been running proto-WebRTC app on Raspi-like device (http://blog.enthinnai.com/2011/04/28/enthinnai-running-on-a-home-server/). This app has IM and voice capability by dynamically downloading a Java applet. It does even ICE with a TRN server built in. Once Raspi was released, the app was moved to it with no further modification. Of course recently we replaced the Java applet and are using WebRTC. A Raspi is running at my home and using it for my personal use.

Hi ,
Many thanks for your nice post.I had a video chat within my home network successfully. But how can i have video chat over internet also in the same manner ?
It would be cool to have video chat with friends over internet.

For that you will first need to place your Raspberry Pi itself on the public internet, or just run the same code on AWS or any other cloud service out there.
You might also need to use a TURN server, depending on the network topology between you and your friend’d equipment.

Quick question…I want to be able to connect to this from the Internet. I have port forwarding on my router already set up and working. Where I specify the IP address for ws//:1234, do I specify the Raspberry Pi’s local private IP? Or do I put my Internet public IP?