From deec0bd497bc004cea70dc132863f7e478f682f1 Mon Sep 17 00:00:00 2001 From: Marcus Hunger Date: Tue, 12 May 2015 13:58:41 +0200 Subject: [PATCH] new nodejs-example express/on-hangup --- examples/nodejs/express/on-hangup.js | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 examples/nodejs/express/on-hangup.js diff --git a/examples/nodejs/express/on-hangup.js b/examples/nodejs/express/on-hangup.js new file mode 100644 index 0000000..c14d23e --- /dev/null +++ b/examples/nodejs/express/on-hangup.js @@ -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);