Skip to content

Instantly share code, notes, and snippets.

@hunnycode
Last active December 18, 2015 22:39
Show Gist options
  • Save hunnycode/5855702 to your computer and use it in GitHub Desktop.
Save hunnycode/5855702 to your computer and use it in GitHub Desktop.
<?php
include '../Services/Twilio/Capability.php';
$accountSid = '<AccountSid>';
$authToken = '<AuthToken>';
$appSid = '<ApplicationSid>';
$clientName = '<Twilio Client Name>';
if (isset($_REQUEST['client'])) {
$clientName = $_REQUEST['client'];
}
$capability = new Services_Twilio_Capability($accountSid, $authToken);
$capability->allowClientOutgoing($appSid);
$capability->allowClientIncoming($clientName);
$token = $capability->generateToken();
?>
<!DOCTYPE html>
<html>
<head>
<title>Hello Client Monkey 6</title>
<script type="text/javascript" src="//static.twilio.com/libs/twiliojs/1.2/twilio.min.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<link href="http://static0.twilio.com/packages/quickstart/client.css" type="text/css" rel="stylesheet" />
<script type="text/javascript">
Twilio.Device.setup("<?php echo $token; ?>");
Twilio.Device.ready(function (device) {
$("#log").text("Client '<?php echo $clientName; ?>' is ready");
});
Twilio.Device.error(function (error) {
$("#log").text("Error: " + error.message);
});
Twilio.Device.connect(function (conn) {
$("#log").text("Successfully established call");
});
Twilio.Device.disconnect(function (conn) {
$("#log").text("Call ended");
});
Twilio.Device.incoming(function (conn) {
$("#log").text("Incoming connection from " + conn.parameters.From);
conn.accept();
});
Twilio.Device.presence(function (pres) {
if (pres.available) {
$("<li>", {id: pres.from, text: pres.from}).click(function () {
$("#number").val(pres.from);
call();
}).prependTo("#people");
}
else {
$("#" + pres.from).remove();
}
});
function call() {
params = {"PhoneNumber": $("#number").val()};
Twilio.Device.connect(params);
}
function hangup() {
Twilio.Device.disconnectAll();
}
</script>
</head>
<body>
<button class="call" onclick="call();">Call</button>
<button class="hangup" onclick="hangup();">Hangup</button>
<input type="text" id="number" name="number" placeholder="Enter a phone number or client to call"/>
<div id="log">Loading pigeons...</div>
<ul id="people"/>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment