Asterisk, HTML5 and NodeJS; a world of endless possibilities

17,849 views

Published on

Published in: Technology
0 Comments
21 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
17,849
On SlideShare
0
From Embeds
0
Number of Embeds
3,364
Actions
Shares
0
Downloads
0
Comments
0
Likes
21
Embeds 0
No embeds

No notes for slide

Asterisk, HTML5 and NodeJS; a world of endless possibilities

  1. 1. Asterisk, HTML5 and NodeJS;a world of endless possibilities Dan Jenkins Astricon 2012 @dan_jenkins @holidayextras
  2. 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. 3. Who am I? el op er Dan Jenkins D ev eb neer r W ngi @dan_jenkins 2 YearsS io en oIP E & V Author of Asterisk-AMI Module
  4. 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. 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 Holidaysshould 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
  6. 6. Get on with it!
  7. 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. 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. 9. So, what’s NodeJS?“Node.js uses an event-driven, non-blocking I/O model thatmakes it lightweight and efficient, perfect for data-intensivereal-time applications that run across distributed devices.”
  10. 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 realtimeWe’ve been through about 3 iterations of the integrationNodeJS and HTML5 have given us the ability to do thisWe are able to move fast to react to the current needs of our business
  11. 11. How does it all fit together? NodeJS Asterisk ServerWeb SocketsAsterisk-AMI TCP SocketSIP Chrome Firefox Safari + SF + SF + SF
  12. 12. Now for the demo @dan_jenkins @holidayextras
  13. 13. Firstly, install the module npm install asterisk-amiPrerequisite: install NodeJS first!
  14. 14. Create a basic NodeJS server Output a ping response from Asterisk in the command line, from the NodeJS app
  15. 15. server.jsvar 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. 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. 17. server.jsvar 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
  18. 18. app.use(express.errorHandler());app.get(/, function(req, res) {  var stream = fs.createReadStream(__dirname + /webpage.html);  stream.on(error, function (err) {      res.statusCode = 500;      res.end(String(err));  });  stream.pipe(res);})var everyone = nowjs.initialize(server);ami.on(ami_data, function(data){  if(everyone.now.echoAsteriskData instanceof Function){    everyone.now.echoAsteriskData(data);  }}); github.com/danjenkins/astricon-2012
  19. 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 tothe socket  }, 2000);});process.on(SIGINT, function () {  ami.disconnect();  process.exit(0);}); github.com/danjenkins/astricon-2012
  20. 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. 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
  22. 22. server.js+everyone.now.send_data_to_asterisk = function(data){+  console.log(got data from browser, data);+  ami.send(data);+} github.com/danjenkins/astricon-2012
  23. 23. webpage.html$(.btn).click(function(e){ var obj = {};  if($(this).is(.help)){   obj = {action: ListCommands};  }else if($(this).is(.reload)){    obj = {action: reload};  }else if($(this).is(.login)){    obj = {action: QueueAdd, queue: 10, interface: sip/2000, penalty: 1, paused:true};  }else if($(this).is(.unpause)){    obj = {action: QueuePause, queue: 10, interface: sip/2000, paused: false};  }else if($(this).is(.dial)){    obj = { action: originate, channel: SIP/1000, exten: 10, context: from-internal,priority : 1, async: true, callerid: 1000 VIA AMI "1000" };  }else if($(this).is(.logout)){   obj = {action: QueueRemove, queue: 10, interface: sip/2000};  }  now.send_data_to_asterisk(obj); e.preventDefault();}) github.com/danjenkins/astricon-2012
  24. 24. Questions?
  25. 25. Thank You!Dan Jenkins @dan_jenkins Astricon 2012 dan.jenkins@holidayextras.com hungrygeek.holidayextras.co.uk npm.im/asterisk-ami github.com/holidayextras/node-asterisk-ami

×