Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/sipgate/sipgate.io
Browse files Browse the repository at this point in the history
  • Loading branch information
TheCK committed May 12, 2015
2 parents 6a9b159 + b4ff2e2 commit f5886c9
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions examples/nodejs/express/on-hangup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
var app = require('express')();
var bodyParser = require('body-parser');
var xml = require('xml');

var calls = {};

app.use(bodyParser.urlencoded({ extended: false }));

app.post("/", function (request, response) {
var from = request.body.from;
var to = request.body.to;
var direction = request.body.direction;
var callId = request.body.callId;

calls[callId] = { "from": from, "to": to };

console.log("call from: " + from + " to: " + to + " direction: " + direction);

response.set('Content-Type', 'application/xml');
response.send(
xml({ Response: [
{_attr: { onHangup: 'http://' + request.headers.host + '/hangup' }}
] })
);
});

app.post("/hangup", function (request, response) {
var callId = request.body.callId;

var from = calls[callId]["from"]
var to = calls[callId]["to"]

console.log("hang up call from: " + from + " to: " + to);

response.send();
});

app.listen(3000);

0 comments on commit f5886c9

Please sign in to comment.