Last active
December 18, 2015 22:39
-
-
Save hunnycode/5855702 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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