Skip to content

Instantly share code, notes, and snippets.

@mheadd
Created June 30, 2011 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mheadd/1056237 to your computer and use it in GitHub Desktop.
Save mheadd/1056237 to your computer and use it in GitHub Desktop.
Sample Code from Philly Lambda Presentation - 6/29/2011
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script type="text/javascript" src="http://127.0.0.1:8901/chloe.js"></script>
<script type="text/javascript">
// Function to return a formatted time.
function getTime() {
var theDate = new Date();
var hours = theDate.getHours() > 12 ? theDate.getHours() -12 : theDate.getHours();
var ap = hours > 12 ? "PM" : "AM";
var minutes = theDate.getMinutes().toString().length == 1 ? "0" + theDate.getMinutes() : theDate.getMinutes();
var seconds = theDate.getSeconds().toString().length == 1 ? "0" + theDate.getSeconds() : theDate.getSeconds();
return hours + ":" + minutes + ":" + seconds + " " + ap;
}
$(document).ready(function() {
var chloe = new Chloe({host: '127.0.0.1', port: 8901});
chloe.connect(function () {
console.log('Connceted to Chloe server...');
});
chloe.onmessage(function (message) {
console.log(message);
var call = JSON.parse(message);
if(call.event == "join") {
$("#calls").append("<li id=\"" + call.id + "\">" + call.callerID +" : " + getTime() + "</li>");
}
else {
$("#" + call.id).remove();
}
});
});
</script>
<style type="text/css">
img {
display: block;
margin-left: auto;
margin-right: auto
}
body {
padding: 10px;
margin-left: 20px;
margin-right: 20px;
}
.center {
text-align: center;
}
ul {
width: 15%;
margin: auto;
}
</style>
</head>
<body>
<img src="tropo.jpeg" height="100" width="130" alt="Tropo logo" title="Tropo Cloud Communications Platform"/>
<h2 class="center">Tropo + Chloe Conference Dashboard</h2>
<script>
document.write('<p class="center">Conference start time: ' + getTime());
</script>
<p class="center">Currently on this conference call:</p>
<ul id="calls"></ul>
</body>
</html>
<?php
// The URL where Chloe is running.
define("CHLOE_ENDPOINT", "");
// Conference identifier.
define("CONFERENCE_ID", 9999999999);
// Function to send data to Chloe server.
function sendEvent($event, $id, $callerID) {
$data = array("event" => $event, "id" => $id, "callerID" => $callerID);
$postData = "data=" . json_encode($data);
$ch = $ch = curl_init(CHLOE_ENDPOINT);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/x-www-form-urlencoded'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$result = curl_exec($ch);
$error = curl_error($ch);
$curl_http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($result === false) {
_log("An error occurred: ".$error);
return false;
}
else {
if ($curl_http_code != '200') {
_log("*** An error occurred: Invalid HTTP response returned: " . $curl_http_code);
return false;
}
return true;
}
}
// Call properties.
$callerID = $currentCall->callerID;
$id = $currentCall->id;
// Send a join event to Chloe.
if(sendEvent("join", $id, $callerID)) {
say("Welcome to the conference. Press the pound key to exit.");
}
else {
say("Sorry, there was a problem joining you to the conference.");
hangup();
}
// Place caller in conference.
conference(CONFERENCE_ID, array("terminator" => "#"));
// Send exit event to Chloe.
sendEvent("exit", $id, $callerID);
// Exit prompt for caller.
say("Thank you for joining the conference, goodbye.");
?>
<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script src="http://s.phono.com/releases/0.2/jquery.phono.js"></script>
</head>
<body>
<input id="call" type="button" disabled="true" value="Loading..." />
<span id="status"></span>
<script>
$(document).ready(function(){
var phono = $.phono({
apiKey: "your-api-key", // Get an API key at http://phono.com
onReady: function() {
console.log("Phono Session ID: " + this.sessionId);
$("#call").attr("disabled", false).val("Call");
},
phone: {
onIncomingCall: function(event) {
var call = event.call;
alert("Incoming call");
}
}
});
$("#call").click(function() {
$("#call").attr("disabled", true).val("Busy");
phono.phone.dial("12156667777", {
onRing: function() {
$("#status").html("Ringing");
},
onAnswer: function() {
$("#status").html("Answered");
},
onHangup: function() {
$("#call").attr("disabled", false).val("Call");
$("#status").html("Hangup");
}
});
});
})
</script>
</body>
</html>
var sys = require('sys');
var http = require('http');
var cradle = require('cradle');
var port = 8000;
var db = new (cradle.Connection)('http://127.0.0.1', 5984).database('smsrecords');
var server = http.createServer(function(req, res) {
req.addListener('data', function(data){
db.save(JSON.parse(data), function(err, res){
if(err) {
sys.puts('Could not save delivery record.');
}
else {
sys.puts('delivery record saved '+ res.id);
}
});
});
res.writeHead(200);
res.end();
}).listen(port);
sys.puts('Server listening on port ' + port);
var sys = require('sys');
var http = require('http');
var port = 8000;
var server = http.createServer(function(req, res) {
req.addListener('data', function(data){
var json = JSON.parse(data);
sys.puts(sys.inspect(json));
});
res.writeHead(200);
res.end();
}).listen(port);
sys.puts('Server listening on port ' + port);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment