This document discusses using NodeJS and HTML5 to build real-time applications that integrate with Asterisk. It describes how Holiday Extras built a customer relationship management system using these technologies to allow customer lookups and call control directly from a web browser. Code examples are provided to connect a NodeJS server to Asterisk via AMI and send commands. This allows actions like making calls between SIP extensions to be triggered by clicking buttons in an HTML page.
1. Asterisk, HTML5 and NodeJS;
a world of endless possibilities
Dan Jenkins
Astricon 2012
@dan_jenkins
@holidayextras
2. The next half an hour....
• Introductions
• Who Holiday Extras are
• HTML5
• What’s NodeJS
• How we’ve used NodeJS within our production environment
• Demonstration
3. Who am I?
el op er Dan Jenkins
D ev
eb neer
r W ngi @dan_jenkins 2 Years
S io
en oIP E
& V
Author of Asterisk-AMI Module
4. It’s in the name, we sell extras for holidays
We’re partners with some big names in the UK
travel industry
Theme Park Breaks
easyJet
Legoland, Alton Towers
to name just a few British Airways
Thomas Cook
Theatre Breaks
5. Since moving to Asterisk,
Over 800,000 calls through
we’ve taken ~516,000 phone
calls in our Contact Centre our Contact Centre last year
We are the market leaders!
We believe Holidays
should be Hassle Free We’ve been using Asterisk
in production since April
Operate in mainland Europe
too, with Holiday Extras DE We’re a 29 year old start up
7. What’s so great about HTML5?
Easier to iterate, there’s millions of
web developers out there No extra plugins required!
Faster time to launch
Over 60% of users with Internet
access have browsers that
Make fully featured apps suppport HTML5
direct in the browser
8. What can you do with HTML5?
Client-side databases
Get User Media
(Microphone & Video) Offline Application cache
Web workers
(Threads)
WebRTC Two way, real-time,
(SIP phone in the browser) communication
9. So, what’s NodeJS?
“Node.js uses an event-driven, non-blocking I/O model that
makes it lightweight and efficient, perfect for data-intensive
real-time applications that run across distributed devices.”
10. What have Holiday Extras done?
Integrated control of the call directly into our in-house CRM
system, this also allows us to look up our customer in realtime
We’ve been through about 3 iterations of the integration
NodeJS and HTML5 have given us the ability to do this
We are able to move fast to react to the current needs of our business
11. How does it all fit together?
NodeJS
Asterisk
Server
Web Sockets
Asterisk-AMI TCP Socket
SIP Chrome Firefox Safari
+ SF + SF + SF
14. Create a basic NodeJS server
Output a ping response from Asterisk in the
command line, from the NodeJS app
15. server.js
var AsteriskAmi = require('asterisk-ami');
var ami = new AsteriskAmi( { host: '172.16.172.130', username: 'astricon', password:
'secret' } );
ami.on('ami_data', function(data){
console.log('AMI DATA', data);
});
ami.connect(function(response){
console.log('connected to the AMI');
setInterval(function(){
ami.send({action: 'Ping'});//run a callback event when we have connected to the socket
}, 2000);
});
process.on('SIGINT', function () {
ami.disconnect();
" process.exit(0);
});
github.com/danjenkins/astricon-2012
16. Time to step it up a notch,
let’s make it output to a webpage
Output that same ping response
to a browser, using NodeJS
17. server.js
var AsteriskAmi = require('asterisk-ami');
var nowjs = require("now");
var fs = require('fs');
var express = require('express');
var http = require('http');
var ami = new AsteriskAmi( { host: '172.16.172.130', username: 'astricon',
password: 'secret' } );
var app = express();
var server = http.createServer(app).listen(8080, function(){
console.log('listening on http://localhost:8080');
});
app.configure(function(){
app.use("/assets", express.static(__dirname + '/assets'));
});
github.com/danjenkins/astricon-2012
19. ami.connect(function(response){
console.log('connected to the AMI');
setInterval(function(){
ami.send({action: 'Ping'});//run a callback event when we have connected to
the socket
}, 2000);
});
process.on('SIGINT', function () {
ami.disconnect();
process.exit(0);
});
github.com/danjenkins/astricon-2012
20. webpage.html
<script type="text/javascript" src="/nowjs/now.js"></script>
<script type="text/javascript">
var output = function(data){
var html = '<div>' + (data instanceof Object ? JSON.stringify(data) : data) + '</div>';
var div = document.getElementById('output');
div.innerHTML = html + div.innerHTML;
}
now.echoAsteriskData = function(data){
output(data);
}
now.ready(function(){
output('connected via nowjs');
});
</script>
github.com/danjenkins/astricon-2012
21. Now, let’s create a call from the webpage
via Bria - Asterisk 11 - SIP Phone
Let’s make the browser do something, make it create
a call between two sip extensions