我正在使用TWILIO在我的应用中提供呼叫功能。我正在使用javascript和php来实现这一目标。我正在使用以下代码并且我的呼叫正常工作但是我想在呼叫正在进行时在页面上显示呼叫持续时间。我无法获得电话的记录/详细信息。你能帮我么 。提前致谢:
<?php
include 'Services/Twilio/Capability .php';
// put your Twilio API credentials here
$accountSid = 'AC';
$authToken = 'ce';
// put your Twilio Application Sid here
$appSid = 'AP';
$capability = new Services_Twilio_Capability($accountSid, $authToken);
$capability->allowClientOutgoing($appSid);
$capability->allowClientIncoming('Harry');
$token = $capability->generateToken();
?>
<!DOCTYPE html>
<html>
<head>
<title>Hello Client</title>
<script type="text/javascript"
src="//static.twilio.com/libs/twiliojs/1.1/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("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.parameters();
});
Twilio.Device.incoming(function (conn) {
$("#log").text("Incoming connection from " + conn.parameters.From);
// accept the incoming connection and start two-way audio
conn.accept();
});
function call() {
// get the phone number to connect the call to
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 to call"/>
<div id="log">Loading pigeons...</div>
</body>
</html>
答案 0 :(得分:0)
调用using setInterval回调函数时,每1000毫秒左右运行一次函数(Twilio.Device.connect
(这种情况发生在VoIP呼叫启动时)。每次setInterval中的函数触发时,都会使用新的时间值更新页面上的HTML元素。使用Twilio.Device.disconnect
回调函数在呼叫结束时停止计时器,并根据需要更新UI。