Developers

Introduction

EasyRTC is a great WebRTC API built by our friends at Priologic. It is both powerful and secure, and the best part is that it’s open source, constantly being updated by a team of amazing people. And it’s said you can spin up a production grade WebRTC application in a matter of hours, not weeks.

Because WebRTC is such a new technology, solid WebRTC APIs are still few and far between these days. But EasyRTC is also among the best we’ve seen, so much so that we’ve decided to persuade our clients to use it and focus on our strength: highly reliable TURN servers.

This tutorial will teach you the basics of hooking EasyRTC into XirSys’s STUN and TURN servers.

Don’t like EasyRTC? You can hook any WebRTC API into our platform.

Prerequisites

If you haven’t already, we highly suggest that you first read our Introduction, followed by our Quick start guide. These guides should give you a fundamental understanding of our platform, making hooking EasyRTC into the XirSys platform a piece of cake.

The demo

EasyRTC’s bare-bones demo can be found here. And you can also fork it from Priologic’s GitHub. We’ll be using this demo for this tutorial, specifically the Simple Audio and Video Chat demo. By default, it is configured to connect to Google’s STUN server at stun.l.google.com:19302, which is intended for public use. It does not connect to any TURN servers out of the box. That’s where we come in.

Creating a listener for the getIceConfig event

Priologic has made it very easy to specify your own STUN and TURN servers. To hook EasyRTC into the XirSys platform, all you have to do is create a listener for the getIceConfig event. This is EasyRTC’s way of having a custom ICE configuration delivered on a per connection basis. iceConfig is the array we use to store XirSys STUN and TURN servers — instead of the default Google STUN server — and have sent back via a callback.

But you can’t just hook into any ICE server. You must first make a POST request to https://service.xirsys.com/ice¬†with your XirSys credentials, and only then can you pass the returned STUN and TURN servers into iceConfig.

Let’s edit server.js to create the event listener getIceConfig, where we’ll also initiate the POST request:

 

Please keep in mind that this POST request should only be implemented in a secure environment, such as a server-side application or a compiled client-side application. Failure to do this will result in unwanted users hijacking your TURN bandwidth and other security flaws. Since this POST request is in server.js, we seem to be following this rule.

Please notice the fact that we’re setting iceConfig to body.d.iceServers, which is where the array of XirSys ICE servers lives.

A successful call should yield similar results to the array of servers returned below:

Confirmation

Let’s try it out. We used the Simple Audio and Video Chat demo. If your XirSys call was truly successful, the new getIceConfig event listener should have replaced the default Google STUN server with XirSys STUN and TURN servers. You can confirm this within your XirSys dashboard by checking how many STUN connections you had before and after testing the updated demo. The dashboard updates instantly, so if your STUN connections increased, congratulations. Achievement unlocked! You’ve successfully hooked EasyRTC into the XirSys platform.

Tying up loose ends

Although this demo now hooks into XirSys’s STUN and TURN servers, it still uses Priologic’s public signaling server. In a later tutorial, we’ll cover how to instead hook into XirSys’s signaling server.

We hope you’ve left with a solid understanding of what it takes to bring these two wonderful platforms together. You can also fork this customized EasyRTC demo from our GitHub, although it may not be as up to date as the official EasyRTC repository. This tutorial covered all the fundamentals you need to develop and deploy an awesome EasyRTC application that hooks into our highly reliable servers.

 


Developers