Skip to content

Instantly share code, notes, and snippets.

@erhangundogan
Created July 10, 2014 11:46
Show Gist options
  • Select an option

  • Save erhangundogan/018e1065b79797c2521d to your computer and use it in GitHub Desktop.

Select an option

Save erhangundogan/018e1065b79797c2521d to your computer and use it in GitHub Desktop.
webrtc
// Load required modules
var http = require("http"); // http server core module
var express = require("express"); // web framework external module
var io = require("socket.io"); // web socket external module
var easyrtc = require("easyrtc"); // EasyRTC external module
// Setup and configure Express http server. Expect a subfolder called "static" to be the web root.
var httpApp = express();
httpApp.use(express.static(__dirname + "/static/"));
// Start Express http server on port 8080
var webServer = http.createServer(httpApp).listen(8088);
// Start Socket.io so it attaches itself to Express server
var socketServer = io.listen(webServer, {"log level":1});
// Start EasyRTC server
var rtc = easyrtc.listen(httpApp, socketServer);
var onEasyrtcMsg = function (connectionObj, msg, socketCallback, next) {
switch (msg.msgType) {
case "MakeCall":
MakeCallSPRequest(msg.msgData.callHandle, msg.msgData.callerID, msg.msgData.calledID);
socketCallback({ msgType: 'Make call ACK:', msgData: "Handle:" + msg.msgData.callHandle + "caller:" + msg.msgData.callerID + " called:" + msg.msgData.calledID });
next(null);
break;
default:
easyrtc.events.emitDefault("easyrtcMsg", connectionObj, msg, socketCallback, next);
break;
}
};
easyrtc.events.on("easyrtcMsg", onEasyrtcMsg);
function MakeCallSPRequest(paramCallerUniqueID, paramCallerID, paramCalledID) {
//https://www.npmjs.org/package/mssql
var sql = require('mssql');
var config = {
user: 'sa',
password: 'AMAZ10',
server: '10.10.10.47',
database: 'SesWareV7'
}
var connection = new sql.Connection(config, function (err) {
// Stored Procedure
if (!err) {
console.log("connected");
var request = new sql.Request(connection);
/*request.query("insert into dbo.CallTable (CallerUniqueID, CallerID, CalledID) values (\'111\', \'222\', \'333\')", function (err, recordset) {
console.log(err);
});
return;*/
request.input('paramUniqueID', sql.VarChar, paramCallerUniqueID);
request.input('paramCallerID', sql.VarChar, paramCallerID);
request.input('paramCalledID', sql.VarChar, paramCalledID);
console.log("executing");
request.execute('sp_incomingcall', function (err, recordsets, returnValue) {
if (!err)
{
console.log("executed [" + paramCallerUniqueID + "][" + paramCallerID + "][" + paramCalledID + "] Ret:" + returnValue);
console.dir(recordsets);
}
else
{
console.log("execute error" + err);
}
});
}
else
{
console.log("not connected: " + err);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment