The EasyRTC Framework Consists of A Client or Browser2
The EasyRTC Framework Consists of A Client or Browser2
on top of a node.js. Because the WebRTC libraries is built into each browser there is no need for a browser plug-in.
Google's Chrome browser has the broadest support for the WebRTC API. Opera is now using the same engine as
Chrome and hence mimics it's behavior. Firefox provides excellent support for data communications but only basic
support for video chats (it lacks the ability to set the camera resolution, programmatically allow screen sharing, or
do statistics gathering).
WebRTC has the potential once it is fully standardized to support audio and video chats and conferencing,
multiplayer games and many other audio, video and data-based applications.
As is often the case with software, with power comes complexity. WebRTC has a learning curve that is
likely to hamper its use by web developers. To hide that complexity, Priologic has built the EasyRTC
framework.
Get access to the local camera and microphone in the form of a "media stream".
Establish a connection to a signaling server.
Initiate a call to a person on another browser.
Connect media streams to video tags.
Using the EasyRTC framework, several of these steps can be collapsed into a single call, vastly
simplifying the developers job, particularly if the web developer is trying to support multiple platforms.
This document is a tutorial for writing applications with the EasyRTC framework. It does not cover the
entire EasyRTC API.
Terminology
Callback - A JavaScript function supplied to a library so that the library will call it when a
particular event occurs.
Media Stream - An object encapsulating a video track and/or one or more audio tracks.
Peer Connection - A connection between two different browsers that enables peer to peer
communication.
Server - The Node.js server plus some JavaScript code we supply provides the server side of the
EasyRTC framework.
1
Include the below four lines in the <head> section of your HTML file. The first two scripts are needed
by EasyRTC, while the third will be your own application logic. The CSS file provides some styling for an
error messages dialog.
<head>
...
<link rel="stylesheet" type="text/css" href="/easyrtc/easyrtc.css" />
<script src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="/easyrtc/easyrtc.js"></script>
<script type="text/javascript" src="mylogic.js"></script>
...
</head>
Put two video tags (one to display video from the local camera, one to display video from somebody else's
camera) with id attributes in the <body> section of your html file, like the below. The second video tag
should be in a <div> block with a CSS position value of "relative" to help position it's hangup button.
There is no hangup button for the self video.
<body>
...
<video style="float:left" id="self" width="300" height="200"
muted="muted"></video>
<div style="position:relative;float:left;width:300px">
<video id="caller" width="300" height="200"></video>
</div>
...
</body>
Now we have to start writing some application logic for the application.js file, starting with an
initialization function that will be called when the page gets loaded. The primary responsibility of the
initialization function is to call the EasyRTC.easyApp method. It takes the following arguments:
The initialization function is also a good place to register a callback to find out who else is hooked up to
the server. The callback is registered using EasyRTC.setRoomOccupantListener.
function my_init() {
easyrtc.setRoomOccupantListener( loggedInListener);
easyrtc.easyApp("Company_Chat_Line", "self", ["caller"],
function(myId) {
console.log("My easyrtcid is " + myId);
}
);
2
}
The callback will be called whenever somebody else connects to or disconnects from the
"CompanyChatLine", and immediately after the call to easyrtc.easyApp.
a room name
a map whose keys are the ids (easyrtcids) of the other people connected to the server using the
same application name.
In our example, the callback will maintain a list of buttons to call the other people connected to the
"CompanyChatLine". We'll add a <div> to the <body> to hold these buttons.
<body>
...
<div id="otherClients"> </div>
...
</body>
label = document.createTextNode(i);
button.appendChild(label);
otherClientDiv.appendChild(button);
}
}
Most applications can ignore the roomName parameter; it is only of interest if your application can access
several rooms simultaneously.
Of course, in a real application, we wouldn't be using the easyrtcids for button labels. Instead, we would
have some application logic to map the easyrtcids to more permanent identifiers like name, job title, and
profile picture.
To actually initiate a call to a person, all we need to do is call the easyrtc.call method, passing it the
easyrtcid of the person, and three callbacks:
3
function accepted(wasAccepted,easyrtcid) - called to indicate whether the call was accepted or not.
function performCall(easyrtcid) {
easyrtc.call(
easyrtcid,
function(easyrtcid) { console.log("completed call to " + easyrtcid);},
function(errorMessage) { console.log("err:" + errorMessage);},
function(accepted, bywho) {
console.log((accepted?"accepted":"rejected")+ " by " + bywho);
}
);
}
Now we just have to modify the body tag of our html file to actually call the my_init function.
<body onload="my_init()">
label = document.createTextNode(i);
button.appendChild(label);
otherClientDiv.appendChild(button);
}
}
function performCall(easyrtcid) {
easyrtc.call(
easyrtcid,
function(easyrtcid) { console.log("completed call to " + easyrtcid);},
function(errorMessage) { console.log("err:" + errorMessage);},
function(accepted, bywho) {
console.log((accepted?"accepted":"rejected")+ " by " + bywho);
}
);
}